www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Overloading issues

reply Vathix <vathix dprogramming.com> writes:
enum Foo { FOO }
enum Bar { BAR }

void foobar(float num, Foo f) { }
void foobar(float num, Bar b) { }

int main()
{
    foobar(1.1, Foo.FOO);
    return 0; // Line 10.
}


DMD 0.118 output:
test.d(10): function test.foobar called with argument types:
         (double,Foo )
matches both:
         test.foobar(float,Foo )
and:
         test.foobar(float,Bar )


If I cast the 1.1 to float it works fine. It looks like it's using the  
base of all parameters when only one needs it. This didn't happen a few  
DMD versions ago.

Another less urgent bug would be the wrong line number.
Mar 16 2005
parent reply Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Vathix schrieb am Wed, 16 Mar 2005 13:16:09 -0500:
 enum Foo { FOO }
 enum Bar { BAR }

 void foobar(float num, Foo f) { }
 void foobar(float num, Bar b) { }

 int main()
 {
     foobar(1.1, Foo.FOO);
     return 0; // Line 10.
 }


 DMD 0.118 output:
 test.d(10): function test.foobar called with argument types:
          (double,Foo )
 matches both:
          test.foobar(float,Foo )
 and:
          test.foobar(float,Bar )


 If I cast the 1.1 to float it works fine.

 It looks like it's using the base of all parameters when only one needs it.

# It matches exactly, it matches with implicit conversions, or it does not # match. If there is more than one match, it is an error.
 This didn't happen a few DMD versions ago.

Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCOZ7i3w+/yD4P9tIRAtfuAKCe2s3pxX5Ns7MxLqKQzYJRoKwS9wCgnn4c WAZo8TykJMOxP1SU/fAXXeQ= =zoBs -----END PGP SIGNATURE-----
Mar 17 2005
parent reply Vathix <vathix dprogramming.com> writes:
On Thu, 17 Mar 2005 16:14:42 +0100, Thomas Kuehne  
<thomas-dloop kuehne.thisisspam.cn> wrote:

 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1

 Vathix schrieb am Wed, 16 Mar 2005 13:16:09 -0500:
 enum Foo { FOO }
 enum Bar { BAR }

 void foobar(float num, Foo f) { }
 void foobar(float num, Bar b) { }

 int main()
 {
     foobar(1.1, Foo.FOO);
     return 0; // Line 10.
 }


 DMD 0.118 output:
 test.d(10): function test.foobar called with argument types:
          (double,Foo )
 matches both:
          test.foobar(float,Foo )
 and:
          test.foobar(float,Bar )


 If I cast the 1.1 to float it works fine.

 It looks like it's using the base of all parameters when only one needs  
 it.

# It matches exactly, it matches with implicit conversions, or it does not # match. If there is more than one match, it is an error.

It still looks like a bug :\ double implicitly converts to float and Foo.FOO exactly matches with Foo.
Mar 17 2005
parent reply Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Vathix schrieb am Thu, 17 Mar 2005 11:02:37 -0500:
 On Thu, 17 Mar 2005 16:14:42 +0100, Thomas Kuehne  
<thomas-dloop kuehne.thisisspam.cn> wrote:
 Vathix schrieb am Wed, 16 Mar 2005 13:16:09 -0500:
 enum Foo { FOO }
 enum Bar { BAR }

 void foobar(float num, Foo f) { }
 void foobar(float num, Bar b) { }

 int main()
 {
     foobar(1.1, Foo.FOO);
     return 0; // Line 10.
 }


 DMD 0.118 output:
 test.d(10): function test.foobar called with argument types:
          (double,Foo )
 matches both:
          test.foobar(float,Foo )
 and:
          test.foobar(float,Bar )

 It looks like it's using the base of all parameters when only one needs  
 it.

# It matches exactly, it matches with implicit conversions, or it does not # match. If there is more than one match, it is an error.

It still looks like a bug :\ double implicitly converts to float and Foo.FOO exactly matches with Foo.

