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

Recursively check if assignment target expression is valid, don't copy returned values #288

Merged
merged 3 commits into from Aug 5, 2020

Conversation

turbolent
Copy link
Member

Instead of just checking if the outer-most expression which is assigned to is assignable, recursively check if it is assignable. Assignable expressions are only identifiers, index expressions, and member access expressions.

This then allows removing the defensive copying of the return statement value. As values are still copied in variable declarations and when passed as arguments, there is no way to return an object and have the caller modify it.

Copy link
Member

@zhangchiqing zhangchiqing left a comment

Choose a reason for hiding this comment

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

Nice tests. Had some questions

runtime/sema/errors.go Outdated Show resolved Hide resolved
runtime/sema/check_assignment.go Show resolved Hide resolved
runtime/tests/checker/assignment_test.go Show resolved Hide resolved
turbolent and others added 2 commits August 4, 2020 15:42
Co-authored-by: Leo Zhang <zhangchiqing@gmail.com>
@turbolent turbolent merged commit c82a76a into master Aug 5, 2020
@turbolent turbolent deleted the bastian/extend-assignable-target-expression-check branch August 5, 2020 05:12
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.

None yet

2 participants