Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix how much is trimmed from an interp string part #18123

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
abonie marked this conversation as resolved.
Show resolved Hide resolved
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
Loading