Skip to content

Commit

Permalink
Fix how much is trimmed from an interp string part (#18123)
Browse files Browse the repository at this point in the history
* Fix how much is trimmed from an interp string part

Only trim last 2 characters if they are "%s" and the '%' is not escaped

* Add release note

---------

Co-authored-by: Adam Boniecki <[email protected]>
  • Loading branch information
abonie and abonie authored Dec 10, 2024
1 parent 7b1eb07 commit cf05314
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/release-notes/.FSharp.Compiler.Service/9.0.200.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Fix lowering of computed array expressions when the expression consists of a simple mapping from a `uint64` or `unativeint` array. [PR #18081](https://github.com/dotnet/fsharp/pull/18081)
* Add missing nullable-metadata for C# consumers of records,exceptions and DU subtypes generated from F# code. [PR #18079](https://github.com/dotnet/fsharp/pull/18079)
* Fix a race condition in file book keeping in the compiler service ([#18008](https://github.com/dotnet/fsharp/pull/18008))

* Fix trimming '%' characters when lowering interpolated string to a concat call [PR #18123](https://github.com/dotnet/fsharp/pull/18123)

### Added

Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Checking/Expressions/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ let (|WithTrailingStringSpecifierRemoved|) (s: string) =
let i = s.AsSpan(0, s.Length - 2).LastIndexOfAnyExcept '%'
let diff = s.Length - 2 - i
if diff &&& 1 <> 0 then
s[..i]
s[..s.Length - 3]
else
s
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ type Foo () =
|> compile
|> shouldSucceed

[<Fact>]
let ``Percent signs and format specifiers with string expression`` () =
Fsx """
let x = "abc"
let s = $"%%%s{x}%%"
printfn "%s" s
"""
|> compileExeAndRun
|> shouldSucceed
|> withStdOutContains "%abc%"

[<Theory>]
// Test different number of interpolated string parts
[<InlineData("$\"\"\"abc{\"d\"}e\"\"\"")>]
Expand Down

0 comments on commit cf05314

Please sign in to comment.