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

Can't prefix format specifier with '%' in interpolated strings #18103

Closed
b-hodge opened this issue Dec 3, 2024 · 3 comments · Fixed by #18123
Closed

Can't prefix format specifier with '%' in interpolated strings #18103

b-hodge opened this issue Dec 3, 2024 · 3 comments · Fixed by #18123
Assignees
Labels
Area-Compiler Compiler-related issues which don't belong to other categories Bug
Milestone

Comments

@b-hodge
Copy link

b-hodge commented Dec 3, 2024

Interpolated strings in F# support the format specifiers described in the F# Plain Text Formatting documentation. This includes producing a literal % character by prefixing it with another %.

This no longer works when the sequence of characters is immediately followed by a format specifier.

Repro steps

Microsoft (R) F# Interactive version 12.9.100.0 for F# 9.0

> let x = "abc";;
val x: string = "abc"

> $"%%%s{x}%%";;
val it: string = "abc%"

Note that this works as expected in F# 8.0:

Microsoft (R) F# Interactive version 12.8.400.0 for F# 8.0

> let x = "abc";;
val x: string = "abc"

> $"%%%s{x}%%";;
val it: string = "%abc%"

Related information

Tested with sdk-9.0.101-macos-arm64.

@brianrourkeboll
Copy link
Contributor

brianrourkeboll commented Dec 4, 2024

Hmm. I think there might have been a bug in #16556, specifically here:

// Removes trailing "%s" unless it was escaped by another '%' (checks for odd sequence of '%' before final "%s")
let (|WithTrailingStringSpecifierRemoved|) (s: string) =
if s.EndsWith "%s" then
let i = s.AsSpan(0, s.Length - 2).LastIndexOfAnyExcept '%'
let diff = s.Length - 2 - i
if diff &&& 1 <> 0 then
s[..i]
else
s
else
s

Should this be something like

-s[..i]
+s[..s.Length - 3]

?

@abonie abonie modified the milestones: Backlog, December-2024 Dec 4, 2024
@abonie
Copy link
Member

abonie commented Dec 5, 2024

Actually I've just built #16556 and it doesn't repro there, so must be something else

Edit: nevermind, I forgot it was behind langversion:preview at that point, so that's why it didn't repro. It is most likely that commit

@T-Gro T-Gro removed the Needs-Triage label Dec 9, 2024
@abonie abonie added the Area-Compiler Compiler-related issues which don't belong to other categories label Dec 9, 2024
@edgarfgp
Copy link
Contributor

edgarfgp commented Dec 9, 2024

This is a regression right ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compiler Compiler-related issues which don't belong to other categories Bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants