[nem-bug] [Nemerle 0001023]: Type parameter constraints are not checked correctly

feedback at nemerle.org feedback at nemerle.org
Thu Sep 6 12:47:13 CEST 2007


A NOTE has been added to this issue.
======================================================================
<http://nemerle.org/bugs/view.php?id=1023> 
======================================================================
Reported By:                nikov
Assigned To:                
======================================================================
Project:                    Nemerle
Issue ID:                   1023
Category:                   Compiler (type engine)
Reproducibility:            always
Severity:                   major
Priority:                   normal
Status:                     new
======================================================================
Date Submitted:             06-06-2007 09:20 CEST
Last Modified:              09-06-2007 12:47 CEST
======================================================================
Summary:                    Type parameter constraints are not checked correctly
Description: 
[nemerle]
abstract class Base[T]
{
    public abstract Foo[S](obj : S) : void where S : T;
}

class Derived : Base[int?]
{
    public override Foo[S](obj : S) : void
    {
        Bar(obj);
    }

    static Bar[T](obj : T) : void where T : struct
    {
        
    }

    static Main() : void
    {
        Derived().Foo.[int?](1);
    }
}
[/nemerle]

This code compiles, but when it runs, JIT-compilation of Derived.Foo[S]
throws VerificationException. Obviously, nullable type int? does not match
'struct' constraint.
======================================================================

----------------------------------------------------------------------
 nazgul - 09-06-07 12:40 
----------------------------------------------------------------------
The funny part is that C# 2.0 compiler has the same problem... - it
compiles the equivalent code, which then fails at runtime.

----------------------------------------------------------------------
 nazgul - 09-06-07 12:47 
----------------------------------------------------------------------
In C# this 

Foo<int?> x;

class Foo <X> where X : struct
{
}

gives error
t.cs(8,14): error CS0453: The type 'int?' must be a non-nullable value
type in order to use it as parameter 'X' in the generic type or method
'Foo<X>'
t.cs(26,7): (Location of symbol related to previous error)


so it really seems that nullables does not fulfill struct constraint and
this is  C# compiler bug.

After recent fixes in constraints handling ncc does no longer compile the
mentioned code, so I will add a testcase and resolve this issue.

Issue History
Date Modified  Username       Field                    Change              
======================================================================
06-06-07 09:20 nikov          New Issue                                    
06-06-07 09:20 nikov          Summary                  Type parameter constrants
are not checked correctly => Type parameter constraints are not checked
correctly
06-06-07 09:20 nikov          Description Updated                          
06-28-07 23:09 divan          Issue Monitored: divan                       
09-06-07 12:40 nazgul         Note Added: 0001954                          
09-06-07 12:47 nazgul         Note Added: 0001955                          
======================================================================




More information about the bugs mailing list