-
Notifications
You must be signed in to change notification settings - Fork 389
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): align Gno constant handling with Go specifications #2828
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
c9b02d2
to
f49c088
Compare
355d799
to
e9a9be7
Compare
@omarsy , can you fix the lint-pr-title CI check? |
🛠 PR Checks Summary🔴 Maintainers must be able to edit this pull request (more info) Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🔴 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
I think it is better to handle it in another PR. WDYT ? |
gnovm/pkg/gnolang/type_check.go
Outdated
switch vx := vx.(type) { | ||
case *NameExpr: | ||
t := evalStaticTypeOf(store, last, vx) | ||
if _, ok := t.(*ArrayType); 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.
hmmm, this logic seems incorrect:
if _, ok := t.(*ArrayType); ok {
break Main
}
Due to this logic, the error in const43.gno
was not caught.
I guess your intention is to check len(arr), right? I think that needs additional context to know if the outer expr is a built func call: len
or max
?
Not so sure, but we need to focus on ensuring that the logic of this function is correct(not limited to the above-mentioned).
gnovm/pkg/gnolang/type_check.go
Outdated
assertValidConstantExprRecursively(store, last, expr, nil) | ||
} | ||
|
||
func assertValidConstantExprRecursively(store Store, last BlockNode, currExpr, parentExpr Expr) { |
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 assertValidConstantExprRecursively(store Store, last BlockNode, currExpr, parentExpr Expr) { | |
func assertValidConstValue(store Store, last BlockNode, currExpr, parentExpr Expr) { |
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 be done here 54878f0
@ltzmaxwell ping me if you approve and would like me to take a look as well, otherwise go ahead and merge after you've approved |
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.
trying to find more counter cases, please check.
case *TypeType: | ||
for _, arg := range currExpr.Args { | ||
assertValidConstValue(store, last, arg, currExpr) | ||
} |
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 check this:
package main
const a = interface{}(nil)
func main() {
println("ok")
}
seems also need to check the type, right?
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.
My bad break on my last refactoring when I move the check type
Nice catch ^^
gnovm/pkg/gnolang/type_check.go
Outdated
|
||
tt := pv.GetBlock(store).Source.GetStaticTypeOf(store, currExpr.Sel) | ||
panic(fmt.Sprintf("%s (variable of type %s) is not constant", currExpr.String(), tt)) | ||
case *PointerType, *DeclaredType, *StructType, *InterfaceType: |
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 counter case:
package main
type MyStruct struct {
arr [2]int
}
const a = len(MyStruct{arr: [2]int{1, 2}}.arr)
func main() {
println("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.
:o I miss this case. Thank you ^^
Done here c45f63e
} | ||
case *ConstExpr: | ||
case *BasicLitExpr: | ||
case *CompositeLitExpr: |
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.
can we just check parent and panic here?
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.
Since we verify the expression type before calling this function, this case should not occur. Removed for array: 4da7934
Related Issues:
Closes #2628
This PR aims to align Gno's constant handling with the Go specification regarding constant expressions (see Go Specification on Constants).
Primitive Type Requirement
Function Calls Disallowed
Only built-in functions should be allowed.
Constant Operands Requirement
Constant expressions may contain only constant operands and are evaluated at compile time.
Type Assertion Forbidden
Index Expression Forbidden
Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the description