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

Constant Evaluation of len with Type Assertion Causes Panic #3409

Open
omarsy opened this issue Dec 26, 2024 · 0 comments
Open

Constant Evaluation of len with Type Assertion Causes Panic #3409

omarsy opened this issue Dec 26, 2024 · 0 comments
Labels
🐞 bug Something isn't working 📦 🤖 gnovm Issues or PRs gnovm related

Comments

@omarsy
Copy link
Member

omarsy commented Dec 26, 2024

Description

The following code works as expected in Go, producing the output "ok 2". However, in Gno, it fails with a runtime panic and generates a lengthy stack trace.

package main

func main() {
	var i interface{} = [2]int{0, 1}
	const a = len(i.([2]int))
	println("ok", a)
}

Expected Behavior

In Go, the code executes without errors and produces the output:

ok 2

This is because the len function correctly evaluates the length of the array type assertion i.([2]int) during compilation.

Actual Behavior

In Gno, the code fails with a runtime panic. The stack trace includes the following:

/Users/ghost/go/pkg/mod/golang.org/[email protected]/src/runtime/debug/stack.go:24 +0x64
        github.com/gnolang/gno/gnovm/pkg/test.(*TestOptions).runTest.func1()
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/test/filetest.go:196 +0xac
        panic({0x105106360?, 0x140002a7800?})
                /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:770 +0x124
        github.com/gnolang/gno/gnovm/pkg/gnolang.doRecover({0x14000245c00, 0x3, 0x20}, {0x1051bcb60, 0x14000271b90})
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/preprocess.go:377 +0xb4
        panic({0x105106360?, 0x140002a7800?})
                /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:770 +0x124
        github.com/gnolang/gno/gnovm/pkg/gnolang.doRecover({0x14000195980, 0x1, 0x1}, {0x1051bcb60, 0x14000271b90})
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/preprocess.go:377 +0xb4
        panic({0x105106360?, 0x140002a7800?})
                /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:770 +0x124
        github.com/gnolang/gno/gnovm/pkg/gnolang.doRecover({0x14000370a00, 0x1, 0x20}, {0x1051bcb60, 0x14000271b90})
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/preprocess.go:399 +0x304
        panic({0x1050be360?, 0x14000195930?})
                /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:770 +0x124
        github.com/gnolang/gno/gnovm/pkg/gnolang.assertValidConstValue({0x1051c6be8, 0x140002bafa0}, {0x1051c7808, 0x140003ae808}, {0x1051bf128, 0x14000229770}, {0x1051be820?, 0x140001ab320?})
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/type_check.go:378 +0x680
        github.com/gnolang/gno/gnovm/pkg/gnolang.assertValidConstValue({0x1051c6be8, 0x140002bafa0}, {0x1051c7808, 0x140003ae808}, {0x1051be820?, 0x140001ab320}, {0x0, 0x0?})
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/type_check.go:289 +0x468
        github.com/gnolang/gno/gnovm/pkg/gnolang.assertValidConstExpr({0x1051c6be8, 0x140002bafa0}, {0x1051c7808, 0x140003ae808}, 0x1051bcb60?, {0x1051be820, 0x140001ab320})
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/type_check.go:243 +0x120
        github.com/gnolang/gno/gnovm/pkg/gnolang.preprocess1.func1({0x14000370c00, 0x0, 0x20}, 0x0, 0x0, {0x1051bcb60, 0x14000271b90}, 0x3)
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/preprocess.go:2302 +0x5c1c
        github.com/gnolang/gno/gnovm/pkg/gnolang.transcribe(0x1400037d3a0, {0x14000370c00, 0x0, 0x20}, 0x0, 0x0, {0x1051bcb60, 0x14000271b90}, 0x1400037d2a7)
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/transcribe.go:752 +0x18a8
        github.com/gnolang/gno/gnovm/pkg/gnolang.Transcribe({0x1051bcb60, 0x14000271b90}, 0x1400037d3a0)
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/transcribe.go:136 +0xb4
        github.com/gnolang/gno/gnovm/pkg/gnolang.preprocess1({0x1051c6be8, 0x140002bafa0}, {0x1051c7808, 0x140003ae808}, {0x1051bcb60, 0x14000271b90?})
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/preprocess.go:476 +0x250
        github.com/gnolang/gno/gnovm/pkg/gnolang.Preprocess({0x1051c6be8?, 0x140002bafa0?}, {0x1051c7808, 0x140003ae808}, {0x1051bcb60?, 0x14000271b90?})
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/preprocess.go:436 +0x34
        github.com/gnolang/gno/gnovm/pkg/gnolang.predefineNow2({0x1051c6be8, 0x140002bafa0}, {0x1051c7808, 0x140003ae808}, {0x1051c0ff0, 0x14000271b90}, 0x1400037d6a0)
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/preprocess.go:4189 +0x290
        github.com/gnolang/gno/gnovm/pkg/gnolang.predefineNow({0x1051c6be8?, 0x140002bafa0?}, {0x1051c7808?, 0x140003ae808?}, {0x1051c0ff0?, 0x14000271b90?})
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/preprocess.go:4061 +0xc4
        github.com/gnolang/gno/gnovm/pkg/gnolang.preprocess1.func1({0x14000370000, 0x3, 0x20}, 0x27, 0x0, {0x1051bcb60, 0x14000271b90}, 0x0)
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/preprocess.go:529 +0xad80
        github.com/gnolang/gno/gnovm/pkg/gnolang.transcribe(0x1400037f150, {0x14000370000, 0x3, 0x20}, 0x27, 0x0, {0x1051bcb60, 0x14000271b90}, 0x1400037e8a7)
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/transcribe.go:143 +0x74
        github.com/gnolang/gno/gnovm/pkg/gnolang.transcribe(0x1400037f150, {0x14000370000, 0x2, 0x20}, 0x47, 0x0, {0x1051bd860, 0x14000364080}, 0x1400037eb37)
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/transcribe.go:411 +0x25fc
        github.com/gnolang/gno/gnovm/pkg/gnolang.transcribe(0x1400037f150, {0x14000370000, 0x1, 0x20}, 0x4f, 0x0, {0x1051bcae0, 0x140003ae808}, 0x1400037edc7)
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/transcribe.go:690 +0x73d0
        github.com/gnolang/gno/gnovm/pkg/gnolang.transcribe(0x1400037f150, {0x14000370000, 0x0, 0x20}, 0x0, 0x0, {0x1051be1e0, 0x14000334608}, 0x1400037f057)
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/transcribe.go:732 +0x2d4c
        github.com/gnolang/gno/gnovm/pkg/gnolang.Transcribe({0x1051be1e0, 0x14000334608}, 0x1400037f150)
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/transcribe.go:136 +0xb4
        github.com/gnolang/gno/gnovm/pkg/gnolang.preprocess1({0x1051c6be8, 0x140002bafa0}, {0x1051c76e0, 0x14000334008}, {0x1051be1e0, 0x14000334608?})
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/preprocess.go:476 +0x250
        github.com/gnolang/gno/gnovm/pkg/gnolang.Preprocess({0x1051c6be8?, 0x140002bafa0?}, {0x1051c76e0, 0x14000334008}, {0x1051be1e0?, 0x14000334608?})
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/preprocess.go:436 +0x34
        github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).runFileDecls(0x140001f2008, {0x14000197b18, 0x1, 0x1})
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/machine.go:495 +0x254
        github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).RunFiles(0x140001f2008, {0x14000197b18?, 0x140000422a0?, 0x6c?})
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/machine.go:446 +0x30
        github.com/gnolang/gno/gnovm/pkg/test.(*TestOptions).runTest(0x140003b6b40, 0x140001f2008, {0x104e34320, 0x4}, {0x140004a0990, 0x11}, {0x1400026b200, 0x6c, 0x140002bafa0?})
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/test/filetest.go:222 +0x46c
        github.com/gnolang/gno/gnovm/pkg/test.(*TestOptions).runFiletest(0x140003b6b40, {0x140004a0990, 0x11}, {0x1400026b200, 0x6c, 0x200})
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/test/filetest.go:68 +0x50c
        github.com/gnolang/gno/gnovm/pkg/test.(*TestOptions).RunFiletest(...)
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/test/filetest.go:28
        github.com/gnolang/gno/gnovm/pkg/gnolang_test.TestFiles.func2.2(0x1400039e000)
                /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/files_test.go:90 +0xfc
        testing.tRunner(0x1400039e000, 0x14000271880)
                /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1689 +0xec
        created by testing.(*T).Run in goroutine 35
                /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1742 +0x318
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 📦 🤖 gnovm Issues or PRs gnovm related
Projects
Development

No branches or pull requests

2 participants