|
Bugzilla – Full Text Bug Listing |
| Summary: | Generic constructor constraint checking erroneously reports default constructor missing if superclass has said generic parameter and non-public zero-argument constructor | ||
|---|---|---|---|
| Product: | [Mono] Mono: Compilers | Reporter: | Scott Oom <other+novell> |
| Component: | C# | Assignee: | Mono Bugs <mono-bugs> |
| Status: | RESOLVED DUPLICATE | QA Contact: | Mono Bugs <mono-bugs> |
| Severity: | Normal | ||
| Priority: | P5 - None | ||
| Version: | 2.0.x | ||
| Target Milestone: | --- | ||
| Hardware: | x86-64 | ||
| OS: | openSUSE 10.3 | ||
| Whiteboard: | |||
| Found By: | --- | Services Priority: | |
| Business Priority: | Blocker: | --- | |
| Marketing QA Status: | --- | IT Deployment: | --- |
| Attachments: | Demonostration of bug (Class1.cs) and demonstration of using the constructor the bug says doesn't exist (Class2.cs) | ||
Duplicate. *** This bug has been marked as a duplicate of bug 324319 *** |
Created attachment 232145 [details] 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).