Skip to content

Instantly share code, notes, and snippets.

@ncw
Created May 28, 2015 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ncw/883d01d0274dda5e32d1 to your computer and use it in GitHub Desktop.
Save ncw/883d01d0274dda5e32d1 to your computer and use it in GitHub Desktop.
Go compiler bug demo

Go compiler bug demo

Compiling this directory with go build you get

./e.go:4: TypeType.New undefined (type *Type has no field or method New)

Where if you look in t.go you can see that method is defined.

If you concatenate e.go and t.go and compile (remove duplicate package line) then it compiles fine.

package foo
var (
Base = TypeType.New()
// To trigger the problem
// * Need Base as argument - it is fine if you substitute with nil
// * Need the x, _ = form of call
Something, _ = NewSomething(Base)
)
func NewSomething(t *Type) (*Type, error) {
return nil, nil
}
package foo
type Type struct{}
var TypeType *Type = &Type{}
func (t *Type) New() *Type {
return &Type{}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment