Fix placement of trivia inside an interpolation#57989
Fix placement of trivia inside an interpolation#57989CyrusNajmabadi merged 42 commits intodotnet:mainfrom
Conversation
…rusNajmabadi/roslyn into simplifyInterpolationPArsing4
|
|
||
| // First grab any trivia right after the {, it will be trailing trivia for the { token. | ||
| var openTokenTrailingTrivia = tempLexer.LexSyntaxTrailingTrivia().Node; | ||
| var openTokenText = text[interpolation.OpenBraceRange]; |
There was a problem hiding this comment.
this is the thrust of the change. the initial trivia is actually trailing trivia on the preceding token.
There was a problem hiding this comment.
answered offline. this ensures our tokens follow the syntactic-model invariants of the roslyn tree system.
| @@ -963,17 +963,17 @@ public static void Main() | |||
| "; | |||
|
|
|||
| ParserErrorMessageTests.ParseAndValidate(test, | |||
There was a problem hiding this comment.
these tests changed because they contain trivia that used to improperly be associated with the interpolation expression (as leading trivia). Once the trivia moved, teh location of the error reported changed to a different place.
| interpolation.OpenBraceRange.End, | ||
| interpolation.HasColon ? interpolation.ColonRange.Start : interpolation.CloseBraceRange.Start)]; | ||
|
|
||
| // TODO: some of the trivia in the interpolation maybe should be trailing trivia of the openBraceToken |
There was a problem hiding this comment.
this TODO is what thsi PR fixes. the trivia after the { belongs to it, not the expression we parse between { and }
625e9ee to
8493bf0
Compare
|
|
||
| // First grab any trivia right after the {, it will be trailing trivia for the { token. | ||
| var openTokenTrailingTrivia = tempLexer.LexSyntaxTrailingTrivia().Node; | ||
| var openTokenText = text[interpolation.OpenBraceRange]; |
|
|
||
| TrySetUnrecoverableError(_lexer.MakeError(_lexer.TextWindow.Position, 1, ErrorCode.ERR_SyntaxError, endingChar.ToString())); | ||
| goto default; | ||
| case '"' when RecoveringFromRunawayLexing(): |
There was a problem hiding this comment.
I'm pretty sure this would still be emitted as a jump table. Do you have an indication it wouldn't?
There was a problem hiding this comment.
talked offline. likely a faulty memory on my part. that said, i prefer the new pattern, and in raw-interpolated branch we extract out this logic for each specific branch into its own method.
8493bf0 to
625e9ee
Compare
Followup to #57966. Draft until that goes in.
Trivia inside an interpolation was being associated with the wrong token. Foudn during the raw string literal work.