[nem-bug] [Nemerle 0000772]: Problem with overloading and implicit
conversions
feedback at nemerle.org
feedback at nemerle.org
Wed Nov 8 22:26:25 CET 2006
A NOTE has been added to this issue.
======================================================================
<http://nemerle.org/bugs/view.php?id=772>
======================================================================
Reported By: steffen
Assigned To:
======================================================================
Project: Nemerle
Issue ID: 772
Category: Compiler
Reproducibility: always
Severity: minor
Priority: normal
Status: new
======================================================================
Date Submitted: 10-01-2006 20:53 CEST
Last Modified: 11-08-2006 22:26 CET
======================================================================
Summary: Problem with overloading and implicit conversions
Description:
When implicit conversions are present, the compiler sometimes fails on
ambiguities.
For example the following C# program:
using System;
public class A {
public static implicit operator int (A a) {
Console.WriteLine ("Conversion A => int called.");
return 0;
}
public static implicit operator A (int a) {
Console.WriteLine ("Conversion int => A called.");
return null;
}
public static bool Func (A a1, A a2) {
Console.WriteLine ("Func (A, A) called");
return true;
}
public static bool Func (A a1, int a2) {
Console.WriteLine ("Func (A, int) called");
return true;
}
public static bool Func (int a1, A a2) {
Console.WriteLine ("Func (int, A) called");
return true;
}
public static void Main () {
A a1 = new A();
A a2 = new A();
Console.WriteLine (Func (a1, a2));
}
}
compiles and and runs fine:
Func (A, A) called
True
However, when I convert this program to nemerle with cs2n, the compiler
fails.
using System;
public class A {
public static @: ( a : A) : int {
Console.WriteLine ("Conversion A => int called.");
0;
}
public static @: ( a : int) : A {
Console.WriteLine ("Conversion int => A called.");
null;
}
public static Func (mutable a1 : A,mutable a2 : A) : bool {
Console.WriteLine ("Func (A, A) called");
true;
}
public static Func (mutable a1 : A,mutable a2 : int) : bool {
Console.WriteLine ("Func (A, int) called");
true;
}
public static Func (mutable a1 : int,mutable a2 : A) : bool {
Console.WriteLine ("Func (int, A) called");
true;
}
public static Main () : void {
mutable a1 = A();
mutable a2 = A();
Console.WriteLine (Func (a1, a2));
}
}
test.n:4:22:4:23: warning: N168: a function parameter a was never used
test.n:4:22:4:23: hint: replace name with `_' or prefix it like `_bar' to
avoid the warning
test.n:9:22:9:23: warning: N168: a function parameter a was never used
test.n:14:32:14:34: warning: N168: a function parameter a1 was never used
test.n:14:48:14:50: warning: N168: a function parameter a2 was never used
test.n:19:32:19:34: warning: N168: a function parameter a1 was never used
test.n:19:48:19:50: warning: N168: a function parameter a2 was never used
test.n:24:32:24:34: warning: N168: a function parameter a1 was never used
test.n:24:50:24:52: warning: N168: a function parameter a2 was never used
test.n:33:24:33:28: error: typing fails on ambiguity between overloads:
method A.Func(a1 : A, a2 : int) : bool
method A.Func(a1 : A, a2 : A) : bool
method A.Func(a1 : int, a2 : A) : bool
The compiler should choose A.Func(a1 : A, a2 : A) : bool in this case.
======================================================================
----------------------------------------------------------------------
malekith - 11-08-06 22:26
----------------------------------------------------------------------
This is because when we compare overloads we don't take implicit conversion
into account, so A and int are incomparable. I'll look into it.
Issue History
Date Modified Username Field Change
======================================================================
10-01-06 20:53 steffen New Issue
11-08-06 22:26 malekith Note Added: 0001494
======================================================================
More information about the bugs
mailing list