Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bug: nil variable definition causes compiler panic #883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
paralin opened this issue Nov 28, 2018 · 6 comments
Open

bug: nil variable definition causes compiler panic #883

paralin opened this issue Nov 28, 2018 · 6 comments

Comments

@paralin
Copy link
Contributor

paralin commented Nov 28, 2018

Add the following line to the bottom of a Go file:

var _ context.Context = nil

This causes a Go compiler error.

Full compiler output and reproduce here:

https://gist.github.com/paralin/ef8a9b472baa6ecedfc708679a0f308c

@myitcv
Copy link
Member

myitcv commented Dec 2, 2018

I can't reproduce this:

$ export GOPATH=$(mktemp -d)
$ export PATH=$GOPATH/bin:$PATH
$ cd $GOPATH
$ go get -u github.com/gopherjs/gopherjs
$ pushd $(go list -f "{{.Dir}}" github.com/gopherjs/gopherjs)
/tmp/tmp.5LNEgdudzf/src/github.com/gopherjs/gopherjs /tmp/tmp.5LNEgdudzf
$ git checkout d547d1d9531ed93dbdebcbff7f83e7c876a1e0ee
HEAD is now at d547d1d... CI: Update to Go 1.11.2. (#878)
$ go install
$ popd
/tmp/tmp.5LNEgdudzf
$ mkdir -p src/example.com/blah
$ cd src/example.com/blah
$ cat <<EOD >blah.go
package nilref

import (
        "context"
)

var _ context.Context = nil
EOD
$ gopherjs test
?       example.com/blah        [no test files]

Do you have a repro?

@paralin
Copy link
Contributor Author

paralin commented Dec 6, 2018

@myitcv Check your little reproduction script, at the end you ran "gopherjs test" and got a "no test files" message. you did not actually compile the code. Try "gopherjs build -v ."

panic: unexpected basic type

@myitcv
Copy link
Member

myitcv commented Dec 6, 2018

@paralin - doh! Thanks for spotting the obvious error. Here is the repro:

$ export GOPATH=$(mktemp -d)
$ export PATH=$GOPATH/bin:$PATH
$ cd $GOPATH
$ go get -u github.com/gopherjs/gopherjs
$ pushd $(go list -f "{{.Dir}}" github.com/gopherjs/gopherjs)
/tmp/tmp.YgplR3yGUf/src/github.com/gopherjs/gopherjs /tmp/tmp.YgplR3yGUf
$ git checkout d547d1d9531ed93dbdebcbff7f83e7c876a1e0ee
HEAD is now at d547d1d... CI: Update to Go 1.11.2. (#878)
$ go install
$ popd
/tmp/tmp.YgplR3yGUf
$ mkdir -p src/example.com/blah
$ cd src/example.com/blah
$ cat <<EOD >blah.go
package nilref

import (
        "context"
)

var _ context.Context = nil
EOD
$ gopherjs build
panic: unexpected basic type

goroutine 1 [running]:
github.com/gopherjs/gopherjs/compiler.(*funcContext).translateExpr(0xc0000df340, 0xa728e0, 0xc00088ae80, 0xc0008ae6e0)
        /tmp/tmp.YgplR3yGUf/src/github.com/gopherjs/gopherjs/compiler/expressions.go:739 +0x11fa0
github.com/gopherjs/gopherjs/compiler.(*funcContext).translateStmt(0xc0000df340, 0xa722e0, 0xc0013abb80, 0x0)
        /tmp/tmp.YgplR3yGUf/src/github.com/gopherjs/gopherjs/compiler/statements.go:359 +0x7643
github.com/gopherjs/gopherjs/compiler.Compile.func6.1()
        /tmp/tmp.YgplR3yGUf/src/github.com/gopherjs/gopherjs/compiler/package.go:341 +0x102
github.com/gopherjs/gopherjs/compiler.(*funcContext).CatchOutput(0xc0000df340, 0x1, 0xc0015e6ba0, 0x0, 0xc000080700, 0x110)
        /tmp/tmp.YgplR3yGUf/src/github.com/gopherjs/gopherjs/compiler/utils.go:67 +0x87
github.com/gopherjs/gopherjs/compiler.Compile.func6()
        /tmp/tmp.YgplR3yGUf/src/github.com/gopherjs/gopherjs/compiler/package.go:340 +0xdb
github.com/gopherjs/gopherjs/compiler.Compile.func4(0xc0013abb40, 0xc0013abb40, 0xc001871360, 0xc0015e7468)
        /tmp/tmp.YgplR3yGUf/src/github.com/gopherjs/gopherjs/compiler/package.go:291 +0x76
github.com/gopherjs/gopherjs/compiler.Compile(0xc0001a62b8, 0x10, 0xc00016d8f0, 0x1, 0x1, 0xc0013ab3c0, 0xc000512170, 0x0, 0x0, 0x0, ...)
        /tmp/tmp.YgplR3yGUf/src/github.com/gopherjs/gopherjs/compiler/package.go:338 +0x2388
github.com/gopherjs/gopherjs/build.(*Session).BuildPackage(0xc00017c990, 0xc0001bc190, 0x0, 0x0, 0x0)
        /tmp/tmp.YgplR3yGUf/src/github.com/gopherjs/gopherjs/build/build.go:706 +0x5c6
main.main.func1.1(0xdf5d40, 0x0, 0x0, 0xc0001800e0, 0xc00017c990, 0xc000168200, 0x88cf60, 0xc0000cbba8)
        /tmp/tmp.YgplR3yGUf/src/github.com/gopherjs/gopherjs/tool.go:139 +0x70a
main.main.func1(0xc0001b2000, 0xdf5d40, 0x0, 0x0)
        /tmp/tmp.YgplR3yGUf/src/github.com/gopherjs/gopherjs/tool.go:155 +0xda
github.com/spf13/cobra.(*Command).execute(0xc0001b2000, 0xdf5d40, 0x0, 0x0, 0xc0001b2000, 0xdf5d40)
        /tmp/tmp.YgplR3yGUf/src/github.com/spf13/cobra/command.go:766 +0x2cc
github.com/spf13/cobra.(*Command).ExecuteC(0xc0001b3400, 0x8, 0x7, 0xc0001b2500)
        /tmp/tmp.YgplR3yGUf/src/github.com/spf13/cobra/command.go:852 +0x2fd
github.com/spf13/cobra.(*Command).Execute(0xc0001b3400, 0xc0000cbf48, 0x8)
        /tmp/tmp.YgplR3yGUf/src/github.com/spf13/cobra/command.go:800 +0x2b
main.main()
        /tmp/tmp.YgplR3yGUf/src/github.com/gopherjs/gopherjs/tool.go:534 +0x119c

@paralin
Copy link
Contributor Author

paralin commented Dec 6, 2018

That's the one!

@myitcv
Copy link
Member

myitcv commented Dec 6, 2018

@paralin I have a fix for this in myitcv#38 (for some reason that closed this issue which I am re-opening).

Per #855 (comment) that fork will be merged back into the main repo at some point hopefully soon.

@myitcv myitcv reopened this Dec 6, 2018
@myitcv
Copy link
Member

myitcv commented Dec 6, 2018

Also to note, per @paralin's observation above, there is a difference in behaviour between go test and gopherjs test when there are no test files (which is what lead to the above sequence of events). This is captured in myitcv#39 (which currently fails CI, pending the fix):

$ go test -run="TestScripts/test_no_tests"
--- FAIL: TestScripts (0.04s)
    --- FAIL: TestScripts/test_no_tests (0.33s)
        testscript.go:228:
            # go (0.067s)
            # gopherjs (0.189s)
            > ! gopherjs test
            [stdout]
            ?           mod     [no test files]
            FAIL: testdata/test_no_tests.txt:12: unexpected command success

FAIL
exit status 1
FAIL    github.com/gopherjs/gopherjs    0.411s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants