gopherjs: Interface implementation errors are not descriptive.

Running this program on play.golang.org produces:

/tmp/sandbox161431897/main.go:14: cannot convert T literal (type T) to type FooBar:
    T does not implement FooBar (missing Bar method)

It tells us that Bar is the missing method (i.e. what the error actually is).

But running the same program via gopherjs.org/play produces a error that is very hard to understand:

prog.go:14:13: cannot convert (T literal) (value of type T) to FooBar 

I actually have code that uses some very large composite interfaces – and it’s hard to track down exactly what I’ve done wrong (it’s code that cannot be run via the standard Go compiler itself, only by gopherjs).

Any ideas on a potential workaround or improvement to this situation?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 15 (15 by maintainers)

Most upvoted comments

@shurcooL you’re absolutely right, sorry I didn’t check that.

I’ve just looked at the go/types source code. For assignments a reason is generated:

https://github.com/golang/go/blob/8db4d02e8fed0b42d71ef311c3b5481b2e72b26d/src/go/types/assignments.go#L60

but for conversions there is no reason:

https://github.com/golang/go/blob/8db4d02e8fed0b42d71ef311c3b5481b2e72b26d/src/go/types/conversions.go#L34

Looks like a relatively simple fix… will see if I can find the time over the weekend.