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

Assignment tracking for many-to-one assignments #181

Conversation

sonalmahajan15
Copy link
Contributor

This PR adds assignment tracking for many-to-one assignments for printing informative error messages, following suit of one-to-one assignment tracking (PR #87 ).

Copy link

codecov bot commented Jan 24, 2024

Codecov Report

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

Comparison is base (8b7423a) 89.19% compared to head (d9aa057) 89.11%.

Files Patch % Lines
assertion/function/assertiontree/backprop.go 42.85% 8 Missing and 4 partials ⚠️
assertion/function/assertiontree/backprop_util.go 64.70% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #181      +/-   ##
==========================================
- Coverage   89.19%   89.11%   -0.09%     
==========================================
  Files          55       55              
  Lines        9165     9176      +11     
==========================================
+ Hits         8175     8177       +2     
- Misses        825      832       +7     
- Partials      165      167       +2     

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

Copy link
Contributor

@yuxincs yuxincs left a comment

Choose a reason for hiding this comment

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

Changes LGTM, I only have a thought for future code simplification (that may not actually be valid) for discussion.

@@ -749,3 +750,22 @@ func CheckGuardOnFullTrigger(trigger annotation.FullTrigger) annotation.FullTrig
}
return trigger
}

// addAssignmentToConsumer updates the consumer with assignment entries for informative printing of errors
func addAssignmentToConsumer(lhs, rhs ast.Expr, pass *analysis.Pass, consumer annotation.ConsumingAnnotationTrigger) (err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we can drop the named return since it's not necessary :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Done :)

func addAssignmentToConsumer(lhs, rhs ast.Expr, pass *analysis.Pass, consumer annotation.ConsumingAnnotationTrigger) (err error) {
var lhsExprStr, rhsExprStr string
if lhsExprStr, err = asthelper.PrintExpr(lhs, pass, true /* isShortenExpr */); err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add more context to the error here? fmt.Errorf("adding assignment to consumer: %w", err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Done!

return err
}
if rhsExprStr, err = asthelper.PrintExpr(rhs, pass, true /* isShortenExpr */); err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

same here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done :)

return err
}

consumer.AddAssignment(annotation.Assignment{
Copy link
Contributor

Choose a reason for hiding this comment

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

Not something to be handled in this PR, but do you think we can actually move the logic (the asthelper.PrintExpr) inside the AddAssignment method? meaning make it take the AST nodes and do the expr shortening inside. I feel that would make the code simpler, but I may have missed some context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could. However, that would mean passing the *analysis.Pass to ConsumeTrigger, which is not required by ConsumeTrigger otherwise. Maybe we can do this refactor later if that seems to be the better approach.

@sonalmahajan15 sonalmahajan15 force-pushed the sonalmahajan15/backprop-error-message-for-many-to-one-assignment branch from 17db0f6 to d9aa057 Compare January 26, 2024 23:11
@sonalmahajan15 sonalmahajan15 merged commit 6b83875 into main Jan 26, 2024
5 checks passed
@sonalmahajan15 sonalmahajan15 deleted the sonalmahajan15/backprop-error-message-for-many-to-one-assignment branch January 26, 2024 23:14
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.

2 participants