Skip to content

Fix crash on nested interpolation #637

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

Merged
merged 2 commits into from
Aug 26, 2022

Conversation

omochi
Copy link
Contributor

@omochi omochi commented Aug 25, 2022

Fix #618, #636

Lex.Cursor.skipToEndOfInterpolatedExpression is called from two paths.

One is from Lexer.Cursor.lexStringLiteral.
Another is from Lexer.lexToEndOfInterpolatedExpression from Parser.parseStringLiteralSegments.

In first case, cursor position is after of ( which opens interpolation.
But skipToEndOfInterpolatedExpression expects it called on position of (.

So Lexer split tokens wrongly with some inputs.
For example:

"text \(a.m({ "\($0)" }).j(s: ",")) text"
                       ^(1)       ^(2)

Lexer closes interpolation (1) wrongly. (2) is correct.

To fix this issue, I change lexStringLiteral.
As changing advance to peek,
cursor position is on ( when it calls skipToEndOfInterpolatedExpression.

@omochi omochi requested a review from ahoppen as a code owner August 25, 2022 07:21
@ahoppen
Copy link
Member

ahoppen commented Aug 25, 2022

Could you add test cases for the two fixed issues as described in https://github.com/apple/swift-syntax/blob/main/Sources/SwiftParser/SwiftParser.docc/FixingBugs.md#round-trip-failure-or-parser-crash?

@ahoppen ahoppen requested a review from CodaFi August 25, 2022 07:23
@omochi
Copy link
Contributor Author

omochi commented Aug 25, 2022

@ahoppen I added test cases 😀

@ahoppen
Copy link
Member

ahoppen commented Aug 25, 2022

Thanks for fixing this crash 👍

@ahoppen
Copy link
Member

ahoppen commented Aug 25, 2022

@swift-ci Please test

@CodaFi CodaFi merged commit 6eb1701 into swiftlang:main Aug 26, 2022
@omochi omochi deleted the fix-nested-interpolation-crash branch August 30, 2022 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SwiftParser crashes on string with nested interpolation
3 participants