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

Deconstruction into dynamic array and dynamic indexer #13724

Merged
merged 1 commit into from
Sep 12, 2016

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Sep 10, 2016

The deconstruction lowering uses TransformCompoundAssignmentLHS to capture the side-effects of left-hand-side variables and get symbols back for writing into those references. But we were always passing isDynamicAssignment as false.
It turns out that is a bug and I added some tests that hit that case. Before this fix, those tests produce code that fails at runtime with System.ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array.

In this process, I found out that lowering of some of the assignment steps (that are part of the deconstruction) would fail because they would would not switch on the proper Kind in VisitAssignmentOperator. It would switch on the kind of the unlowered left (ie the kind of the placeholder), instead of the proper kind DynamicIndexerAccess.
After this fix, lowering of the assignment step directly makes lowered assignment nodes with MakeAssignmentOperator instead of calling VisitExpression on the un-lowered assignment node.

Fixes #12398

@AlekseyTs @dotnet/roslyn-compiler for review.

@jcouv
Copy link
Member Author

jcouv commented Sep 12, 2016

@AlekseyTs @dotnet/roslyn-compiler for review. Thank

comp.VerifyDiagnostics();
// No runtime failure (System.ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array.)
// because of the special handling for dynamic in LocalRewriter.TransformCompoundAssignmentLHS
}
Copy link
Member

Choose a reason for hiding this comment

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

Was this just a missing test or does the test hit the rewriter changes?

Copy link
Member Author

@jcouv jcouv Sep 12, 2016

Choose a reason for hiding this comment

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

This test hits the change I made. Prior to the fix, this test would produce a runtime exception.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ignore my last comment. This test was not crashing.
But we were missing a test that verifies execution of compound assignment with dynamic array.

@cston
Copy link
Member

cston commented Sep 12, 2016

LGTM

var rewrittenRight = (BoundExpression)Visit(assignment.Right);

var loweredAssignment = MakeAssignmentOperator(assignment.Syntax, rewrittenLeft, rewrittenRight, assignment.Type,
used: true, isChecked: false, isCompoundAssignment: false);
Copy link
Contributor

Choose a reason for hiding this comment

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

isChecked: false [](start = 56, length = 16)

What difference does this parameter make?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure. I'm using the same option that the previous code was using. The local rewriter's VisitAssignmentOperator is implicitly setting isChecked to false (by omission) when it calls MakeDynamicSetIndex or MakeDynamicSetMember.

@AlekseyTs
Copy link
Contributor

LGTM

@jcouv jcouv merged commit ed41c22 into dotnet:master Sep 12, 2016
@jcouv
Copy link
Member Author

jcouv commented Sep 12, 2016

Thanks! Going ahead with merge.

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.

Verify the behavior of dynamic in deconstructions
4 participants