Skip to content

Commit

Permalink
fix #353 - Syntax error on templatized variable declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars-Kristiansen committed May 27, 2019
1 parent 22ebe99 commit 4c0e521
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/dparse/parser.d
Original file line number Diff line number Diff line change
Expand Up @@ -2303,10 +2303,19 @@ class Parser
error("no identifier for declarator");
return null;
}
if (peekIs(tok!"("))
mixin (nullCheck!`node.functionDeclaration = parseFunctionDeclaration(t, false)`);
else
mixin (nullCheck!`node.variableDeclaration = parseVariableDeclaration(t, false)`);
const b2 = setBookmark();
node.variableDeclaration = parseVariableDeclaration(t, false);
if (node.variableDeclaration is null)
{
goToBookmark(b2);
node.functionDeclaration = parseFunctionDeclaration(t, false);
}
else abandonBookmark(b2);
if (!node.variableDeclaration && !node.functionDeclaration)
{
error("invalid variable declaration or function declaration", false);
return null;
}
break;
case tok!"version":
if (peekIs(tok!"("))
Expand Down
4 changes: 4 additions & 0 deletions test/pass_files/declarations.d
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,12 @@ __traits(getMember, Foo, "Bar") fooBar;
const(__traits(getMember, Foo, "Bar")) fooBar;
alias FooBar = __traits(getMember, Foo, "Bar");
const fooBar = cast(__traits(getMember, Foo, "Bar")) __traits(getMember, Foo, "bar");
int twice(int x) = 2 * x;
const int twice(int x) = 2 * x;
immutable int twice(int x) = 2 * x;

void foo()
{
__traits(getMember, Foo, "Bar") fooBar;
immutable int twice(int x) = 2 * x;
}

0 comments on commit 4c0e521

Please sign in to comment.