[Mono-bugs] [Bug 415314] New: Generic constructor constraint checking erroneously reports default constructor missing if superclass has said generic parameter and non-public zero-argument constructor
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Wed Aug 6 22:55:43 EDT 2008
https://bugzilla.novell.com/show_bug.cgi?id=415314
Summary: Generic constructor constraint checking erroneously
reports default constructor missing if superclass has
said generic parameter and non-public zero-argument
constructor
Product: Mono: Compilers
Version: 2.0
Platform: x86-64
OS/Version: openSUSE 10.3
Status: NEW
Severity: Normal
Priority: P5 - None
Component: C#
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: other+novell at bluecherry.net
QAContact: mono-bugs at lists.ximian.com
Found By: ---
Created an attachment (id=232145)
--> (https://bugzilla.novell.com/attachment.cgi?id=232145)
Demonostration of bug (Class1.cs) and demonstration of using the constructor
the bug says doesn't exist (Class2.cs)
CS0310 is reported on a class that has a zero-argument default constructor when
subclassing a base class with a type constraint such that the generic parameter
is the subclass.
Example (from attached Class1.cs):
public class Generic<T> where T : Generic<T>, new() {
protected Generic() { }
}
public class Implementation : Generic<Implementation> {
}
The "Implementation" class has a default constructor that implicitly calls the
base class's protected Generic(), thus it should meet the new() constraint on T
from Generic<T>. However, gmcs reports:
Class1.cs(9,35): error CS0310: The type `TestCase.Implementation' must have a
public parameterless constructor in order to use it as parameter `T' in the
generic type or method `TestCase.Generic<T>'
Class1.cs(6,18): (Location of the symbol related to previous error)
Class1.cs(9,18): (Location of the symbol related to previous error)
This error is not reported with csc.exe (2.0).
Strangely, it does not happen if the constraint is not done as part of the
inheritance on itself, such as (Class3.cs):
public class Generic<T> where T : new() { }
public class Base {
protected Base() { }
}
public class Derived : Base { }
public class Test {
private Generic<Derived> var;
}
The above sample works fine and does not report a compile error.
This was tested with both the preview release 2.0 and SVN (revision 109742).
--
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