Skip to content

Commit

Permalink
fix #353 - Syntax error on templatized variable declarations (#363)
Browse files Browse the repository at this point in the history
fix #353 - Syntax error on templatized variable declarations
merged-on-behalf-of: Basile-z <Basile-z@users.noreply.github.com>
  • Loading branch information
Basile-z authored and dlang-bot committed May 27, 2019
1 parent 0b67a4d commit cf12c2d
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 @@ -2318,10 +2318,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 cf12c2d

Please sign in to comment.