File tree Expand file tree Collapse file tree 4 files changed +29
-2
lines changed Expand file tree Collapse file tree 4 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -1653,6 +1653,8 @@ class Parser {
1653
1653
ParserResult<Expr> parseExprRegexLiteral ();
1654
1654
1655
1655
StringRef copyAndStripUnderscores (StringRef text);
1656
+ StringRef stripUnderscoresIfNeeded (StringRef text,
1657
+ SmallVectorImpl<char > &buffer);
1656
1658
1657
1659
ParserStatus parseStringSegments (SmallVectorImpl<Lexer::StringSegment> &Segments,
1658
1660
Token EntireTok,
Original file line number Diff line number Diff line change @@ -5809,7 +5809,9 @@ ParserStatus Parser::parseLineDirective(bool isLine) {
5809
5809
diagnose (Tok, diag::expected_line_directive_number);
5810
5810
return makeParserError ();
5811
5811
}
5812
- if (Tok.getText ().getAsInteger (0 , StartLine)) {
5812
+ SmallString<16 > buffer;
5813
+ auto text = stripUnderscoresIfNeeded (Tok.getText (), buffer);
5814
+ if (text.getAsInteger (0 , StartLine)) {
5813
5815
diagnose (Tok, diag::expected_line_directive_number);
5814
5816
return makeParserError ();
5815
5817
}
@@ -5840,7 +5842,9 @@ ParserStatus Parser::parseLineDirective(bool isLine) {
5840
5842
diagnose (Tok, diag::expected_line_directive_number);
5841
5843
return makeParserError ();
5842
5844
}
5843
- if (Tok.getText ().getAsInteger (0 , StartLine)) {
5845
+ SmallString<16 > buffer;
5846
+ auto text = stripUnderscoresIfNeeded (Tok.getText (), buffer);
5847
+ if (text.getAsInteger (0 , StartLine)) {
5844
5848
diagnose (Tok, diag::expected_line_directive_number);
5845
5849
return makeParserError ();
5846
5850
}
Original file line number Diff line number Diff line change @@ -1009,6 +1009,17 @@ StringRef Parser::copyAndStripUnderscores(StringRef orig) {
1009
1009
return StringRef (start, p - start);
1010
1010
}
1011
1011
1012
+ StringRef Parser::stripUnderscoresIfNeeded (StringRef text,
1013
+ SmallVectorImpl<char > &buffer) {
1014
+ if (text.contains (' _' )) {
1015
+ buffer.clear ();
1016
+ llvm::copy_if (text, std::back_inserter (buffer),
1017
+ [](char ch) { return ch != ' _' ; });
1018
+ return StringRef (buffer.data (), buffer.size ());
1019
+ }
1020
+ return text;
1021
+ }
1022
+
1012
1023
// / Disambiguate the parse after '{' token that is in a place that might be
1013
1024
// / the start of a trailing closure, or start the variable accessor block.
1014
1025
// /
Original file line number Diff line number Diff line change @@ -67,3 +67,13 @@ enum E {
67
67
// CHECK: sr8772.swift:400:2: error: expected member name following '.'
68
68
// CHECK: sr8772.swift:400:3: error: consecutive statements on a line must be separated by ';'
69
69
// CHECK: sr8772.swift:400:3: error: expected expression
70
+
71
+ // https://github.com/apple/swift/issues/55049
72
+ class I55049 {
73
+ #sourceLocation(file: "issue-55049.swift", line: 1_000)
74
+ let bar = 12
75
+ #sourceLocation(file: "issue-55049.swift", line: 2_000)
76
+ }
77
+
78
+ #line 1_000 " issue-55049.swift "
79
+ class I55049_1 { }
You can’t perform that action at this time.
0 commit comments