-
Notifications
You must be signed in to change notification settings - Fork 440
Fix a crash when string interpolation creates a MissingStmtSyntax #1291
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 a crash when string interpolation creates a MissingStmtSyntax #1291
Conversation
String(describing: error), | ||
""" | ||
|
||
1 │ return 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not testing the formatted string here. That's going to be a pain if we ever change it 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have tests that check the diagnostic format in SwiftDiagnosticTests
and I really want to check that we produce a nice-looking error message here.
So: I would-refer to keep it.
@@ -19,8 +19,10 @@ import SwiftParser | |||
import SwiftParserDiagnostics | |||
|
|||
extension SyntaxParseable { | |||
public init(stringInterpolationOrThrow stringInterpolation: SyntaxStringInterpolation) throws { | |||
self = try performParse(source: stringInterpolation.sourceText, parse: { parser in | |||
public typealias StringInterpolation = SyntaxStringInterpolation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why wasn't this needed before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I honestly don’t know and gave up trying to figure out why we need it now after a couple of minutes.
self = trivia | ||
if pieces.contains(where: { $0.isUnexpected }) { | ||
var diagnostics: [Diagnostic] = [] | ||
let tree = SourceFileSyntax(statements: [], eofToken: .eof(leadingTrivia: self)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Little bit weird, but I suppose this is what we were doing before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does the job of presenting a nice diagnostic so 🤷
We were crashing here because string interpolation created a `MissingStmtSyntax`, which doesn’t have any children. It then tried to assign the remaining tokens as unexpected tokens to the last child of the `MissingStmtSyntax`, which failed (because there are no children). The fix here is to just add an `unexpected` child to the missing nodes. I’ve got a gut feeling that that might be useful anyway.
806a42f
to
b6bfbb2
Compare
@swift-ci Please test |
We were crashing here because string interpolation created a
MissingStmtSyntax
, which doesn’t have any children. It then tried to assign the remaining tokens as unexpected tokens to the last child of theMissingStmtSyntax
, which failed (because there are no children).The fix here is to just add an
unexpected
child to the missing nodes. I’ve got a gut feeling that that might be useful anyway.