-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test/implement some aspects of primary constructor parameter capturing. #66499
Test/implement some aspects of primary constructor parameter capturing. #66499
Conversation
1 similar comment
// (2,7): error CS0177: The out parameter 'y' must be assigned to before control leaves the current method | ||
// class C1(out int x, out S s, out string y) | ||
Diagnostic(ErrorCode.ERR_ParamUnassigned, "C1").WithArguments("y").WithLocation(2, 7), | ||
// (6,13): error CS1628: Cannot use ref, out, or in parameter 'x' inside an anonymous method, lambda expression, query expression, or local function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message seems incorrect since there is no lambda or local function involved. Should the message be updated or a distinct error reported?
This is tracked by a PROTOTYPE comment on line 13036.
public void ParameterCapturing_095_DefiniteAssignment() | ||
{ | ||
var text = @" | ||
class C1(out int x, out S s, out string y) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider also testing ref
and in
primary constructor parameters. #Pending
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider also testing
ref
andin
primary constructor parameters.
They cannot be captured. The goal here was to make sure we do not also require assigning out
parameters in methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add suggested tests as ParameterCapturing_100_DefiniteAssignment and ParameterCapturing_101_DefiniteAssignment in the next PR
// int f1 = y; | ||
Diagnostic(ErrorCode.ERR_UseDefViolationOut, "y").WithArguments("y").WithLocation(4, 14) | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider testing with a partial class
:
var text1 = @"
partial class C1(out int x, out int y)
{
int f1 = y;
int xx = x = 1;
}
";
var text2 = @"
partial class C1
{
int f2 = x;
int yy = y = 1;
}
";
CreateCompilation(new[] { text1, text2 }).VerifyEmitDiagnostics(...);
CreateCompilation(new[] { text2, text1 }).VerifyEmitDiagnostics(...);
``` #Pending
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding DefiniteAssignment_07 in the next PR
@jjonescz, https://github.com/orgs/dotnet/teams/roslyn-compiler For the second review |
No description provided.