Skip to content

feat(validation): Assignment suggestions for = operator #1049

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

Merged
merged 11 commits into from
Dec 19, 2023

Conversation

volsa
Copy link
Member

@volsa volsa commented Dec 6, 2023

This PR adds a validation to identify binary expressions using the = operator with no effects. For example the following statement foo = bar; does nothing and the user probably meant to use a := here, i.e. foo := bar;.

Resolves #939

Copy link

codecov bot commented Dec 11, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (a3c0055) 95.72% compared to head (5868db1) 95.74%.

Files Patch % Lines
src/resolver.rs 98.73% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1049      +/-   ##
==========================================
+ Coverage   95.72%   95.74%   +0.01%     
==========================================
  Files         153      153              
  Lines       42883    42875       -8     
==========================================
- Hits        41051    41049       -2     
+ Misses       1832     1826       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@volsa volsa marked this pull request as ready for review December 11, 2023 11:42
@volsa volsa requested review from riederm, ghaith and mhasel December 11, 2023 11:47
Copy link
Collaborator

Choose a reason for hiding this comment

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

How did these tests change? Nothing in the commit affects codegen/debugging

Copy link
Member Author

@volsa volsa Dec 11, 2023

Choose a reason for hiding this comment

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

Adding a type-hint onto the condition of control statements does because we then enter the cast_if_needed here afaik

Ok(cast_if_needed!(self, target_type, actual_type, v, self.annotations.get(expression)))

Copy link
Member

@mhasel mhasel Dec 11, 2023

Choose a reason for hiding this comment

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

My guess is because the condition expressions now receive a type-hint, we hit the cast_if_needed call in generate_expression were previously we returned the value as-is

Copy link
Member Author

Choose a reason for hiding this comment

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

Just to add some additional context, this issue will go away once we implement #1041

Copy link
Member Author

Choose a reason for hiding this comment

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

Anything blocking this PR @ghaith @mhasel ? Arguably the IR got uglier but at the top of my head I'm not sure how else to implement this feature without type-hints.

@volsa volsa mentioned this pull request Dec 19, 2023
@volsa volsa merged commit aa577c2 into master Dec 19, 2023
@volsa volsa deleted the assignment-suggestion branch December 19, 2023 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assignment suggestions for = operator
3 participants