Bug 14249 – Loose error check for incorrect template mixin

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-03-05T13:48:00Z
Last change time
2015-06-17T21:04:32Z
Keywords
accepts-invalid, diagnostic, pull
Assigned to
nobody
Creator
k.hara.pg

Comments

Comment #0 by k.hara.pg — 2015-03-05T13:48:13Z
Following code should fail to compile, but doesn't. mixin template Mix() { // shared static this() {} shared static ~this() {} // static this() {}'func.c' static ~this() {} unittest {} // invariant {} // alias a this; // new(size_t sz) { return null; } // delete(void* p) { } // this(int) {} // this(this) {} // ~this() {} // union { int x; double y; } } void main() { mixin Mix!(); }
Comment #1 by k.hara.pg — 2015-03-05T13:50:24Z
And, the error diagnostic for other invalid cases is not good. mixin template Mix() { shared static this() {} // shared static ~this() {} static this() {} // static ~this() {} // unittest {} invariant {} alias a this; new(size_t sz) { return null; } delete(void* p) { } this(int) {} this(this) {} ~this() {} union { int x; double y; } } void main() { mixin Mix!(); } test.d(8): Error: function test.main.Mix!().__invariant6 invariants are only for struct/union/class definitions test.d(9): Error: alias this test.main.Mix!().__anonymous alias this can only appear in struct or class declaration, not main test.d(10): Error: allocator test.main.Mix!().new new allocators only are for class or struct definitions test.d(11): Error: deallocator test.main.Mix!().delete new allocators only are for class or struct definitions test.d(12): Error: constructor test.main.Mix!().this constructors are only for class or struct definitions test.d(13): Error: function test.main.Mix!().__postblit post blits are only for struct/union definitions, not function main test.d(14): Error: destructor test.main.Mix!().~this destructors are only for class/struct/union definitions, not function main test.d(15): Error: anonymous union __anonymous can only be a part of an aggregate test.d(3): Error: function test.main.Mix!()._sharedStaticCtor4 static constructor can only be member of struct/class/module, not function main test.d(5): Error: function test.main.Mix!()._staticCtor5 static constructor can only be member of struct/class/module, not function main test.d(19): Error: mixin test.main.Mix!() error instantiating
Comment #2 by k.hara.pg — 2015-03-05T14:02:29Z
Comment #3 by github-bugzilla — 2015-04-09T02:05:22Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/bdc92c7c244398a361261369c3f59daccaa62664 fix Issue 14249 - Loose error check for incorrect template mixin
Comment #4 by github-bugzilla — 2015-06-17T21:04:32Z
Commit pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/bdc92c7c244398a361261369c3f59daccaa62664 fix Issue 14249 - Loose error check for incorrect template mixin