Skip to content

Calling a func on a nil interface results in a potentially confusing JS error #563

Open
@flimzy

Description

@flimzy

This may or may not be a "bug" per se, but attempting to call a method on a nil interface results in a JS error, rather than a GopherJS runtime error. Example:

package main

func main() {
	foo := GetFoo()
	foo.Foo()
}

type Foo interface {
	Foo()
}

func GetFoo() Foo {
	return nil
}

Results in:

TypeError: foo.Foo is not a function

Or in Chrome:

main.js:146674 Uncaught TypeError: Cannot read property 'Foo' of undefined

This is only undesirable insofar as it tends to suggest a problem with a JS lib.

In Go the same error is reported as:

panic: runtime error: invalid memory address or nil pointer dereference

Something similar would be ideal, IMHO, in GopherJS.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions