-
Notifications
You must be signed in to change notification settings - Fork 399
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): len/array of array with function calls should not be constant #3714
base: master
Are you sure you want to change the base?
Conversation
🛠 PR Checks SummaryAll Automated Checks passed. ✅ 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
|
…tion with seen tracking
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
@ltzmaxwell can you take a look for a first review? I think there must be something better than implementing |
switch fv.Name { | ||
case "len", "cap": | ||
at := evalStaticTypeOf(store, last, currExpr.Args[0]) | ||
if _, ok := unwrapPointerType(baseOf(at)).(*ArrayType); ok { | ||
// ok | ||
break Main | ||
if AsExpr(currExpr.Args[0], &CallExpr{}, &seen[Expr]{}) { | ||
panic(fmt.Sprintf("%s (value of type %s) is not constant", currExpr.String(), at)) |
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 into the compositLit's Elts, and do:
assertValidConstValue(store, last, elt.Value)
?
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
const a = len([1]int{ | ||
func() int { println("hey!!"); return 1 }(), | ||
}) | ||
fmt.Println("Hello", a) | ||
} | ||
|
||
// Error: |
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 also add another test to clarify, which is valid:
nestedArr := [1]int{func() int { println("hey!!"); return 1 }()}
const a = len(nestedArr)
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 change introduces a regression at least for the following case:
package main
func main() {
a := 1.0
const c1 = len([1]int{int(a)})
println(c1)
}
which now panics, but should not (and wasn't).
closes: #3701