[Mono-bugs] [Bug 702467] New: a cycle in assignability rules (with variance) crashes the compiler

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Jun 27 15:53:03 EDT 2011


https://bugzilla.novell.com/show_bug.cgi?id=702467

https://bugzilla.novell.com/show_bug.cgi?id=702467#c0


           Summary: a cycle in assignability rules (with variance) crashes
                    the compiler
    Classification: Mono
           Product: Mono: Compilers
           Version: 2.10.x
          Platform: x86-64
        OS/Version: Linux
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: michael.miller at novell.com
        ReportedBy: grzegorz.herman at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: No


Description of Problem:

Compiling the following code causes dmcs to run into infinite recursion and
crash:

interface A<in B> where B: class {}
interface B<in A> where A: class {}
class X : A<B<X>>, A<Y> {}
class Y : B<A<Y>> {}
class Test {
  static void Main() {
    A<Y> ay = new X();
  }
}


Steps to reproduce the problem:
1. compile the above code snippet

Actual Results:
dmcs recurses infinitely:
..
  at Mono.CSharp.Convert.ImplicitReferenceConversionExists
(Mono.CSharp.Expression,Mono.CSharp.TypeSpec) <0x000ff>
  at Mono.CSharp.TypeSpecComparer/Variant.IsEqual
(Mono.CSharp.TypeSpec,Mono.CSharp.TypeSpec) <0x00397>
  at Mono.CSharp.TypeSpec.ImplementsInterface (Mono.CSharp.TypeSpec,bool)
<0x000bb>
..

Expected Results:
the code should compile: correctly or with an error

How often does this happen? 
always

Additional Information:
Apparently checking whether X is assignable to A<Y> causes the following
deduction loop:
X         ->   A<Y>     (use X's leftmost declared interface)
A<B<X>>   ->   A<Y>     (use A's contravariance)
B<X>      <-   Y        (use Y's leftmost declared interface)
B<X>      <-   B<A<X>>  (use B's contravariance)
X         ->   A<Y>
Putting A<Y> before A<B<X>> on X's interface list makes the code compile
cleanly.

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


More information about the mono-bugs mailing list