-
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: solve problem that variable (of declaredType) is not assigned with correct type #674
Conversation
Hi, @r3v4s , would you check this. |
@ltzmaxwell good findings! We are definitely in the right direction. However, there are a lot of changes. Can you help describe the root cause and why the fix solved the problem? I noticed a side effect in this test case.
Above is the "data" field metadata in an NFTToken instance. The value is "NFT#1"
instead of
|
Thank you @piux2 , it's actually a bug, I'm giving fix. |
@peter7891 is ok for review |
Do not merge, please see #651 (comment) Also please add me as a reviewer for all gnolang vm changes! |
WIP, block. |
Hi @jaekwon , Can you take a look at this? Thank you! update: 1.enhanced preprocessing. An explicit conversion from unnamed-composite to named declared types has now been implemented. This solution addresses the majority of the issues encountered previously. 2.The copy function has also been fixed. According to the Go specification, "The core types of both arguments must be slices with identical element types". Our previous implementation lacked this necessary check, so we have now added it for improved robustness. |
Hi, @jaekwon , I have another question, currently the code below would not work since n2 is not assigned with correct type from the assignment. It works in go playground: https://go.dev/play/p/pA0cqF-nuBV the question is whether we can fix it in preprocess stage? Thank you!
|
this is the solution we want: https://gist.github.com/piux2/49bada7be72186371e6684d007d3ed75?permalink_comment_id=4579166#gistcomment-4579166 links to https://github.com/gnolang/gno/compare/master...piux2:gno:fix_declaredtype_preprocess?expand=1 . The thread on piux2's thread (first link) has comments on improvements and what is necessary to make complete. To answer your exact question, yes we can and we will, but the simplest solution for now is to do the following: // pseudocode
// on LEAVE AssignStmt around 1574 for `case *CallExpr:`
...
if dest type is interface type {
...
} else if leftType is exactly rightType {
// perfect match, continue
} else if checkType(leftType, rightType) {
panic("a, b := x() implicit conversion not supported yet")
} else {
panic("type check error")
} Ray has the context to complete this. Then, you can work with Ray to complete the next PR which is to do the expansion only when necessary. |
gnovm/pkg/gnolang/preprocess.go
Outdated
@@ -2364,7 +2379,7 @@ func convertConst(store Store, last BlockNode, cx *ConstExpr, t Type) { | |||
// Assert that xt can be assigned as dt (dest type). | |||
// If autoNative is true, a broad range of xt can match against | |||
// a target native dt type, if and only if dt is a native type. | |||
func checkType(xt Type, dt Type, autoNative bool) { | |||
func checkType(xt Type, dt Type, autoNative bool, conversionNeeded *bool) { |
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.
right, right. this would make sense (or it could just return the value as a bool, i think is simpler) to get the information out of the function. we will need this later for the full unroll solution (e.g. the second pr after ray's), but I suggest a return bool value instead.
args1T := evalStaticTypeOf(store, last, n.Args[1]) | ||
if args0T.Elem().TypeID() != args1T.Elem().TypeID() { | ||
panic(fmt.Sprintf( | ||
"arguments to copy have different element types, want %s, got %s", args0T.Elem().TypeID(), args1T.Elem().TypeID())) |
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.
what prompted this? seems like this could/should be a separate PR for complete discussion. seems correct though.
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.
It's a fix of copy
function. According to the Go specification, "The core types of both arguments must be slices with identical element types". Our previous implementation lacked this necessary check.
I'll put it into another PR. Thank you~
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.
we can close this or @piux2 can merge here.
house keeping. |
code like this won't work. when
abs
is assigned like this:abs = []Word{0}
, abs is assigned with a type of[]Word
, thusabs.add3()
does not work.another example,
abs
is a nested field:The problem come from : #651 .
The solution is to give proper type to variable with declaredType.