Skip to content

Commit

Permalink
Merge pull request #8356 from RazvanN7/Issue_16051
Browse files Browse the repository at this point in the history
Fix Issue 16088 - Parse error for import expression in statement
  • Loading branch information
RazvanN7 committed Jun 14, 2018
2 parents d08e0fb + 6ebf865 commit 56a69ae
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/dmd/parse.d
Expand Up @@ -6076,10 +6076,28 @@ final class Parser(AST) : Lexer
}
case TOK.import_:
{
AST.Dsymbols* imports = parseImport();
s = new AST.ImportStatement(loc, imports);
if (flags & ParseStatementFlags.scope_)
s = new AST.ScopeStatement(loc, s, token.loc);
/* https://issues.dlang.org/show_bug.cgi?id=16088
*
* At this point it can either be an
* https://dlang.org/spec/grammar.html#ImportExpression
* or an
* https://dlang.org/spec/grammar.html#ImportDeclaration.
* See if the next token after `import` is a `(`; if so,
* then it is an import expression.
*/
if (peekNext() == TOK.leftParentheses)
{
AST.Expression e = parseExpression();
check(TOK.semicolon);
s = new AST.ExpStatement(loc, e);
}
else
{
AST.Dsymbols* imports = parseImport();
s = new AST.ImportStatement(loc, imports);
if (flags & ParseStatementFlags.scope_)
s = new AST.ScopeStatement(loc, s, token.loc);
}
break;
}
case TOK.template_:
Expand Down
1 change: 1 addition & 0 deletions test/compilable/imports/imp16088.d
@@ -0,0 +1 @@
module imports.imp16088;
9 changes: 9 additions & 0 deletions test/compilable/test16088.d
@@ -0,0 +1,9 @@
// REQUIRED_ARGS: -Jcompilable/imports/

// https://issues.dlang.org/show_bug.cgi?id=16088

void bar(string x) {}
auto foo()
{
import("imp16088.d").bar;
}

0 comments on commit 56a69ae

Please sign in to comment.