[Issue 16125] mixin string/template confusion, results in no-op

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Jun 5 04:39:39 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=16125

ag0aep6g at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |ag0aep6g at gmail.com
         Resolution|---                         |DUPLICATE

--- Comment #1 from ag0aep6g at gmail.com ---
(In reply to Tomer Filiba from comment #0)
> enum Stub(string s) = s;

This expands to `template Stub(string s) { enum Stub = s; }

> mixin Stub!"int x;";

This mixes in `enum Stub s = "int x;";`. The mixed in `Stub` is shadowed by the
template of the same name. We can give the mixin a name to go around that:

mixin Stub!"int x;" MixedInStub;

Then we can print it:

void main() { writeln(MixedInStub.Stub); } /* prints "int x;" */

The problem in all this is that dmd allows to mixin a template that's not a
`mixin template`. Issue 12298 calls this out.

The behavior you're asking for (either behave as string mixin, or fail to
compile) is also being asked for in issue 16025.

Closing this as a duplicate of 16025.

*** This issue has been marked as a duplicate of issue 16025 ***

--


More information about the Digitalmars-d-bugs mailing list