diff --git a/compiler/src/dmd/parse.d b/compiler/src/dmd/parse.d index a7a930335ad5..b953582f12b2 100644 --- a/compiler/src/dmd/parse.d +++ b/compiler/src/dmd/parse.d @@ -1705,19 +1705,28 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer * mixin Foo; * mixin Foo!(args); * mixin a.b.c!(args).Foo!(args); - * mixin Foo!(args) identifier; * mixin typeof(expr).identifier!(args); + * mixin Foo!(args) identifier; + * mixin identifier = Foo!(args); */ private AST.Dsymbol parseMixin() { AST.TemplateMixin tm; - Identifier id; + Identifier id, name; AST.Objects* tiargs; //printf("parseMixin()\n"); const locMixin = token.loc; nextToken(); // skip 'mixin' + // mixin Identifier = MixinTemplateName TemplateArguments; + if (token.value == TOK.identifier && peekNext() == TOK.assign) + { + name = token.ident; + nextToken(); + nextToken(); + } + auto loc = token.loc; AST.TypeQualified tqual = null; if (token.value == TOK.dot) @@ -1780,14 +1789,14 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer nextToken(); } - id = null; - if (token.value == TOK.identifier) + // mixin MixinTemplateName TemplateArguments Identifier; + if (!name && token.value == TOK.identifier) { - id = token.ident; + name = token.ident; nextToken(); } - tm = new AST.TemplateMixin(locMixin, id, tqual, tiargs); + tm = new AST.TemplateMixin(locMixin, name, tqual, tiargs); if (token.value != TOK.semicolon) error("`;` expected after `mixin`"); nextToken(); diff --git a/compiler/test/runnable/mixin1.d b/compiler/test/runnable/mixin1.d index d36d3f1ec0e0..2cded33a5412 100644 --- a/compiler/test/runnable/mixin1.d +++ b/compiler/test/runnable/mixin1.d @@ -100,6 +100,7 @@ template Foo2(T) mixin Foo2!(uint) B2; mixin Foo2!(long) C2; +mixin D2 = Foo2!(wchar); mixin Foo2!(int); void test2() @@ -107,6 +108,7 @@ void test2() B2.x2 = 3; assert(B2.x2 == 3); assert(C2.x2 == long.sizeof); + assert(D2.x2 == 2); // assert(x2 == int.sizeof); } @@ -284,6 +286,9 @@ void test11() int y = 8; mixin Foo11!(y) B; assert(B.abc() == 8); + + mixin C = Foo11!2; + assert(C.abc() == 2); } /*******************************************/