www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7549] New: typeof of overloaded function picks the lexically first one

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7549

           Summary: typeof of overloaded function picks the lexically
                    first one
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: timon.gehr gmx.ch


--- Comment #0 from timon.gehr gmx.ch 2012-02-19 14:48:36 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 19 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7549



--- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2012-02-19 15:25:42 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 19 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7549



--- Comment #2 from timon.gehr gmx.ch 2012-02-19 15:33:25 PST ---
I agree with your design.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 19 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7549


Denis Shelomovskij <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |blood.of.life gmail.com


--- Comment #3 from Denis Shelomovskij <verylonglogin.reg gmail.com> 2012-11-15
11:27:45 MSK ---
*** Issue 6263 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 15 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7549


Andrei Alexandrescu <andrei erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei erdani.com


--- Comment #4 from Andrei Alexandrescu <andrei erdani.com> 2013-02-03 07:00:13
PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 03 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7549


Martin Nowak <code dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code dawg.eu


--- Comment #5 from Martin Nowak <code dawg.eu> 2013-05-20 11:50:59 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 20 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7549



--- Comment #6 from timon.gehr gmx.ch 2013-05-20 12:06:39 PDT ---
(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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 20 2013