[Mono-bugs] [Bug 522677] Ambiguity resolving in inhereted interface polymorphism reversed in comparison to .net

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed May 19 18:35:58 EDT 2010


http://bugzilla.novell.com/show_bug.cgi?id=522677

http://bugzilla.novell.com/show_bug.cgi?id=522677#c3


Nikos Sarris <nsarris79 at hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEEDINFO                    |NEW
       InfoProvider|nsarris79 at hotmail.com       |

--- Comment #3 from Nikos Sarris <nsarris79 at hotmail.com> 2010-05-19 22:35:57 UTC ---
(In reply to comment #2)
> could you provide C# compatible test case

This was quite a while back. I tested it with 2.6 and seems to be fixed, the
problem was at 2.2 (tested it again to be sure).

Just for the sake of it:
Example

interface A
{event EventHandler Member;}

interface B : A
{ new event EventHandler Member;}

interface BA : B,A    {}

public class C : BA
{

EventHandler _AMember;
EventHandler _Member;

event EventHandler A.Member
{
add { _AMember += value; Console.WriteLine("Setting A Event"); }
remove { _AMember -= value; }
}

public event EventHandler Member
{
add { _Member+=value; Console.WriteLine("Setting Direct Event"); }
remove { _Member-=value; }
}

} 

public class Test
{
public void TestMe()
{
C c = new C();
Console.WriteLine("Trying to set EventHandler Directly - should set Direct
Event ");
c.Member += new EventHandler(f);

Console.WriteLine("Trying to set EventHandler through A interface - Should set
A Event");
((A)c).Member += new EventHandler(f);

Console.WriteLine("Trying to set EventHandler through BA interface - Should set
Direct Event");
((BA)c).Member += new EventHandler(f);
}

void f(object sender,EventArgs e){}

}

Explanation:

A and B define the same member event.Interface BA inherits both in that order
(B then A). Class C implements both BA. 

Event from interface A is explicitly implemeted, so a direct call refers to B.
The test sets the member event directly (through C.Member) then thorugh
interface A, then through interface BA.

A call through C should refer to the direct member. A call through A should
refer to the explicitely defined A member.

A call through BA is ambigious as both B and A define the same member. In .net
this is resolved by selecting the first interface in the definition list(thus
B). So ((BA)c).Member += new EventHandler(f); would set _Member


In mono 2.2 it was selecting the last interface (thus A). So ((BA)c).Member +=
new EventHandler(f); would incorrectly set _AMember

In mono 2.6 it seems to be fixed to comply with .net

So I guess this bug can be safely closed.

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list