void foo(){}
void foo(int){}
Without further information, a declaration that contains typeof(foo) should fail.
static assert(!is({typeof(foo)* x;}));
OTOH, 'foo' has some type, we just don't know which one.
static if(is(typeof(foo));
The simplest way to resolve this would be to define typeof(overloadset):=void.
Comment #1 by k.hara.pg — 2012-02-19T15:25:42Z
I think typeof(overloadset):=void is not good.
Because, in this case, calculating typeof(foo) to void is valid by translating foo to foo() first.
So introducing new ambiguous function type instead of void is much better.
(My idea is here: https://github.com/D-Programming-Language/dmd/pull/71)
void foo();
void foo(int);
static assert(is(typeof(foo) == void)); // without -property switch
static if (is(typeof(foo) R)) {} // evaluated to false with -property switch,
// because R is ambiguous type, not exact type.
@property int foo();
@property void foo(int);
static assert(is(typeof(foo) == int)); // always true
void foo(int);
void foo(long);
static assert(is(typeof(foo))); // always true, because foo has some type,
// even if it is ambiguous type.
static if (is(typeof(foo) R)) {} // evaluated to false,
// because R is ambiguous type, not exact type.
Comment #2 by timon.gehr — 2012-02-19T15:33:25Z
I agree with your design.
Comment #3 by verylonglogin.reg — 2012-11-15T00:27:45Z
*** Issue 6263 has been marked as a duplicate of this issue. ***
Comment #4 by andrei — 2013-02-03T07:00:13Z
Let me add one more case that doesn't involve any property-related stuff:
unittest
{
class C1 {
int fun(string) { return 1; }
int fun() { return 1; }
}
auto c1 = new C1;
writeln(typeof(&c1.fun).stringof);
}
This should fail with ambiguity error, but actually prints the type of the first overload.
Comment #5 by code — 2013-05-20T11:50:59Z
This seems to happen for any type deduction.
void foo() {}
void foo(int) {}
auto val1 = &foo; // should be ambiguous
auto val2 = cast(void function(int))&foo; // works
void function(int) val3 = &foo; // works
auto bar1() { return &foo; } // should be ambiguous
auto bar2() { return cast(void function(int))&foo; } // works
void function(int) bar3() { return &foo; } // works
Comment #6 by timon.gehr — 2013-05-20T12:06:39Z
(In reply to comment #2)
> I agree with your design.
Actually, I think is(typeof(foo)) should be consistent with whether or not foo compiles.