Skip to content

Commit 2b1e8ce

Browse files
authored
Merge pull request #2485 from WalterBright/mixin-args
fix Issue 19292 - Mixin expressions should take an argument list
2 parents 0e23fd2 + 5ab55dd commit 2b1e8ce

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

spec/expression.dd

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,18 +1728,20 @@ $(H3 $(LNAME2 mixin_expressions, Mixin Expressions))
17281728

17291729
$(GRAMMAR
17301730
$(GNAME MixinExpression):
1731-
$(D mixin $(LPAREN)) $(GLINK AssignExpression) $(D $(RPAREN))
1731+
$(D mixin $(LPAREN)) $(GLINK ArgumentList) $(D $(RPAREN))
17321732
)
17331733

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

17391741
---
17401742
int foo(int x)
17411743
{
1742-
return mixin("x + 1") * 7; // same as ((x + 1) * 7)
1744+
return mixin("x +", 1) * 7; // same as ((x + 1) * 7)
17431745
}
17441746
---
17451747

spec/module.dd

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -623,12 +623,17 @@ $(H2 $(LEGACY_LNAME2 MixinDeclaration, mixin-declaration, Mixin Declaration))
623623

624624
$(GRAMMAR
625625
$(GNAME MixinDeclaration):
626-
$(D mixin) $(D $(LPAREN)) $(ASSIGNEXPRESSION) $(D $(RPAREN)) $(D ;)
626+
$(D mixin) $(D $(LPAREN)) $(GLINK2 expression, ArgumentList) $(D $(RPAREN)) $(D ;)
627627
)
628628

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

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

spec/statement.dd

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,11 +1866,13 @@ $(H2 $(LEGACY_LNAME2 MixinStatement, mixin-statement, Mixin Statement))
18661866

18671867
$(GRAMMAR
18681868
$(GNAME MixinStatement):
1869-
$(D mixin) $(D $(LPAREN)) $(ASSIGNEXPRESSION) $(D $(RPAREN)) $(D ;)
1869+
$(D mixin) $(D $(LPAREN)) $(GLINK2 expression, ArgumentList) $(D $(RPAREN)) $(D ;)
18701870
)
18711871

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

18991901
mixin("y =" ~ "4;"); // ok
1902+
1903+
mixin("y =", 2+2, ";"); // ok
19001904
}
19011905
---
19021906

0 commit comments

Comments
 (0)