D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10556 - mixin template fails overload resolution
Summary: mixin template fails overload resolution
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-06 07:06 UTC by monarchdodra
Modified: 2024-12-13 18:08 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description monarchdodra 2013-07-06 07:06:03 UTC
--------mixin template fooImpl(T)
{
    static void foo(T t)
    {}
}
struct S{}
mixin fooImpl!S;
mixin fooImpl!int;
mixin fooImpl!long;

void main()
{
    S s;
    int a;
    foo(s);
    foo(a); //17
}

--------
hello.d
17
Error: hello.fooImpl!(int).foo at hello.d:3 conflicts with hello.fooImpl!(long).foo at hello.d:3
--------

Here, I'm using mixin template fooImpl to create a finite set of non-template functions. In particular, I'm generating the functions "foo(int)" and "foo(long)".

Yet, when making the call to "foo" with an int, the compiler complains of finding multiple matches, failing to "see" that there is an exact match.

Apparently, I think the compiler sees "foo" as template functions "fooImpl!long.foo(long)", so they all equally match. I think this is wrong behavior.

The specs state that "If two different mixins are put in the same scope, and each define a declaration with the same name, there is an ambiguity error when the declaration is referenced", however this is clearly not the case, since "foo(s)" is correctly resolved. foo(int) and foo(long) should also correctly resolve just as well.
Comment 1 monarchdodra 2013-07-06 07:09:46 UTC
http://d.puremagic.com/issues/show_bug.cgi?id=8074

8074 is related, although it deals with "strictly non-ambiguous overloads". In this example, there are multiple matches, but one is "exact".
Comment 2 Ferdinand Majerech 2015-01-01 04:53:34 UTC
Any progress on this issue? I've just run into it in my code; can work around with a string mixin but the result is much uglier.
Comment 3 dlangBugzillaToGithub 2024-12-13 18:08:53 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18621

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB