digitalmars.D.bugs - [Issue 9235] New: Template mixin makes doesn't allow to mixin in non-conflicting overloads
- d-bugmail puremagic.com Dec 28 2012
- d-bugmail puremagic.com Dec 28 2012
- d-bugmail puremagic.com Jan 30 2013
- d-bugmail puremagic.com Feb 04 2013
- d-bugmail puremagic.com Feb 14 2013
- d-bugmail puremagic.com Feb 14 2013
- d-bugmail puremagic.com Feb 14 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9235 Summary: Template mixin makes doesn't allow to mixin in non-conflicting overloads Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: major Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: dmitry.olsh gmail.com --- Comment #0 from Dmitry Olshansky <dmitry.olsh gmail.com> 2012-12-28 04:55:48 PST --- The program below show the problem. If it was by design then design is faulty as the broken error message indicates. (I have a real-world use case for this and see no reason to forbid it) enum Command{ Char, Any, Fork, Jump, End }; template FlowEvaluator() { //if control flow bool execute(Command cmd)() if(cmd == Command.Jump || cmd == Command.Fork) { return false; } } template MatchEvaluator() { //if operation bool execute(Command cmd)() if(cmd == Command.Char || cmd == Command.Any || cmd == Command.End) { return false; } } struct Machine { mixin FlowEvaluator; mixin MatchEvaluator; bool exec() { return execute!(Command.Any)(); } } Fails with: mixin.d(36): Error: template instance execute!(cast(Command)1) ambiguous template declaration mixin.Machine.MatchEvaluator!().execute(Command cmd)() if (cmd == Command.Char || cmd == Command.Any || cmd == Command.End) and mixin.Machine.FlowEvaluator!().execute(Command cmd)() if (cmd == Command.Jump || cmd == Command.Fork) mixin.d(36): Error: template instance execute!(cast(Command)1) execute!(cast(Command)1) does not match template declaration execute(Command cmd)() if (cmd == Command.Jump || cmd == Command.Fork) mixin.d(36): Error: function expected before (), not execute!(cast(Command)1) of type void The second message hints to me that compiler in fact knows perfectly well which one template does match the instantiation but something prevented it from just picking it. Tested on 2.061alpha, I think it was there all along. Marking as major as there is either bogus diagnostic or a broken feature. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 28 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9235 --- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2012-12-28 05:55:08 PST --- This is a kind of "template overload set", which is not yet supported in current dmd. Following is an another case which fails to compile based on the same issue. --- // module a; template A(T) if (is(T == int)) {} // module b; template A(T) if (is(T == double)) {} // moudle test; import a, b; alias A!int X; --- output: test.d(5): Error: template instance A!(int) ambiguous template declaration b.A(T) if (is(T == double)) and a.A(T) if (is(T == int)) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 28 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9235 Maksim Zholudev <maximzms gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |maximzms gmail.com --- Comment #2 from Maksim Zholudev <maximzms gmail.com> 2013-01-30 05:49:59 PST --- http://dlang.org/template-mixin.html "Alias declarations can be used to overload together functions declared in different mixins" Unfortunately this doesn't work: ------------------- mixin template mixA() { void foo(string s)() if(s == "a") {} } mixin template mixB() { void foo(string s)() if(s == "b") {} } struct Foo { mixin mixA A; mixin mixB B; alias A.foo foo; alias B.foo foo; } void main() { Foo f; f.foo!"a"(); } ------------------- test.d(16): Error: alias test.Foo.foo conflicts with alias test.Foo.foo at test.d(15) ------------------- It looks like signature constraints are ignored in this case. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 30 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9235 --- Comment #3 from Maksim Zholudev <maximzms gmail.com> 2013-02-04 08:12:40 PST --- Signature constraints are ignored also for structures: ------------------- struct A { void foo(string s)() if(s == "a") {} } struct B { void foo(string s)() if(s == "b") {} } struct Foo { A a; B b; alias a.foo foo; alias b.foo foo; } void main() { Foo f; f.foo!"a"(); } ------------------- test.d(16): Error: alias test.Foo.foo conflicts with alias test.Foo.foo at test.d(15) ------------------- -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 04 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9235 Kenji Hara <k.hara.pg gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |pull --- Comment #4 from Kenji Hara <k.hara.pg gmail.com> 2013-02-14 08:06:47 PST --- https://github.com/D-Programming-Language/dmd/pull/1660 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 14 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9235 --- Comment #5 from Kenji Hara <k.hara.pg gmail.com> 2013-02-14 08:15:38 PST --- (In reply to comment #3)Signature constraints are ignored also for structures:
It is not valid code, becausestruct Foo { A a; B b; alias a.foo foo; alias b.foo foo; }
is just same as: struct Foo { A a; B b; alias A.foo foo; // alias doesn't handle context *expression* alias B.foo foo; // so 'a' and 'b' are simply truncated. } Then,Foo f; f.foo!"a"();
is identical with: A.foo!"a"(); But A.foo requires a valid 'this' expression, so compilation fails. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 14 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9235 Andrej Mitrovic <andrej.mitrovich gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |andrej.mitrovich gmail.com --- Comment #6 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-02-14 08:20:42 PST --- Is this related to http://d.puremagic.com/issues/show_bug.cgi?id=8074 ? Because it seems like overloading via template mixins is something Andrei wants to ban (I disagree with it). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 14 2013









d-bugmail puremagic.com 