Foo and Bar implicitly also convert to int. There is no exact match for (double, Foo) thus all implicit conversions are checked: (double, int) - 2 hits (float, Foo) - 1 hits exact: 0 hits implicit: 3 hits -> Error Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCOmjW3w+/yD4P9tIRAhr1AJ9kVO+eDVUua4DOPm6Dw79cWfq5pgCfYThj gmUeuDtCvHU8T9wLjTNeMDM= =z87Y -----END PGP SIGNATURE-----
Mar 17 2005
parent reply "Regan Heath" <regan netwin.co.nz> writes:
On Fri, 18 Mar 2005 06:36:22 +0100, Thomas Kuehne  
<thomas-dloop kuehne.thisisspam.cn> wrote:
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1

 Vathix schrieb am Thu, 17 Mar 2005 11:02:37 -0500:
 On Thu, 17 Mar 2005 16:14:42 +0100, Thomas Kuehne
 <thomas-dloop kuehne.thisisspam.cn> wrote:
 Vathix schrieb am Wed, 16 Mar 2005 13:16:09 -0500:
 enum Foo { FOO }
 enum Bar { BAR }

 void foobar(float num, Foo f) { }
 void foobar(float num, Bar b) { }

 int main()
 {
     foobar(1.1, Foo.FOO);
     return 0; // Line 10.
 }


 DMD 0.118 output:
 test.d(10): function test.foobar called with argument types:
          (double,Foo )
 matches both:
          test.foobar(float,Foo )
 and:
          test.foobar(float,Bar )

 It looks like it's using the base of all parameters when only one  
 needs
 it.

# It matches exactly, it matches with implicit conversions, or it does not # match. If there is more than one match, it is an error.

It still looks like a bug :\ double implicitly converts to float and Foo.FOO exactly matches with Foo.

Foo and Bar implicitly also convert to int. There is no exact match for (double, Foo) thus all implicit conversions are checked: (double, int) - 2 hits (float, Foo) - 1 hits exact: 0 hits implicit: 3 hits -> Error

Can't it implicitly convert one, then the other, before doing both at once? i.e. do it in phases and only complain if multiple hits are found in each phase. i.e. [phase0] exact match [phase1] implicitly convert one param [phase2] implicitly convert two params ...etc.. so: [phase0] (double,Foo) [phase1] (float,Foo),(double,int),etc [phase2] (float,int),etc in this case a single match will be found in phase1: (float,Foo); Regan
Mar 18 2005
next sibling parent reply Vathix <vathix dprogramming.com> writes:
On Fri, 18 Mar 2005 23:03:08 +1300, Regan Heath <regan netwin.co.nz> wrote:

 Can't it implicitly convert one, then the other, before doing both at  
 once? i.e. do it in phases and only complain if multiple hits are found  
 in each phase. i.e.

 [phase0] exact match
 [phase1] implicitly convert one param
 [phase2] implicitly convert two params
 ...etc..

 so:

 [phase0] (double,Foo)
 [phase1] (float,Foo),(double,int),etc
 [phase2] (float,int),etc

 in this case a single match will be found in phase1: (float,Foo);

 Regan

That's what I was trying to explain. Thanks.
Mar 18 2005
parent "Regan Heath" <regan netwin.co.nz> writes:
On Fri, 18 Mar 2005 12:10:08 -0500, Vathix <vathix dprogramming.com> wrote:

 On Fri, 18 Mar 2005 23:03:08 +1300, Regan Heath <regan netwin.co.nz>  
 wrote:

 Can't it implicitly convert one, then the other, before doing both at  
 once? i.e. do it in phases and only complain if multiple hits are found  
 in each phase. i.e.

 [phase0] exact match
 [phase1] implicitly convert one param
 [phase2] implicitly convert two params
 ...etc..

 so:

 [phase0] (double,Foo)
 [phase1] (float,Foo),(double,int),etc
 [phase2] (float,int),etc

 in this case a single match will be found in phase1: (float,Foo);

 Regan

That's what I was trying to explain. Thanks.

I thought it might be :) We'll have to toss this idea round to find out if there are any problems with it, specifically the sort of complexity Walter has intentionally tried to avoid thus far. Regan
Mar 18 2005
prev sibling parent reply "Unknown W. Brackets" <unknown simplemachines.org> writes:
I think the issue is complication and confusion.  From what I've read 
Walter post, the overloading rules of C were complicated and the sources 
of much confusion for some.

And what phases would you do?  Which implict conversion is "more 
precendent"?  Which one should be done first?  Which one last?

