Skip to content

[Parse] Fix minor bug in #sourceLocation on lex error #19344

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
Sep 19, 2018
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
16 changes: 9 additions & 7 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3583,7 +3583,6 @@ ParserStatus Parser::parseLineDirective(bool isLine) {

unsigned StartLine = 0;
Optional<StringRef> Filename;
const char *LastTokTextEnd;
if (!isLine) {
// #sourceLocation()
// #sourceLocation(file: "foo", line: 42)
Expand Down Expand Up @@ -3640,10 +3639,10 @@ ParserStatus Parser::parseLineDirective(bool isLine) {
consumeToken(tok::integer_literal);
}

LastTokTextEnd = Tok.getText().end();
if (parseToken(tok::r_paren, diag::sourceLocation_expected, ")"))
if (Tok.isNot(tok::r_paren)) {
diagnose(Tok, diag::sourceLocation_expected, ")");
return makeParserError();

}
} else { // Legacy #line syntax.

// #line\n returns to the main buffer.
Expand Down Expand Up @@ -3679,10 +3678,10 @@ ParserStatus Parser::parseLineDirective(bool isLine) {
"#line");
if (!Filename.hasValue())
return makeParserError();
LastTokTextEnd = Tok.getText().end();
consumeToken(tok::string_literal);
}


const char *LastTokTextEnd = Tok.getText().end();

// Skip over trailing whitespace and a single \n to the start of the next
// line.
while (*LastTokTextEnd == ' ' || *LastTokTextEnd == '\t')
Expand All @@ -3703,6 +3702,9 @@ ParserStatus Parser::parseLineDirective(bool isLine) {
Filename.getValue(), LineOffset);
assert(isNewFile);(void)isNewFile;

// Lexing of next token must be deferred until after virtual file setup.
consumeToken(isLine ? tok::string_literal : tok::r_paren);

InPoundLineEnvironment = true;
return makeParserSuccess();
}
Expand Down
7 changes: 7 additions & 0 deletions test/Parse/line-directive.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %target-typecheck-verify-swift
// RUN: not %target-swift-frontend -c %s 2>&1 | %FileCheck %s

let x = 0 // We need this because of the #sourceLocation-ends-with-a-newline requirement.

Expand Down Expand Up @@ -53,3 +54,9 @@ enum E {
case C, D
#sourceLocation()
}

#sourceLocation(file: "sr8772.swift", line: 400)
2., 3
// CHECK: sr8772.swift:400:2: error: expected member name following '.'
// CHECK: sr8772.swift:400:3: error: consecutive statements on a line must be separated by ';'
// CHECK: sr8772.swift:400:3: error: expected expression