Skip to content

Commit

Permalink
Merge pull request #2485 from WalterBright/mixin-args
Browse files Browse the repository at this point in the history
fix Issue 19292 - Mixin expressions should take an argument list
  • Loading branch information
WalterBright committed Oct 14, 2018
2 parents 0e23fd2 + 5ab55dd commit 2b1e8ce
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
12 changes: 7 additions & 5 deletions spec/expression.dd
Expand Up @@ -1728,18 +1728,20 @@ $(H3 $(LNAME2 mixin_expressions, Mixin Expressions))

$(GRAMMAR
$(GNAME MixinExpression):
$(D mixin $(LPAREN)) $(GLINK AssignExpression) $(D $(RPAREN))
$(D mixin $(LPAREN)) $(GLINK ArgumentList) $(D $(RPAREN))
)

$(P The $(I AssignExpression) must evaluate at compile time
to a constant string.
$(P Each $(GLINK AssignExpression) in the $(I ArgumentList) is
evaluated at compile time, and the result must be representable
as a string.
The resulting strings are concatenated to form a string.
The text contents of the string must be compilable as a valid
$(I Expression), and is compiled as such.)
$(GLINK Expression), and is compiled as such.)

---
int foo(int x)
{
return mixin("x + 1") * 7; // same as ((x + 1) * 7)
return mixin("x +", 1) * 7; // same as ((x + 1) * 7)
}
---

Expand Down
13 changes: 9 additions & 4 deletions spec/module.dd
Expand Up @@ -623,12 +623,17 @@ $(H2 $(LEGACY_LNAME2 MixinDeclaration, mixin-declaration, Mixin Declaration))

$(GRAMMAR
$(GNAME MixinDeclaration):
$(D mixin) $(D $(LPAREN)) $(ASSIGNEXPRESSION) $(D $(RPAREN)) $(D ;)
$(D mixin) $(D $(LPAREN)) $(GLINK2 expression, ArgumentList) $(D $(RPAREN)) $(D ;)
)

$(P The $(ASSIGNEXPRESSION) must evaluate at compile time to a constant string.
The text contents of the string must be compilable as a valid $(GLINK DeclDefs),
and is compiled as such.)
$(P Each $(GLINK2 expression, AssignExpression) in the $(I ArgumentList) is
evaluated at compile time, and the result must be representable
as a string.
The resulting strings are concatenated to form a string.
The text contents of the string must be compilable as a valid
$(GLINK DeclDefs), and is compiled as such.
)


$(H2 $(LEGACY_LNAME2 PackageModule, package-module, Package Module))

Expand Down
10 changes: 7 additions & 3 deletions spec/statement.dd
Expand Up @@ -1866,11 +1866,13 @@ $(H2 $(LEGACY_LNAME2 MixinStatement, mixin-statement, Mixin Statement))

$(GRAMMAR
$(GNAME MixinStatement):
$(D mixin) $(D $(LPAREN)) $(ASSIGNEXPRESSION) $(D $(RPAREN)) $(D ;)
$(D mixin) $(D $(LPAREN)) $(GLINK2 expression, ArgumentList) $(D $(RPAREN)) $(D ;)
)

$(P The $(ASSIGNEXPRESSION) must evaluate at compile time
to a constant string.
$(P Each $(GLINK2 expression, AssignExpression) in the $(I ArgumentList) is
evaluated at compile time, and the result must be representable
as a string.
The resulting strings are concatenated to form a string.
The text contents of the string must be compilable as a valid
$(GLINK StatementList), and is compiled as such.
)
Expand All @@ -1897,6 +1899,8 @@ void main()
mixin("y =") 4; // error, string must be complete statement

mixin("y =" ~ "4;"); // ok

mixin("y =", 2+2, ";"); // ok
}
---

Expand Down

0 comments on commit 2b1e8ce

Please sign in to comment.