Skip to content
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): support constant evaluation of len and cap on arrays #3600

Merged
merged 9 commits into from
Feb 4, 2025
Prev Previous commit
Next Next commit
Update gnovm/pkg/gnolang/preprocess.go
Co-authored-by: Lee ByeongJun <[email protected]>
  • Loading branch information
omarsy and notJoon authored Jan 24, 2025
commit 9351618e8b8ac837a9b32e808a2b80829c582974
6 changes: 3 additions & 3 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -3378,18 +3378,18 @@
t := evalStaticTypeOf(store, last, clx.Args[0])
if ar, ok := unwrapPointerType(baseOf(t)).(*ArrayType); ok {
fv := clx.Func.(*ConstExpr).V.(*FuncValue)
switch {
case fv.Name == "cap":
switch fv.Name {
case "cap":
fallthrough
case fv.Name == "len":
case "len":
tv := TypedValue{T: IntType}
tv.SetInt(ar.Len)
cx = &ConstExpr{
Source: x,
TypedValue: tv,
}
default:
panic(fmt.Sprintf("unexpected const func %s", fv.Name))

Check warning on line 3392 in gnovm/pkg/gnolang/preprocess.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/preprocess.go#L3391-L3392

Added lines #L3391 - L3392 were not covered by tests
}
}
}
Expand Down
Loading