-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Open
Labels
Area-CompilersConcept-Diagnostic ClarityThe issues deals with the ease of understanding of errors and warnings.The issues deals with the ease of understanding of errors and warnings.Feature - Primary Constructorshelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on itThe issue is "up for grabs" - add a comment if you are interested in working on it
Milestone
Description
CS9105 is reported either when accessing the primary constructor within a static context (see here), or within another constructor (see here). As stated in #82351, this could be improved by adding a separate error for when it occurs in a static context, to point the problem out more clearly
Sample with static context (first link):
class Program(int item)
{
static void Main()
{
item.ToString(); // error CS9105: Cannot use primary constructor parameter 'int item' in this context.
// Compare with:
this.ToString(); // error CS0026: Keyword 'this' is not valid in a static property, static method, or static field initializer
}
}
/Program.cs(5,9): error CS9105: Cannot use primary constructor parameter 'int item' in this context.
Sample with another constructor (second link):
class Program(int item)
{
public Program(float f) : this(0) {
_ = item;
}
}
/Program.cs(4,13): error CS9105: Cannot use primary constructor parameter 'int item' in this context.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Area-CompilersConcept-Diagnostic ClarityThe issues deals with the ease of understanding of errors and warnings.The issues deals with the ease of understanding of errors and warnings.Feature - Primary Constructorshelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on itThe issue is "up for grabs" - add a comment if you are interested in working on it