-
Notifications
You must be signed in to change notification settings - Fork 942
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
Inconsistent Behavior with len
on Nil Array Pointer in tinygo
#4786
Comments
I think func main() {
println(cap(*nilPtrToArray()))
} |
I can confirm this issue. |
Looks like this is actually a bug in the golang.org/x/tools/go/ssa package. I'll see whether I can create a reproducer for the Go team. |
Reported the issue upstream: golang/go#72844 |
@aykevl It looks like a Go compiler bug! Thank you for submitting the issue on upstream. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
len
function behaves inconsistently when applied to anil
array pointer in TinyGo compared to standard Go. While Go 1.24.1 returns the array length without a panic, TinyGo produces a runtime error when dereferencing anil
array pointer.Expected Behavior
In Go,
len(*nilPtrToArray())
should not result in a panic. Instead, it should return the length of the array type (in this case,2
), as thelen
function in Go does not evaluate the contents of the array but rather its static length.tinygo
should replicate this behavior to maintain compatibility.Analysis
The discrepancy likely stems from how
tinygo
handles nil pointer dereferencing in combination withlen
. In standard Go, dereferencing anil
pointer to an array solely for evaluating its length does not trigger a runtime error.tinygo
, however, appears to strictly enforce pointer validity, leading to a nil pointer dereference panic.The text was updated successfully, but these errors were encountered: