Skip to content

[SwiftSyntax] Fix assertion failure if regex literal was not terminated at the end of the file #59069

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 1 commit into from
May 25, 2022

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented May 25, 2022

Fixes a SwiftSyntax parsing assertion failure if there is a regex literal at the end of the file. I.e. either a single line regex literal in a file without a trailing newline or a multi-line regex literal.

This does not crash in non-assert builds.

@ahoppen ahoppen requested a review from rintaro May 25, 2022 13:03
@ahoppen
Copy link
Member Author

ahoppen commented May 25, 2022

@swift-ci Please smoke test

Comment on lines 5 to 6
// IMPORTANT: This file must not contain a trailing newline
#/
unterminatedLiteral
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI GitHub doesn't appear to show the "no newline at end of file" marker for this case

Given the fiddly nature of these tests, I kind of wonder whether we should at some point introduce a testing script that strips trailing newlines, rather than having the file be like that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that’s because this file is supposed to have a newline (because it’s using a multi-line regex literal). I just forgot to remove the comment.

…ed at the end of the file

Fixes a SwiftSyntax parsing assertion failure if there is a regex literal at the end of the file. I.e. either a single line regex literal in a file without a trailing newline or a multi-line regex literal.

This does not crash in non-assert builds.
@ahoppen ahoppen force-pushed the pr/unterminated-regex-literal branch from 3e25f21 to e75c56b Compare May 25, 2022 13:36
@ahoppen
Copy link
Member Author

ahoppen commented May 25, 2022

@swift-ci Please smoke test

@ahoppen ahoppen merged commit 0b74559 into swiftlang:main May 25, 2022
@ahoppen ahoppen deleted the pr/unterminated-regex-literal branch May 25, 2022 16:38
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.

3 participants