C# compiler issues inappropiate error message if type of const is a type parameter - by Vladimir Reshetnikov

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 281814 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 6/7/2007 3:03:38 AM
Access Restriction Public


Try to compile the following code:
class Program
    static void Foo<T>() where T : class 
        const T x = null;

Compiler (version 8.00.50727.42) issues a compile-time error (error CS0134: 'x' is of type 'T.' A const of reference type other than string can only be initialized with null). The message is inappropiate here. Should be a kind of 'The type specified in a constant declaration shall be sbyte, byte, short, ushort, int, uint, long,
ulong, char, float, double, decimal, bool, string, an enum-type, or a reference-type.'
Sign in to post a comment.
Posted by Microsoft on 6/11/2007 at 3:07 PM
Thank you for logging this issue.

It is indeed a bug, and your proposed fix is what should happen. Unfortunately this is one that we don't dare to fix at this point in the product cycle - the impact of the bug is limited, and fixing it is less trivial than it looks; which increases the risk of introducing other late bugs. We will revisit this for the next product cycle.

Thanks again,

Mads Torgersen, C# language PM
Posted by Microsoft on 6/7/2007 at 3:13 AM
Thanks for your feedback. We have reproduced this bug on Visual Studio Codename Orcas Beta1, and we are sending this bug to the appropriate group within the VisualStudio Product Team for triage and resolution.

Thank you,
Visual Studio Product Team.