Skip to content

Commit 1da032a

Browse files
authored
Fix range start of INTERP_STRING_PART (#16785)
* use the same mechanism we used to fix the range start of INTERP_STRING_END to also fix the range start of INTERP_STRING_PART * - use a new rule for '"}" +' to catch the correct range start - clean up work around structures introduced before and not needed anymore with this * Revert "- use a new rule for '"}" +' to catch the correct range start" This reverts commit 4d01cda. * add second PR to changelog * remove commented poc code
1 parent 68a7dae commit 1da032a

File tree

6 files changed

+23
-11
lines changed

6 files changed

+23
-11
lines changed

docs/release-notes/.FSharp.Compiler.Service/8.0.300.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### Fixed
22

3-
* Fix wrong range start of INTERP_STRING_END. ([PR #16774](https://github.com/dotnet/fsharp/pull/16774))
3+
* Fix wrong range start of INTERP_STRING_END. ([PR #16774](https://github.com/dotnet/fsharp/pull/16774), [PR #16785](https://github.com/dotnet/fsharp/pull/16785))
44
* Fix missing warning for recursive calls in list comprehensions. ([PR #16652](https://github.com/dotnet/fsharp/pull/16652))
55
* Code generated files with > 64K methods and generated symbols crash when loaded. Use infered sequence points for debugging. ([Issue #16399](https://github.com/dotnet/fsharp/issues/16399), [#PR 16514](https://github.com/dotnet/fsharp/pull/16514))
66
* `nameof Module` expressions and patterns are processed to link files in `--test:GraphBasedChecking`. ([PR #16550](https://github.com/dotnet/fsharp/pull/16550), [PR #16743](https://github.com/dotnet/fsharp/pull/16743))

src/Compiler/Service/ServiceLexing.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module FSharpTokenTag =
3535
let INTERP_STRING_BEGIN_PART =
3636
tagOfToken (INTERP_STRING_BEGIN_PART("a", SynStringKind.Regular, LexCont.Default))
3737

38-
let INTERP_STRING_PART = tagOfToken (INTERP_STRING_PART("a", LexCont.Default))
38+
let INTERP_STRING_PART = tagOfToken (INTERP_STRING_PART("a", None, LexCont.Default))
3939
let INTERP_STRING_END = tagOfToken (INTERP_STRING_END("a", None, LexCont.Default))
4040
let LPAREN = tagOfToken LPAREN
4141
let RPAREN = tagOfToken RPAREN
@@ -491,7 +491,7 @@ module internal LexerStateEncoding =
491491
| STRING_TEXT cont
492492
| EOF cont
493493
| INTERP_STRING_BEGIN_PART(_, _, cont)
494-
| INTERP_STRING_PART(_, cont)
494+
| INTERP_STRING_PART(_, _, cont)
495495
| INTERP_STRING_BEGIN_END(_, _, cont)
496496
| INTERP_STRING_END(_, _, cont)
497497
| LBRACE cont

src/Compiler/SyntaxTree/LexHelpers.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ type LexerStringFinisher =
188188
else
189189
INTERP_STRING_BEGIN_END(s, synStringKind, cont)
190190
else if isPart then
191-
INTERP_STRING_PART(s, cont)
191+
INTERP_STRING_PART(s, None, cont)
192192
else
193193
INTERP_STRING_END(s, None, cont)
194194
elif kind.IsByteString then

src/Compiler/lex.fsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ let checkExprGreaterColonOp (lexbuf:UnicodeLexing.Lexbuf) =
120120
let unexpectedChar lexbuf =
121121
LEX_FAILURE (FSComp.SR.lexUnexpectedChar(lexeme lexbuf))
122122

123-
let startString args (lexbuf: UnicodeLexing.Lexbuf) altStartForStringEnd =
123+
let startString args (lexbuf: UnicodeLexing.Lexbuf) altStartForStringPartOrEnd =
124124
let buf = ByteBuffer.Create StringCapacity
125125
let m = lexbuf.LexemeRange
126126
let startp = lexbuf.StartPos
@@ -158,9 +158,9 @@ let startString args (lexbuf: UnicodeLexing.Lexbuf) altStartForStringEnd =
158158
INTERP_STRING_BEGIN_END (s, synStringKind, cont)
159159
else
160160
if isPart then
161-
INTERP_STRING_PART (s, cont)
161+
INTERP_STRING_PART (s, altStartForStringPartOrEnd, cont)
162162
else
163-
INTERP_STRING_END (s, altStartForStringEnd, cont)
163+
INTERP_STRING_END (s, altStartForStringPartOrEnd, cont)
164164
else
165165
let s = Lexhelp.stringBufferAsString buf
166166
let synStringKind =

src/Compiler/pars.fsy

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ let parse_error_rich = Some(fun (ctxt: ParseErrorContext<_>) ->
3737
%token <string * SynStringKind * ParseHelpers.LexerContinuation> STRING
3838
%token <string * SynStringKind * ParseHelpers.LexerContinuation> INTERP_STRING_BEGIN_END
3939
%token <string * SynStringKind * ParseHelpers.LexerContinuation> INTERP_STRING_BEGIN_PART
40-
%token <string * ParseHelpers.LexerContinuation> INTERP_STRING_PART
40+
%token <string * range option * ParseHelpers.LexerContinuation> INTERP_STRING_PART
4141
%token <string * range option * ParseHelpers.LexerContinuation> INTERP_STRING_END
4242
%token <ParseHelpers.LexerContinuation> LBRACE RBRACE
4343

@@ -6784,13 +6784,25 @@ interpolatedStringParts:
67846784
[ SynInterpolatedStringPart.String(s, m) ] }
67856785

67866786
| INTERP_STRING_PART interpolatedStringFill interpolatedStringParts
6787-
{ SynInterpolatedStringPart.String(fst $1, rhs parseState 1) :: SynInterpolatedStringPart.FillExpr $2 :: $3 }
6787+
{ let (s, altStart, _) = $1
6788+
let mOrig = rhs parseState 1
6789+
let m =
6790+
match altStart with
6791+
| Some r -> unionRanges r mOrig
6792+
| None -> mOrig
6793+
SynInterpolatedStringPart.String(s, m) :: SynInterpolatedStringPart.FillExpr $2 :: $3 }
67886794

67896795
| INTERP_STRING_PART interpolatedStringParts
67906796
{ let rbrace = parseState.InputEndPosition 1
67916797
let lbrace = parseState.InputStartPosition 2
67926798
reportParseErrorAt (mkSynRange rbrace lbrace) (FSComp.SR.parsEmptyFillInInterpolatedString())
6793-
SynInterpolatedStringPart.String(fst $1, rhs parseState 1) :: $2 }
6799+
let (s, altStart, _) = $1
6800+
let mOrig = rhs parseState 1
6801+
let m =
6802+
match altStart with
6803+
| Some r -> unionRanges r mOrig
6804+
| None -> mOrig
6805+
SynInterpolatedStringPart.String(s, m) :: $2 }
67946806

67956807
/* INTERP_STRING_BEGIN_END */
67966808
/* INTERP_STRING_BEGIN_PART int32 INTERP_STRING_END */

tests/service/data/SyntaxTree/String/SynExprInterpolatedStringWithTripleQuoteMultipleDollars.fs.bsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ImplFile
1818
InterpolatedString
1919
([String ("1 + ", (2,8--2,21));
2020
FillExpr (Const (Int32 41, (2,21--2,23)), None);
21-
String (" = ", (2,25--2,32));
21+
String (" = ", (2,23--2,32));
2222
FillExpr (Const (Int32 6, (2,32--2,33)), None);
2323
String (" * 7", (2,33--2,43))], TripleQuote, (2,8--2,43)),
2424
(2,4--2,5), Yes (2,0--2,43), { LeadingKeyword = Let (2,0--2,3)

0 commit comments

Comments
 (0)