Thread overview
[Issue 4702] New: Long Postfix not working with cross-module overloading
Aug 21, 2010
Andrej Mitrovic
Dec 30, 2010
Andrej Mitrovic
Jan 22, 2012
Andrej Mitrovic
Oct 27, 2012
Andrej Mitrovic
Oct 27, 2012
Andrej Mitrovic
August 21, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4702

           Summary: Long Postfix not working with cross-module overloading
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2010-08-21 08:37:39 PDT ---
widget.d:

void fun(int x)
{
}


widget.d:

void fun(int x)
{
}


main.d:

import widget;
import io;

void main()
{
    long y = 10L;
    fun(y);                 // fine, no errors, goes to io.fun

    writeln(typeid(10L));   // writes long
    fun(10L);   // error: io.fun at io.d(4) conflicts with widget.fun at
widget.d(4)
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 30, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4702



--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2010-12-30 14:12:29 PST ---
OOPS!

That example code is completely wrong, please diregard it. This is the proper one which should work but doesn't:

main.d:
import std.stdio : writeln;
import foo;     // void fun(int x)
import bar;     // void fun(long x)

void main()
{
    auto y = 10L;
    fun(y);                 // ok, goes to bar.fun

    writeln(typeid(10L));   // writes long
    fun(10L);               // error: bar.fun conflicts with foo.fun
}

foo.d:
void fun(int x)
{
}

bar.d:
void fun(long x)
{
}


This only happens with literals and when the two fun methods are defined in separate modules. If the fun methods are defined directly in main(), there's no error.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 22, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=4702



--- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-01-21 17:53:28 PST ---
I think what's going on is DMD figures out the literal can fit into an int and does the optimization where it converts it into an int behind the scenes.

Proof is in the pudding:

import std.stdio;
import foo;
import bar;

void main()
{
    long x;
    fun(cast(long)2147483648);  // ok, int.max is 2147483647, overflows to long
    fun(cast(long)2147483647);  // error, no overflow and literal stored as int
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=4702


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


--- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-10-27 11:02:29 PDT ---
The problem is there are two overload sets and they're not explicitly merged. The fix is:

import foo;     // void fun(int x)
import bar;     // void fun(long x)

alias foo.fun fun;  // added
alias bar.fun fun;  // added

void main()
{
    auto y = 10L;
    fun(y);                 // ok, goes to bar.fun
    fun(10L);               // error: bar.fun conflicts with foo.fun
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=4702



--- Comment #4 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-10-27 11:03:02 PDT ---
(In reply to comment #3)
>     fun(10L);               // error: bar.fun conflicts with foo.fun

Disregard the comment it's a leftover from OP sample, the code will work now.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------