Bug 7549 – typeof of overloaded function picks the lexically first one

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-02-19T14:48:36Z
Last change time
2024-12-13T17:58:40Z
Keywords
accepts-invalid, pull
Assigned to
Kenji Hara
Creator
timon.gehr
Moved to GitHub: dmd#17541 →

Comments

Comment #0 by timon.gehr — 2012-02-19T14:48:36Z
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.
Comment #7 by k.hara.pg — 2014-04-16T07:35:40Z
Comment #8 by simen.kjaras — 2018-04-19T20:30:43Z
*** Issue 18777 has been marked as a duplicate of this issue. ***
Comment #9 by simen.kjaras — 2018-04-19T20:31:55Z
*** Issue 8780 has been marked as a duplicate of this issue. ***
Comment #10 by robert.schadek — 2024-12-13T17:58:40Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17541 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB