Skip to content
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

Conversation

AlekseyTs
Copy link
Contributor

No description provided.

@AlekseyTs
Copy link
Contributor Author

@cston, @jjonescz, @dotnet/roslyn-compiler Please review.

1 similar comment
@AlekseyTs
Copy link
Contributor Author

@cston, @jjonescz, @dotnet/roslyn-compiler Please review.

// (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
Copy link
Member

@cston cston Jan 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot use ref, out, or in parameter 'x' inside an anonymous method, lambda expression, query expression, or local function

The message seems incorrect since there is no lambda or local function involved. Should the message be updated or a distinct error reported? #Resolved

Copy link
Contributor Author

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)
Copy link
Member

@cston cston Jan 23, 2023

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

Copy link
Contributor Author

@AlekseyTs AlekseyTs Jan 23, 2023

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.

They cannot be captured. The goal here was to make sure we do not also require assigning out parameters in methods.

Copy link
Contributor Author

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)
);
}
Copy link
Member

@cston cston Jan 23, 2023

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

Copy link
Contributor Author

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

@AlekseyTs
Copy link
Contributor Author

@cston, @jjonescz, @dotnet/roslyn-compiler Please review.

@AlekseyTs
Copy link
Contributor Author

@AlekseyTs AlekseyTs merged commit e2a08b5 into dotnet:features/PrimaryConstructors Jan 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants