[nem-bug] [Nemerle 0000833]: Incorrect ambiguous

feedback at nemerle.org feedback at nemerle.org
Sun Feb 4 17:45:39 CET 2007


A NOTE has been added to this issue.
======================================================================
<http://nemerle.org/bugs/view.php?id=833> 
======================================================================
Reported By:                VladD2
Assigned To:                
======================================================================
Project:                    Nemerle
Issue ID:                   833
Category:                   Compiler
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
======================================================================
Date Submitted:             01-21-2007 14:43 CET
Last Modified:              02-04-2007 17:45 CET
======================================================================
Summary:                    Incorrect ambiguous
Description: 
public class A : System.IEquatable[A]
{
  public override Equals (other : object) : bool { this == other }
  public Equals (other : A) : bool { this : object == other }
}
-------------------------------------------------------------
Main.n(4,3,4,62): error : ambiguous implements-match for interface
method(s):
[method System.IEquatable.Equals(other : T.0) : bool], please 
use explicit implementation
======================================================================

----------------------------------------------------------------------
 VladD2 - 01-21-07 14:57 
----------------------------------------------------------------------
One more example:
using System;
public class A : System.IEquatable[A]
{
}

def a = A();
def b : System.IEquatable[A] = a;
Console.WriteLine(a.Equals(a));
Console.WriteLine(a.Equals(b));
Console.WriteLine(b.Equals(a));
------------------------------------------
Compile and run OK.

----------------------------------------------------------------------
 nazgul - 01-21-07 20:30 
----------------------------------------------------------------------
This is because Equals (object) is a valid implementation of Equals (A)
interface method (considering contravariance)... So I would call it a
feature :)

On the other hand we could do better here and order methods by "how well"
do they match interface method and then signal error if it is still
ambiguous.

----------------------------------------------------------------------
 nazgul - 01-21-07 20:32 
----------------------------------------------------------------------
The second example works just for the same reason - compiler finds Equals
(object) in parten class and uses it for implementing Equals (A)
requirement. This is a bit unfortunate in this situation (compiler do not
catch the most probable intention of user... but I would leave it as it
is)

----------------------------------------------------------------------
 VladD2 - 02-04-07 17:45 
----------------------------------------------------------------------
C# (example 1):
public class A : System.IEquatable<A>
{
  public override bool Equals (object other) { return this == other; }
  public bool Equals(A other) { return (object)this == other; }
}
Compile OK.
--------------------------------------------------------------------
C# (example 2):
public class A : System.IEquatable<A>
{
}
E: CS0535: 'A' does not implement interface member
'System.IEquatable<A>.Equals(A)'
--------------------------------------------------------------------
C# behavior is logically and intuitively clearly.
In my option, current Nemerle behavior is a bug.

Issue History
Date Modified  Username       Field                    Change              
======================================================================
01-21-07 14:43 VladD2         New Issue                                    
01-21-07 14:57 VladD2         Note Added: 0001619                          
01-21-07 20:30 nazgul         Note Added: 0001621                          
01-21-07 20:32 nazgul         Note Added: 0001622                          
02-04-07 17:45 VladD2         Note Added: 0001673                          
======================================================================




More information about the bugs mailing list