[Mono-bugs] [Bug 414153] New: Compiler error when implementing interface with generic constraint

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sat Aug 2 08:05:24 EDT 2008


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


           Summary: Compiler error when implementing interface with generic
                    constraint
           Product: Mono: Compilers
           Version: 1.9
          Platform: x86-64
        OS/Version: Linux
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: mono at e-tobi.net
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


When having a generic constraint in an interface, The gmcs fails to compile any
implementor of this interface, when one generic parameter is a constraint of
the other.

Compiling this code:

using System;

public interface IFoo
{
    void Bar<U, V>() where V : U;
}

public class Foo: IFoo
{
    public void Bar<U, V>() where V : U
    {
    }

    static public void Main ()
    {
    }
}

I get this compiler error:

$ gmcs --version ; gmcs test2.cs 
Mono C# compiler version 1.9.1.0

Unhandled Exception: Mono.CSharp.InternalErrorException: test2.cs(10,17):
Foo.Bar<U,V>() ---> System.IndexOutOfRangeException: Array index is out of
range.
  at Mono.CSharp.TypeParameter+InflatedConstraints.inflate (System.Type t)
[0x00000] 
  at Mono.CSharp.TypeParameter+InflatedConstraints..ctor
(Mono.CSharp.GenericConstraints gc, System.Type[] dargs) [0x00000] 
  at Mono.CSharp.TypeParameter+InflatedConstraints..ctor
(Mono.CSharp.GenericConstraints gc, System.Type declaring) [0x00000] 
  at Mono.CSharp.TypeParameter.DefineType (IResolveContext ec,
System.Reflection.Emit.MethodBuilder builder, System.Reflection.MethodInfo
implementing, Boolean is_override) [0x00000] 
  at Mono.CSharp.GenericMethod.DefineType (Mono.CSharp.EmitContext ec,
System.Reflection.Emit.MethodBuilder mb, System.Reflection.MethodInfo
implementing, Boolean is_override) [0x00000] 
  at Mono.CSharp.MethodData.Define (Mono.CSharp.DeclSpace parent) [0x00000] 
  at Mono.CSharp.MethodOrOperator.Define () [0x00000] 
  at Mono.CSharp.Method.Define () [0x00000] 
  at Mono.CSharp.TypeContainer+MemberCoreArrayList.DefineContainerMembers ()
[0x00000] --- End of inner exception stack trace ---

  at Mono.CSharp.TypeContainer+MemberCoreArrayList.DefineContainerMembers ()
[0x00000] 
  at Mono.CSharp.TypeContainer.DefineContainerMembers
(Mono.CSharp.MemberCoreArrayList mcal) [0x00000] 
  at Mono.CSharp.Class.DefineContainerMembers (Mono.CSharp.MemberCoreArrayList
list) [0x00000] 
  at Mono.CSharp.TypeContainer.DoDefineMembers () [0x00000] 
  at Mono.CSharp.Class.DoDefineMembers () [0x00000] 
  at Mono.CSharp.TypeContainer.DefineMembers () [0x00000] 
  at Mono.CSharp.RootContext.PopulateTypes () [0x00000] 
  at Mono.CSharp.Driver.MainDriver (System.String[] args) [0x00000] 
  at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] 


This works fine:

using System;

public interface IBar
{
}

public interface IFoo
{
    void Bar<U, V>() where V : IBar;
}

public class Foo: IFoo
{
    public void Bar<U, V>() where V : IBar
    {
    }

    static public void Main ()
    {
    }
}


-- 
Configure bugmail: https://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