-
Notifications
You must be signed in to change notification settings - Fork 373
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
feat(gnovm): sync code AssignStmt - ValueDecl #3017
base: master
Are you sure you want to change the base?
feat(gnovm): sync code AssignStmt - ValueDecl #3017
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3017 +/- ##
=======================================
Coverage 63.33% 63.33%
=======================================
Files 548 548
Lines 78646 78624 -22
=======================================
- Hits 49807 49794 -13
+ Misses 25478 25469 -9
Partials 3361 3361
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Looks good to me 🔥
Co-authored-by: Mikael VALLENET <[email protected]>
gnovm/pkg/gnolang/preprocess.go
Outdated
nx.Path = last.GetPathForName(nil, nx.Name) | ||
} | ||
} | ||
if len(n.Values) != 1 && len(n.Values) != 0 && len(n.NameExprs) != len(n.Values) { |
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.
why this len(n.Values) != 1 && len(n.Values) != 0
?
I think this will not handle this case:
package main
var a, b = 1
func main() {
}
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.
Originally, there were 3 cases:
if numNames > 1 && len(n.Values) == 1 {
...
} else if len(n.Values) != 0 && numNames != len(n.Values) {
...
} else {
...
}
To be able to refactor the code, I've moved this check first then 2 others. So I've added the condition but it looks strange like that, I've pushed the change.
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.
@omarsy I've checked, actually the errors for var a, b = 1 vs a, b := 1 are identical with Golang
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 don't know why but I cannot resolve the comment :/
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.
Overall, this refactoring is on the good track, and I agree with the general direction. Nice work.
In addition to the remarks in the code, could you please add a few more tests to cover some corner cases such as:
Mixing single and multiple return expression in the same assignment:
func f() (a, b int) {return 1, 2}
var x, y, z = 1, f()
Or covering slices, arrays, type conversions, etc.
Thanks
gnovm/pkg/gnolang/preprocess.go
Outdated
// - `a, b, c T := f()` | ||
// - `a, b := n.(T)` | ||
// - `a, b := n[i], where n is a map` | ||
func specialParseTypeVals( |
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.
func specialParseTypeVals( | |
func parseMultipleAssignFromOneExp( |
specialParseTypeVals
is unclear. Please use a descriptive function name as suggested.
Also, for the function comment, please follow Go conventions to describe the function:
// parseMultimpleAssignFromOneExp parses assignment to multiple variables from a single expression, etc...
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.
I've updated the function name + comment
gnovm/pkg/gnolang/preprocess.go
Outdated
// - `var a, b = n.(T)` | ||
// - `var a, b = n[i], where n is a map` | ||
// Assign | ||
// - `a, b, c T := f()` |
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, b, c T := f()` | |
// - `a, b, c := f()` |
Type name makes no sense in short declarations.
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.
I've updated :)
gnovm/pkg/gnolang/preprocess.go
Outdated
|
||
for i := 0; i < numNames; i++ { | ||
if st != nil { | ||
// TODO check tt and nt compat. |
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.
Please, perform the required type check, as it is important to catch types mismatch as early as possible.
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.
I've added the compat check :)
gnovm/pkg/gnolang/preprocess.go
Outdated
) { | ||
numNames := len(nameExprs) | ||
|
||
// ensure that function only return 1 value |
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.
// ensure that function only return 1 value | |
// Ensure that function only return 1 value. |
Comment lines should follow normal sentence rules (1st letter capital, punctuation, ...).
gnovm/pkg/gnolang/preprocess.go
Outdated
} | ||
} | ||
|
||
// evaluate types and convert consts. |
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.
// evaluate types and convert consts. | |
// Evaluate types and convert consts. |
gnovm/pkg/gnolang/preprocess.go
Outdated
for i := 0; i < numNames; i++ { | ||
sts[i] = nt | ||
} | ||
// convert if const to nt. |
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.
// convert if const to nt. | |
// Convert if const to nt. |
gnovm/pkg/gnolang/preprocess.go
Outdated
checkOrConvertType(store, bn, &valueExprs[i], nt, false) | ||
} | ||
} else if isConst { | ||
// derive static type from values. |
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.
// derive static type from values. | |
// Derive static type from values. |
thanks @mvertes for your time and your reviews , I've addressed all your feedbacks. Please re-check the PR, please. Thanksssss. |
} | ||
|
||
// Error: | ||
// main/files/assign33.gno:8:6: cannot use foo<VPBlock(3,0)>() (value of type bool) as int value in assignment |
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.
// main/files/assign33.gno:8:6: cannot use foo<VPBlock(3,0)>() (value of type bool) as int value in assignment | |
// main/files/assign33.gno:8:6: cannot use foo<VPBlock(3,0)>() (value of type bool) as int value in assignment: |
Please apply this to fix the failing test (see https://github.com/gnolang/gno/actions/runs/11701117443/job/32586531655?pr=3017)
if st != nil { | ||
tt := tuple.Elts[i] | ||
|
||
if tt.Kind() != st.Kind() { |
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.
Testing for identical type kinds is too weak!
For assignement expressions, you must verify that type st
is assignable to type tt
. Hint: look for function checkAssignableTo
in types.go
, same package.
if len(n.Values) > 1 && len(n.NameExprs) != len(n.Values) { | ||
panic(fmt.Sprintf("assignment mismatch: %d variable(s) but %d value(s)", len(n.NameExprs), len(n.Values))) |
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.
Sorry my last request. What do you think about moving this check into the defineOrDecl
function?
This PR aims at fixing this issue 1958
Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the description