-
Notifications
You must be signed in to change notification settings - Fork 385
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
fix(gnovm): Improve Error Message in evalStaticTypeOf
function
#2695
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
evalStaticTypeOf
functionevalStaticTypeOf
function
} | ||
return "<unknown function>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't happend. I added it just in case.
gnovm/pkg/gnolang/preprocess.go
Outdated
func getFunctionName(x Expr) string { | ||
switch expr := x.(type) { | ||
case *CallExpr: | ||
if id, ok := expr.Func.(*NameExpr); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another name other than id
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
e948f68
gnovm/pkg/gnolang/preprocess.go
Outdated
msg = fmt.Sprintf("%s: %s() (no value) used as value", loc, funcName) | ||
} else { | ||
msg = fmt.Sprintf("%s: %s() (%d values) used as single value", loc, funcName, valueCount) | ||
} | ||
|
||
panic(fmt.Errorf("%s\nHint: Ensure the function returns a single value, or use multiple assignment", msg)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hint may not be very effective if it corresponds to one of the messages above, such as:
panic: main/func.gno:3:1: f() (no value) used as value
Hint: Ensure the function returns a single value, or use multiple assignment.
I mean in this case, "or use multiple assignment" is superfluous。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or not, this check should be checked somewhere other than evalStaticTypeOf
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well I think this part feels odd to me(the original logic in evalStaticTypeOf
:
if len(tt.Elts) != 1 {
panic(fmt.Sprintf(
"evalStaticTypeOf() only supports *CallExpr with 1 result, got %s",
tt.String(),
))
at the very least for case like:
n := f2()
func f2() (string, int) {
return "hey", 0
}
the check can happened in *AssignStmt, to identify a mismatch on LHS and RHS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Writing so much just for the sake of discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes @ltzmaxwell I think this check should be done in AssignStmt and ValueDecl in trans_enter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few small suggestions, but looks good to me overall.
|
||
// getFunctionName attempts to extract the function name from the expression | ||
func getFunctionName(x Expr) string { | ||
switch expr := x.(type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nitpick, but it is a bit strange to have a switch with only one case
|
||
var msg string | ||
if valueCount == 0 { | ||
msg = fmt.Sprintf("%s: %s() (no value) used as value", loc, funcName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the message could be improved here. "no value" doesn't seem as clear as saying something like "function does not return a value".
Did you get a chance to see @ltzmaxwell's comments? 🙏 |
what is the status of this one? |
@ltzmaxwell dust off now. sorry for the delay 🙏 |
Closing this PR in favor of #3049 to avoid duplicate work |
…tion which does not return any value (#3049) This PR aims at resolving this issue: #1082 This depends on #3017 because it refactored the code to sync the logic/code between AssignStmt vs ValueDecl. Related #2695 <details><summary>Contributors' checklist...</summary> - [ ] Added new tests, or not needed, or not feasible - [ ] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [ ] Updated the official documentation or not needed - [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [ ] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests </details> --------- Co-authored-by: hieu.ha <hieu.ha@hsc.com.vn> Co-authored-by: Mikael VALLENET <mikael.vallenetpro@gmail.com>
…tion which does not return any value (gnolang#3049) This PR aims at resolving this issue: gnolang#1082 This depends on gnolang#3017 because it refactored the code to sync the logic/code between AssignStmt vs ValueDecl. Related gnolang#2695 <details><summary>Contributors' checklist...</summary> - [ ] Added new tests, or not needed, or not feasible - [ ] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [ ] Updated the official documentation or not needed - [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [ ] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests </details> --------- Co-authored-by: hieu.ha <hieu.ha@hsc.com.vn> Co-authored-by: Mikael VALLENET <mikael.vallenetpro@gmail.com>
…tion which does not return any value (gnolang#3049) This PR aims at resolving this issue: gnolang#1082 This depends on gnolang#3017 because it refactored the code to sync the logic/code between AssignStmt vs ValueDecl. Related gnolang#2695 <details><summary>Contributors' checklist...</summary> - [ ] Added new tests, or not needed, or not feasible - [ ] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [ ] Updated the official documentation or not needed - [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [ ] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests </details> --------- Co-authored-by: hieu.ha <hieu.ha@hsc.com.vn> Co-authored-by: Mikael VALLENET <mikael.vallenetpro@gmail.com>
Description
Closes #1082
Enhanced the error message in
evalStaticTypeOf
function to match with go's error message and provide more informative feeback.Example of Errors
Sample code (taken from linked issue)
Before
After
Go version (go playground)
Further Works
I think it would be good to fix
getTypeOf
function as well, but I can't think of a case where it would cause panic.Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the description