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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Parse/SyntaxRegexFallbackLexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ bool syntaxparse_lexRegexLiteral(
case '\0': {
if (Ptr - 1 == BufferEnd) {
// Reached to EOF.
diagnose(BridgedDiagEngine, Ptr, diag::lex_regex_literal_unterminated);
diagnose(BridgedDiagEngine, Ptr - 1, diag::lex_regex_literal_unterminated);
// In multi-line mode, we don't want to skip over what is likely
// otherwise valid Swift code, so resume from the first newline.
*InputPtr = firstNewline ? firstNewline : (Ptr - 1);
Expand Down
6 changes: 6 additions & 0 deletions test/Syntax/Parser/unterminated_multiline_regex.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: %swift-syntax-parser-test -dump-diags %s | %FileCheck %s
// CHECK: 7:1 Error: unterminated regex literal
// CHECK: 1 error(s) 0 warnings(s) 0 note(s)

#/
unterminatedLiteral
6 changes: 6 additions & 0 deletions test/Syntax/Parser/unterminated_regex.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: %swift-syntax-parser-test -dump-diags %s | %FileCheck %s
// CHECK: 6:21 Error: unterminated regex literal
// CHECK: 1 error(s) 0 warnings(s) 0 note(s)

// IMPORTANT: This file must not contain a trailing newline
/unterminatedLiteral