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

Missing Type Check for Built-in Function Arguments (len, cap) Causes Runtime Panic #3454

Open
omarsy opened this issue Jan 7, 2025 · 0 comments
Labels
🐞 bug Something isn't working

Comments

@omarsy
Copy link
Member

omarsy commented Jan 7, 2025

Description

The following code triggers a runtime panic in Gno, but it should fail at preprocessor time due to invalid arguments passed to the built-in function len.

func main() {
	a := len(nil)
	println(a)
}

Expected Behavior

The code should fail to compile and produce a preprocessor error, such as:

invalid argument: nil for built-in len

Actual Behavior

the code compiles successfully but triggers a runtime panic when executed.

Stacktrace
testing.tRunner.func1.2({0x1009d2ec0, 0x100f0a9b0})
        /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1631 +0x1c4
testing.tRunner.func1()
        /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1634 +0x33c
panic({0x1009d2ec0?, 0x100f0a9b0?})
        /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:770 +0x124
github.com/gnolang/gno/gnovm/pkg/gnolang.toConstExpTrace(0x14000488b40?)
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/frame.go:216 +0x534
github.com/gnolang/gno/gnovm/pkg/gnolang.toExprTrace({0x100a9af58?, 0x140003aae40})
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/frame.go:171 +0x648
github.com/gnolang/gno/gnovm/pkg/gnolang.toExprTrace({0x100a9aba0?, 0x140003aa6c0})
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/frame.go:144 +0x6a8
github.com/gnolang/gno/gnovm/pkg/gnolang.Stacktrace.String({{0x140003b9560?, 0x1?, 0x1?}, 0x100000100a768c0?})
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/frame.go:127 +0x250
github.com/gnolang/gno/gnovm/pkg/test.(*TestOptions).runTest.func1()
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/test/filetest.go:215 +0x274
panic({0x1009d2ec0?, 0x100f0a9b0?})
        /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:770 +0x124
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).Run.func1()
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/machine.go:1162 +0xac
panic({0x1009d2ec0?, 0x100f0a9b0?})
        /Users/ghost/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:770 +0x124
github.com/gnolang/gno/gnovm/pkg/gnolang.(*TypedValue).GetLength(0x140003d65a0?)
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/values.go:2106 +0x304
github.com/gnolang/gno/gnovm/pkg/gnolang.makeUverseNode.func6(0x140001f2008)
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/uverse.go:794 +0x98
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).doOpCallNativeBody(...)
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/op_call.go:191
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).Run(0x140001f2008)
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/machine.go:1204 +0x140
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).RunStatement(0x140001f2008, {0x100a9bca0, 0x140003a6e40})
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/machine.go:813 +0x330
github.com/gnolang/gno/gnovm/pkg/test.(*TestOptions).runTest(0x140003292c0, 0x140001f2008, {0x10070d1c0, 0x4}, {0x140004a09f0, 0x11}, {0x14000389400, 0x128, 0x140003b6000?})
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/test/filetest.go:230 +0x5e4
github.com/gnolang/gno/gnovm/pkg/test.(*TestOptions).runFiletest(0x140003292c0, {0x140004a09f0, 0x11}, {0x14000389400, 0x128, 0x200})
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/test/filetest.go:68 +0x514
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(0x140003a0000)
        /Users/ghost/Documents/projects/teritori/gno/gnovm/pkg/gnolang/files_test.go:90 +0xfc
testing.tRunner(0x140003a0000, 0x1400038db90)
        /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
FAIL    github.com/gnolang/gno/gnovm/pkg/gnolang 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
Status: Triage
Development

No branches or pull requests

1 participant