-[Unknown]


 On Fri, 18 Mar 2005 06:36:22 +0100, Thomas Kuehne  
 <thomas-dloop kuehne.thisisspam.cn> wrote:
 
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1

 Vathix schrieb am Thu, 17 Mar 2005 11:02:37 -0500:

 On Thu, 17 Mar 2005 16:14:42 +0100, Thomas Kuehne
 <thomas-dloop kuehne.thisisspam.cn> wrote:

 Vathix schrieb am Wed, 16 Mar 2005 13:16:09 -0500:

 enum Foo { FOO }
 enum Bar { BAR }

 void foobar(float num, Foo f) { }
 void foobar(float num, Bar b) { }

 int main()
 {
     foobar(1.1, Foo.FOO);
     return 0; // Line 10.
 }


 DMD 0.118 output:
 test.d(10): function test.foobar called with argument types:
          (double,Foo )
 matches both:
          test.foobar(float,Foo )
 and:
          test.foobar(float,Bar )

 It looks like it's using the base of all parameters when only one  
 needs
 it.

# It matches exactly, it matches with implicit conversions, or it does not # match. If there is more than one match, it is an error.

It still looks like a bug :\ double implicitly converts to float and Foo.FOO exactly matches with Foo.

Foo and Bar implicitly also convert to int. There is no exact match for (double, Foo) thus all implicit conversions are checked: (double, int) - 2 hits (float, Foo) - 1 hits exact: 0 hits implicit: 3 hits -> Error

Can't it implicitly convert one, then the other, before doing both at once? i.e. do it in phases and only complain if multiple hits are found in each phase. i.e. [phase0] exact match [phase1] implicitly convert one param [phase2] implicitly convert two params ...etc.. so: [phase0] (double,Foo) [phase1] (float,Foo),(double,int),etc [phase2] (float,int),etc in this case a single match will be found in phase1: (float,Foo); Regan

Mar 18 2005
parent "Regan Heath" <regan netwin.co.nz> writes:
On Fri, 18 Mar 2005 15:58:26 -0800, Unknown W. Brackets  
<unknown simplemachines.org> wrote:
 I think the issue is complication and confusion.  From what I've read  
 Walter post, the overloading rules of C were complicated and the sources  
 of much confusion for some.

I understand his position and support it. I'm not sure this adds the same level of confusion that he is trying to avoid, we'll have to poke and prod it to find out :)
 And what phases would you do?

Phases 0 thru x, as shown below (and originally).
 Which implict conversion is "more precendent"?

Within each phase, no implicit conversion has "more precedent". The phases themselves do, phase 0 being the highest thru to phase x being the lowest. phase 0 being an explicit match. phase 1 being an implicit match where 1 of the params is implicitly cast. .. phase x being an implicit match where x of the params is implicitly cast.
 Which one should be done first?  Which one last?

Within each phase it doesn't matter. If 2 or more matches are found within a phase, it's an error. Regan
 On Fri, 18 Mar 2005 06:36:22 +0100, Thomas Kuehne   
 <thomas-dloop kuehne.thisisspam.cn> wrote:

 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1

 Vathix schrieb am Thu, 17 Mar 2005 11:02:37 -0500:

 On Thu, 17 Mar 2005 16:14:42 +0100, Thomas Kuehne
 <thomas-dloop kuehne.thisisspam.cn> wrote:

 Vathix schrieb am Wed, 16 Mar 2005 13:16:09 -0500:

 enum Foo { FOO }
 enum Bar { BAR }

 void foobar(float num, Foo f) { }
 void foobar(float num, Bar b) { }

 int main()
 {
     foobar(1.1, Foo.FOO);
     return 0; // Line 10.
 }


 DMD 0.118 output:
 test.d(10): function test.foobar called with argument types:
          (double,Foo )
 matches both:
          test.foobar(float,Foo )
 and:
          test.foobar(float,Bar )

 It looks like it's using the base of all parameters when only one   
 needs
 it.

# It matches exactly, it matches with implicit conversions, or it does not # match. If there is more than one match, it is an error.

It still looks like a bug :\ double implicitly converts to float and Foo.FOO exactly matches with Foo.

Foo and Bar implicitly also convert to int. There is no exact match for (double, Foo) thus all implicit conversions are checked: (double, int) - 2 hits (float, Foo) - 1 hits exact: 0 hits implicit: 3 hits -> Error

at once? i.e. do it in phases and only complain if multiple hits are found in each phase. i.e. [phase0] exact match [phase1] implicitly convert one param [phase2] implicitly convert two params ...etc.. so: [phase0] (double,Foo) [phase1] (float,Foo),(double,int),etc [phase2] (float,int),etc in this case a single match will be found in phase1: (float,Foo); Regan


Mar 18 2005