Allow interpolated string adjacent to '=' (e.g. C(Name=$"value"))#19820
Open
edgarfgp wants to merge 2 commits into
Open
Allow interpolated string adjacent to '=' (e.g. C(Name=$"value"))#19820edgarfgp wants to merge 2 commits into
edgarfgp wants to merge 2 commits into
Conversation
Contributor
❗ Release notes required
Warning No PR link found in some release notes, please consider adding it.
|
The lexer greedily matched '=$' as a single INFIX_COMPARE_OP, so
'C(Name=$"123")' and 'let x =$"123"' failed with FS0035 ('$' not
permitted in operator names). Add a lexer rule that matches '=$"',
consumes only the '=', and rewinds so the next scan begins at '$"' —
letting the regular interpolated-string lexer handle the rest, including
interpolation holes and triple-quoted forms.
Fix is position-agnostic (works in let-bindings, named args, record
creation/copy). Scoped to '=$"'; the '$@', '@$' and '$$' verbatim/extended
forms still require a space, as before.
03ecfa7 to
98d38a4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #16696.
Problem
When an interpolated string immediately follows
=with no space, the lexer greedily matches=$as a singleINFIX_COMPARE_OPtoken (since$is an operator character).checkExprOpthen rejects it with FS0035 ('$' is not permitted as a character in operator names), so property/named-argument initialization with an interpolated string fails to parse.Before
After
The produced AST is identical to the spaced form
= $"...", so all downstream tooling sees the same tree.Solution
A lexer-level rule for the exact 3-character sequence
=$":It matches
=$"(winning over the 2-char operator rule via longest-match), emitsEQUALS, then rewindsLexemeLengthto 1 so the next scan begins at$". The existing interpolated-string lexer then processes the rest — including interpolation holes and triple-quoted forms. Because the fix is in the lexer, it applies in every position where= $"..."is valid (let-bindings, named args, record creation/copy), not just one grammar rule.The previously-
internalLexBuffer.LexemeLengthsetter is exposed inprim-lexing.fsi(no change to the public API surface — the type isinternal).Scope
Limited to the
$"opening sequence (single- and triple-quoted). Defining or using=$as a custom operator remains rejected (FS0035), preserving the "reserved for future use" semantics.Open question — should we also handle the remaining variants?
These forms still require a space and continue to error as before (regression tests assert this):
They're out of scope for the reported issue (which only shows the
$"form), and the workaround is a single space. They could be added with the same lexer technique (longer=$@",=@$",=$$"""rules with a larger rewind), at the cost of more lexer rules. Do we want to cover them in this PR, defer to a follow-up, or leave them as-is?