Skip to content

'gopherjs build' crashes for 'undeclared name' in shared dependency #412

Closed
@flimzy

Description

@flimzy

It appears that when a package is imported through more than one path (i.e. a -> b -> c and a -> c), and the imported package has an undeclared name, gopherjs crashes, rather than producing a meaningful error.

Example code:

main.go:

package main

import (
    "github.com/flimzy/jstest/foo"
    "github.com/flimzy/jstest/bar"
)

func main() {}

foo/foo.go:

package foo

import "github.com/flimzy/jstest/bar"

bar/bar.go:

package bar

func Bar() int {
    return undefinedThing
}

And the result:

$ gopherjs build
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0xa0 pc=0x69aed4]

goroutine 1 [running]:
panic(0xa16040, 0xc820010120)
        /usr/local/go/src/runtime/panic.go:464 +0x3e6
go/types.(*Checker).handleBailout(0xc8201362a0, 0xc820153d90)
        /usr/local/go/src/go/types/check.go:213 +0xd8
panic(0xa16040, 0xc820010120)
        /usr/local/go/src/runtime/panic.go:426 +0x4e9
github.com/gopherjs/gopherjs/compiler.packageImporter.Import(0xc82013e420, 0xc82013e430, 0xc820142681, 0x1c, 0xa4b860, 0x0, 0x0)
        /home/jonhall/go/src/github.com/gopherjs/gopherjs/compiler/package.go:117 +0x124
github.com/gopherjs/gopherjs/compiler.(*packageImporter).Import(0xc82013e450, 0xc820142681, 0x1c, 0xc820153a18, 0x0, 0x0)
        <autogenerated>:22 +0xb8
go/types.(*Checker).collectObjects(0xc8201362a0)
        /usr/local/go/src/go/types/resolver.go:196 +0x3354
go/types.(*Checker).Files(0xc8201362a0, 0xc82002e198, 0x1, 0x1, 0x0, 0x0)
        /usr/local/go/src/go/types/check.go:223 +0xb3
go/types.(*Config).Check(0xc82013ad40, 0xc820135725, 0x18, 0xc82013abc0, 0xc82002e198, 0x1, 0x1, 0xc820138640, 0xc82001e00c, 0x0, ...)
        /usr/local/go/src/go/types/api.go:344 +0x1f7
github.com/gopherjs/gopherjs/compiler.Compile(0xc820135725, 0x18, 0xc82002e198, 0x1, 0x1, 0xc82013abc0, 0xc82013e420, 0x0, 0x200000003, 0x0, ...)
        /home/jonhall/go/src/github.com/gopherjs/gopherjs/compiler/package.go:147 +0x54c
github.com/gopherjs/gopherjs/build.(*Session).BuildPackage(0xc8200e1de0, 0xc820138460, 0x0, 0x0)
        /home/jonhall/go/src/github.com/gopherjs/gopherjs/build/build.go:512 +0x10ae
github.com/gopherjs/gopherjs/build.(*Session).BuildDir(0xc8200e1de0, 0xc8201351a0, 0x2d, 0xc8201351a0, 0x2d, 0x0, 0x0, 0x0, 0x0)
        /home/jonhall/go/src/github.com/gopherjs/gopherjs/build/build.go:359 +0x3bc
main.main.func1.1(0x0, 0x0)
        /home/jonhall/go/src/github.com/gopherjs/gopherjs/tool.go:91 +0xca
main.handleError(0xc820155b28, 0xc82013a080, 0x0, 0x0)
        /home/jonhall/go/src/github.com/gopherjs/gopherjs/tool.go:653 +0x3f
main.main.func1(0xc82013c000, 0xe1e160, 0x0, 0x0)
        /home/jonhall/go/src/github.com/gopherjs/gopherjs/tool.go:89 +0x108
github.com/spf13/cobra.(*Command).execute(0xc82013c000, 0xe1e160, 0x0, 0x0, 0x0, 0x0)
        /home/jonhall/go/src/github.com/spf13/cobra/command.go:499 +0x85a
github.com/spf13/cobra.(*Command).Execute(0xc82013cc40, 0x0, 0x0)
        /home/jonhall/go/src/github.com/spf13/cobra/command.go:582 +0x46a
main.main()
        /home/jonhall/go/src/github.com/gopherjs/gopherjs/tool.go:505 +0x161f

If I modify main.go not to directly import package bar, I get the expected output from gopherjs:

$ gopherjs build
bar/bar.go:4:9: undeclared name: undefinedThing

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions