Home Dashboard Directory Help

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


 as Fixed Help for as Fixed

Sign in
to vote
Type: Bug
ID: 281814
Opened: 6/7/2007 3:03:38 AM
Access Restriction: Public
User(s) can reproduce this bug


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.
Sign in to post a workaround.