Skip to content

fix(filetest) : stop after panic when using nil function argument #4256

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/gno.land/r/issue/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/issue
9 changes: 9 additions & 0 deletions examples/gno.land/r/issue/issue.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package issue

func Example(v any) {
if v == nil {
panic("boom!")
}

panic("boom!")
}
10 changes: 10 additions & 0 deletions examples/gno.land/r/issue/z_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import "gno.land/r/issue"

func main() {
issue.Example(nil)
}

//Error:
//boom!
3 changes: 2 additions & 1 deletion gnovm/pkg/gnolang/type_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ func checkAssignableTo(n Node, xt, dt Type, autoNative bool) error {
if dt == nil || dt.Kind() == InterfaceKind {
return nil
}
if !maybeNil(dt) {

if !maybeNil(dt) && dt.Kind() != BoolKind {
switch n := n.(type) {
case *ValueDecl:
panic(fmt.Sprintf("cannot use nil as %v value in variable declaration", dt))
Expand Down
2 changes: 2 additions & 0 deletions gnovm/pkg/gnolang/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func (pv *PointerValue) GetBase(store Store) Object {
// TODO: document as something that enables into-native assignment.
// TODO: maybe consider this as entrypoint for DataByteValue too?
func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 TypedValue, cu bool) {

// Special cases.
if pv.TV.T == DataByteType {
// Special case of DataByte into (base=*SliceValue).Data.
Expand All @@ -236,6 +237,7 @@ func (pv PointerValue) Assign2(alloc *Allocator, store Store, rlm *Realm, tv2 Ty
}

func (pv PointerValue) Deref() (tv TypedValue) {

if pv.TV.T == DataByteType {
dbv := pv.TV.V.(DataByteValue)
tv.T = dbv.ElemType
Expand Down
Loading