[Mono-bugs] [Bug 457087] Generic constrained fails to compile

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Dec 11 06:35:32 EST 2008


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

User mono at e-tobi.net added comment
https://bugzilla.novell.com/show_bug.cgi?id=457087#c1


Tobias Grimm <mono at e-tobi.net> changed:

           What    |Removed                                         |Added
----------------------------------------------------------------------------
                 CC|                                                |mono at e-tobi.net
            Summary|Complexe generics / lambda scenario causes      |Generic constrained fails to compile
                   |compiler to fail                                |




--- Comment #1 from Tobias Grimm <mono at e-tobi.net>  2008-12-11 04:35:30 MST ---
Sorry, I made this more complex than needed. First of all - Lambdas are not
involved at all. The problem is much more simple:

namespace Test
{
    public class Bar<T, U>
    {
        public void DoSomething<V>() where V : U
        {
        }
    }

    public class Baz
    {
        public void GetInTroubleHere()
        {
            var bar = new Bar<String, String>();
            bar.DoSomething<String>();
        }
    }
}

The above code fails to compile (see output below).
If I declare the class Bar as Bar<U, T> instead, it works fine. So the problem
happens only, if the constrained in a class uses a classes second generic
parameter.

What Happens is, that...

    typeof(Bar<String,String>).GetMethod ("DoSomething").GetGenericArguments()

.. only returns an array with a single generic argument (V in this case).
In CheckConstraint() this array is "atypes" and because the position of U is 1,
atypes[1] fails.

This bug is really annoying, because it blocks me from using StructureMap with
Mono.

----

Here's the error output produced by the compiler:

[mono-trunk] /tmp @ MONO_OPTIONS=--debug gmcs test.cs
Exception caught by the compiler while compiling:
   Block that caused the problem begin at: test.cs(14,21):
                     Block being compiled: [test.cs(15,9):,test.cs(18,9):]
System.IndexOutOfRangeException: Array index is out of range.
Internal compiler error at test.cs(14,21):: exception caught while emitting
MethodBuilder [Baz::GetInTroubleHere]

Unhandled Exception: System.IndexOutOfRangeException: Array index is out of
range.
  at Mono.CSharp.ConstraintChecker.CheckConstraint (IResolveContext ec,
System.Type ptype, Mono.CSharp.Expression expr, System.Type ctype) [0x000a4] in
/home/tobias/sandbox/x/mcs/mcs/generic.cs:1466 
  at Mono.CSharp.ConstraintChecker.CheckConstraints (IResolveContext ec, Int32
index) [0x0018d] in /home/tobias/sandbox/x/mcs/mcs/generic.cs:1412 
  at Mono.CSharp.ConstraintChecker.CheckConstraints (IResolveContext ec)
[0x00007] in /home/tobias/sandbox/x/mcs/mcs/generic.cs:1335 
  at Mono.CSharp.ConstraintChecker.CheckConstraints (Mono.CSharp.EmitContext
ec, System.Reflection.MethodBase definition, System.Reflection.MethodBase
instantiated, Location loc) [0x00014] in
/home/tobias/sandbox/x/mcs/mcs/generic.cs:1553 
  at Mono.CSharp.MethodGroupExpr.OverloadResolve (Mono.CSharp.EmitContext ec,
System.Collections.ArrayList& Arguments, Boolean may_fail, Location loc)
[0x00875] in /home/tobias/sandbox/x/mcs/mcs/ecore.cs:4415 
  at Mono.CSharp.Invocation.DoResolveOverload (Mono.CSharp.EmitContext ec)
[0x00000] in /home/tobias/sandbox/x/mcs/mcs/expression.cs:4859 
  at Mono.CSharp.Invocation.DoResolve (Mono.CSharp.EmitContext ec) [0x0013e] in
/home/tobias/sandbox/x/mcs/mcs/expression.cs:4799 
  at Mono.CSharp.Expression.Resolve (Mono.CSharp.EmitContext ec, ResolveFlags
flags) [0x00075] in /home/tobias/sandbox/x/mcs/mcs/ecore.cs:488 
  at Mono.CSharp.Expression.Resolve (Mono.CSharp.EmitContext ec) [0x00000] in
/home/tobias/sandbox/x/mcs/mcs/ecore.cs:515 
  at Mono.CSharp.ExpressionStatement.ResolveStatement (Mono.CSharp.EmitContext
ec) [0x00000] in /home/tobias/sandbox/x/mcs/mcs/ecore.cs:1311 
  at Mono.CSharp.StatementExpression.Resolve (Mono.CSharp.EmitContext ec)
[0x0000b] in /home/tobias/sandbox/x/mcs/mcs/statement.cs:743 
  at Mono.CSharp.Block.Resolve (Mono.CSharp.EmitContext ec) [0x000f0] in
/home/tobias/sandbox/x/mcs/mcs/statement.cs:2241 
  at Mono.CSharp.ExplicitBlock.Resolve (Mono.CSharp.EmitContext ec) [0x00000]
in /home/tobias/sandbox/x/mcs/mcs/statement.cs:2541 
  at Mono.CSharp.EmitContext.ResolveTopBlock (Mono.CSharp.EmitContext
anonymous_method_host, Mono.CSharp.ToplevelBlock block, Mono.CSharp.Parameters
ip, IMethodData md, System.Boolean& unreachable) [0x00087] in
/home/tobias/sandbox/x/mcs/mcs/codegen.cs:799 


-- 
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