www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - presence of function template prevents diagnostic

reply kdevel <kdevel vogtner.de> writes:
~~~A.d
module A;
import std.stdio;

void bar (int s) { __PRETTY_FUNCTION__.writeln; }
~~~

~~~foo.d
import std.stdio;
import A;
alias bar = A.bar;

version (X) {
    void bar (T) (T t) { __PRETTY_FUNCTION__.writeln; }
}

void bar (int s) { __PRETTY_FUNCTION__.writeln; }

void main ()
{
    bar (1);
}
~~~

$ dmd -i foo
foo.d(13): Error: foo.bar called with argument types (int) 
matches both:
A.d(4):     A.bar(int s)
and:
foo.d(9):     foo.bar(int s)


$ dmd -version=X -i foo
$ ./foo
void A.bar(int s)

Is the latter behavior intended or a bug?
Nov 14 2020
parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 11/14/20 5:44 PM, kdevel wrote:

 $ dmd -version=X -i foo
 $ ./foo
 void A.bar(int s)
 
 Is the latter behavior intended or a bug?
That seems like a bug. It shouldn't be less ambiguous because you *added* an overload that can also handle it... -Steve
Nov 16 2020
parent reply Max Haughton <maxhaton gmail.com> writes:
On Monday, 16 November 2020 at 17:03:32 UTC, Steven Schveighoffer 
wrote:
 On 11/14/20 5:44 PM, kdevel wrote:

 $ dmd -version=X -i foo
 $ ./foo
 void A.bar(int s)
 
 Is the latter behavior intended or a bug?
That seems like a bug. It shouldn't be less ambiguous because you *added* an overload that can also handle it... -Steve
It could be technically kosher because of template lookup but I'm not sure if the behaviour is actually specified in the standard. Probably should be a bug.
Nov 16 2020
parent kdevel <kdevel vogtner.de> writes:
On Monday, 16 November 2020 at 18:34:14 UTC, Max Haughton wrote:
 [...] Probably should be a bug.
filed as Issue 21481
Dec 13 2020