From 5a8235129d8c2f909277441628f19dcd13a08da6 Mon Sep 17 00:00:00 2001 From: Adam Boniecki Date: Mon, 9 Dec 2024 15:27:57 +0100 Subject: [PATCH 1/2] Fix how much is trimmed from an interp string part Only trim last 2 characters if they are "%s" and the '%' is not escaped --- src/Compiler/Checking/Expressions/CheckExpressions.fs | 2 +- .../Language/InterpolatedStringsTests.fs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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 [] From b7bda52b274d758fee3ed17d36e884ac22e83030 Mon Sep 17 00:00:00 2001 From: Adam Boniecki Date: Tue, 10 Dec 2024 12:37:17 +0100 Subject: [PATCH 2/2] Add release note --- docs/release-notes/.FSharp.Compiler.Service/9.0.200.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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