Skip to content

Conversation

@AlekseyTs
Copy link
Contributor

@AlekseyTs
Copy link
Contributor Author

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

@AlekseyTs
Copy link
Contributor Author

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

1 similar comment
@AlekseyTs
Copy link
Contributor Author

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

@cston
Copy link
Contributor

cston commented Oct 4, 2022

";

Consider testing:

(scoped _, var a) = r;
(scoped scoped _, var b) = r;

In reply to: 1267291775


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs:11206 in 4df2321. [](commit_id = 4df2321, deletion_comment = False)

@cston
Copy link
Contributor

cston commented Oct 4, 2022

}";

Consider testing:

M1(out scoped _);
M1(out scoped scoped _);

In reply to: 1267317245


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs:10647 in 4df2321. [](commit_id = 4df2321, deletion_comment = False)

@cston
Copy link
Contributor

cston commented Oct 4, 2022

            Diagnostic(ErrorCode.ERR_RefReturnParameter, "r0").WithArguments("r0").WithLocation(11, 30)

These errors look unnecessary. This might be #64448, if not already fixed in #64318.


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs:11540 in 4df2321. [](commit_id = 4df2321, deletion_comment = False)

@RikkiGibson
Copy link
Member

Is this change being considered for 17.4?

@AlekseyTs
Copy link
Contributor Author

Is this change being considered for 17.4?

Not at the moment. Do you think it should be?

@cston
Copy link
Contributor

cston commented Oct 4, 2022

            Diagnostic(ErrorCode.ERR_EscapeVariable, "s1").WithArguments("s1").WithLocation(7, 15)

This looks like #64448.


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs:11896 in 4df2321. [](commit_id = 4df2321, deletion_comment = False)

@RikkiGibson
Copy link
Member

Is this change being considered for 17.4?

Not at the moment. Do you think it should be?

My preference would be to do it in 17.5.

@cston
Copy link
Contributor

cston commented Oct 4, 2022

";

Consider testing:

{
    int i1 = 1;
    (new S(ref i1)).M(out scoped S1);
    s0 = s1;
}
{
    int i1 = 1;
    (new S(ref i1)).M(out var S1);
    s0 = s1;
}
{
    int i1 = 1;
    (new S(ref i1)).M(out scoped var S1);
    s0 = s1;
}

Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs:12289 in 4df2321. [](commit_id = 4df2321, deletion_comment = False)

Copy link
Contributor

@cston cston left a comment

Choose a reason for hiding this comment

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

LGTM, with a few test suggestions.

@AlekseyTs
Copy link
Contributor Author

@RikkiGibson, @dotnet/roslyn-compiler For the second review.

2 similar comments
@AlekseyTs
Copy link
Contributor Author

@RikkiGibson, @dotnet/roslyn-compiler For the second review.

@AlekseyTs
Copy link
Contributor Author

@RikkiGibson, @dotnet/roslyn-compiler For the second review.

@RikkiGibson RikkiGibson self-assigned this Oct 7, 2022
@AlekseyTs
Copy link
Contributor Author

@RikkiGibson, @dotnet/roslyn-compiler For the second review.

1 similar comment
@AlekseyTs
Copy link
Contributor Author

@RikkiGibson, @dotnet/roslyn-compiler For the second review.

@cston
Copy link
Contributor

cston commented Oct 12, 2022

            //             (new S(ref i1)).M(out S s1);

Is the error because of out S s1? Is s1 being inferred as scoped but not scoped to the nested block?


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs:12693 in 66a1623. [](commit_id = 66a1623, deletion_comment = False)

@AlekseyTs
Copy link
Contributor Author

@cston

Is the error because of out S s1? Is s1 being inferred as scoped but not scoped to the nested block?

I am having a hard time mapping this question to a specific location in source. Could you repost it relative to the current state of the branch?

@cston
Copy link
Contributor

cston commented Oct 12, 2022

I am having a hard time mapping this question to a specific location in source. Could you repost it relative to the current state of the branch?

The comment was referring to the error reported for (new S(ref i1)).M(out S s1); in LocalScope_12_OutVar.

@AlekseyTs
Copy link
Contributor Author

I cannot comment about reasons why the errors are reported, simply didn't dig into that. The behavior is consistent with behavior when out var declaration isn't used:

        int i0 = 0;
        S s0 = new S(ref i0);
        {
            int i1 = 1;
            S s1;
            (new S(ref i1)).M(out s1);
            s0 = s1;
        }

{
parent = node.Parent as DeclarationExpressionSyntax;
return node == parent?.Type;
parent = node.ModifyingScopedOrRefTypeOrSelf().Parent as DeclarationExpressionSyntax;
Copy link
Member

@RikkiGibson RikkiGibson Oct 10, 2022

Choose a reason for hiding this comment

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

What is the difference between node.ModifyingScopedOrRefTypeOrSelf() and node.SkipScoped(out _).SkipRef(out _)? #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.

What is the difference between node.ModifyingScopedOrRefTypeOrSelf() and node.SkipScoped(out _).SkipRef(out _)?

ModifyingScopedOrRefTypeOrSelf goes up (to the parent), "skip" helpers go down (to the child). They are, effectively, opposite operations.

var discard = tree.GetRoot().DescendantNodes().OfType<DiscardDesignationSyntax>().ToArray();
Assert.Equal(8, discard.Length);

for (int i = 0; i < 6; i++)
Copy link
Member

@RikkiGibson RikkiGibson Oct 12, 2022

Choose a reason for hiding this comment

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

I didn't understand why the last 2 discard elements are not checked (since length was asserted to be 8 above). #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.

I didn't understand why the last 2 discard elements are not checked (since length was asserted to be 8 above).

The last two discards refer to an undeclared type, do not align with the rest, and are not really interesting for the purpose of the test.

@AlekseyTs AlekseyTs merged commit f020a37 into dotnet:main Oct 13, 2022
@ghost ghost added this to the Next milestone Oct 13, 2022
@RikkiGibson RikkiGibson modified the milestones: Next, 17.5 P1 Oct 24, 2022
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.

No error reported for ref type in a declaration expression

3 participants