Skip to content

gopherjs build crashes with various invalid receivers #396

Open
@flimzy

Description

@flimzy

If I create a function with an invalid receiver, GopherJS crashes, where Go provides a descriptive error message. A few examples:

package main

func (r *io.Foo) BreakTheWorld() {}

Go:

$ go build xxx.go
# command-line-arguments
./xxx.go:3: undefined: io in io.Foo

GopherJS:

$ gopherjs build xxx.go
panic: interface conversion: ast.Expr is *ast.SelectorExpr, not *ast.Ident

goroutine 1 [running]:
github.com/gopherjs/gopherjs/build.parse.func1(0xc820124d80, 0x0, 0x0)
    /home/jonhall/go/src/github.com/gopherjs/gopherjs/build/build.go:147 +0x1a5
<snip>

Or for this input:

package main

import "io"

func (r *io.Reader) BreakTheWorld() {}

Go:

$ go build xxx.go
# command-line-arguments
./xxx.go:5: invalid receiver type *io.Reader (io.Reader is an interface type)

GopherJS:

$ gopherjs build xxx.go
panic: interface conversion: ast.Expr is *ast.SelectorExpr, not *ast.Ident

goroutine 1 [running]:
github.com/gopherjs/gopherjs/build.parse.func1(0xc820109950, 0x0, 0x0)
    /home/jonhall/go/src/github.com/gopherjs/gopherjs/build/build.go:147 +0x1a5
<snip>

And finally (the case that actually bit me):

package main

import "github.com/gopherjs/gopherjs/js"

func (o *js.Object) BreakTheWorld() {}

Go:

$ go build xxx.go
# command-line-arguments
./xxx.go:5: cannot define new methods on non-local type js.Object

GopherJS:

$ gopherjs build xxx.go
panic: interface conversion: ast.Expr is *ast.SelectorExpr, not *ast.Ident

goroutine 1 [running]:
github.com/gopherjs/gopherjs/build.parse.func1(0xc82010b590, 0x0, 0x0)
    /home/jonhall/go/src/github.com/gopherjs/gopherjs/build/build.go:147 +0x1a5
<snip>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions