diff --git a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md index a6ea239c57d..4c8d5c04829 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md @@ -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 diff --git a/src/Compiler/Checking/Expressions/CheckExpressions.fs b/src/Compiler/Checking/Expressions/CheckExpressions.fs index b13e3d01d12..16dc49c1a61 100644 --- a/src/Compiler/Checking/Expressions/CheckExpressions.fs +++ b/src/Compiler/Checking/Expressions/CheckExpressions.fs @@ -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 diff --git a/tests/FSharp.Compiler.ComponentTests/Language/InterpolatedStringsTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/InterpolatedStringsTests.fs index b4e2cc8eab9..e7c18f0d679 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/InterpolatedStringsTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/InterpolatedStringsTests.fs @@ -130,6 +130,17 @@ type Foo () = |> compile |> shouldSucceed + [] + let ``Percent signs and format specifiers with string expression`` () = + Fsx """ +let x = "abc" +let s = $"%%%s{x}%%" +printfn "%s" s + """ + |> compileExeAndRun + |> shouldSucceed + |> withStdOutContains "%abc%" + [] // Test different number of interpolated string parts []