Skip to content

fixedbugs/bug180.go, fixedbugs/issue12133.go: Causes panic in fixNumber due to unhandled Basic.Kind value types.UntypedInt. #297

Closed
@dmitshur

Description

@dmitshur

This is the first two of four panics found via Go compiler tests added in #296.

This is the failing test case:

package main

func shift(x int) int { return 1 << (1 << (1 << (uint(x)))) }

func main() {
    if n := shift(2); n != 1<<(1<<(1<<2)) {
        println("bad shift", n)
        panic("fail")
    }
}

It causes a panic in fixNumber: panic: 20. Changing the output to make the error more readable:

-panic(int(basic.Kind()))
+panic(fmt.Sprintf("fixNumber unhandled basic.Kind(): %s", basic.String()))

We get:

panic: fixNumber unhandled basic.Kind(): untyped int

These are all the values of types.BasicKind: https://godoc.org/go/types#BasicKind.

I imagine the fix is simply to add types.UntypedInt to the case that handles types.Int.

Reproduce

$ cd $GOPATH/src/github.com/gopherjs/gopherjs/tests
$ go run run.go -v -summary -show_known_fails -- fixedbugs/bug180.go
goos: "darwin", goarch: "js"
# go run run.go -- fixedbugs/bug180.go
exit status 2
panic: 20

goroutine 1 [running]:
github.com/gopherjs/gopherjs/compiler.(*funcContext).fixNumber(0xc820158370, 0xc82010d3c0, 0x9098a0, 0xc820124900)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/expressions.go:1177 +0x235
github.com/gopherjs/gopherjs/compiler.(*funcContext).translateExpr(0xc820158370, 0xe00460, 0xc820111740, 0xc820146928)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/expressions.go:383 +0xed76
github.com/gopherjs/gopherjs/compiler.(*funcContext).formatExprInternal.func3.1(0x0, 0x0)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/expressions.go:1265 +0x1d8
github.com/gopherjs/gopherjs/compiler.(*funcContext).formatExprInternal.func3(0x6500, 0x0)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/expressions.go:1286 +0x571
github.com/gopherjs/gopherjs/compiler.(*funcContext).formatExprInternal.func1(0xc820115590)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/expressions.go:1220 +0xcf
github.com/gopherjs/gopherjs/compiler.(*funcContext).formatExprInternal(0xc820158370, 0x62f3d0, 0x2, 0xc82010f3c0, 0x1, 0x1, 0xc820146e01, 0xc820146e40)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/expressions.go:1339 +0x3b4
github.com/gopherjs/gopherjs/compiler.(*funcContext).formatParenExpr(0xc820158370, 0x62f3d0, 0x2, 0xc82010f3c0, 0x1, 0x1, 0x0)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/expressions.go:1204 +0x58
github.com/gopherjs/gopherjs/compiler.(*funcContext).translateExpr(0xc820158370, 0xe00428, 0xc82010c880, 0x909700)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/expressions.go:447 +0x1c097
github.com/gopherjs/gopherjs/compiler.(*funcContext).translateImplicitConversion(0xc820158370, 0xe00428, 0xc82010c880, 0xcb46b0, 0x909700, 0x0)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/expressions.go:1110 +0xbb0
github.com/gopherjs/gopherjs/compiler.(*funcContext).translateExpr(0xc820158370, 0xe00460, 0xc820111770, 0xc820149d28)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/expressions.go:383 +0xea20
github.com/gopherjs/gopherjs/compiler.(*funcContext).formatExprInternal.func3.1(0x0, 0x0)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/expressions.go:1265 +0x1d8
github.com/gopherjs/gopherjs/compiler.(*funcContext).formatExprInternal.func3(0x6500, 0x0)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/expressions.go:1286 +0x571
github.com/gopherjs/gopherjs/compiler.(*funcContext).formatExprInternal.func1(0xc820115540)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/expressions.go:1220 +0xcf
github.com/gopherjs/gopherjs/compiler.(*funcContext).formatExprInternal(0xc820158370, 0x62f3d0, 0x2, 0xc82010f360, 0x1, 0x1, 0xc82014a201, 0xc82014a240)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/expressions.go:1339 +0x3b4
github.com/gopherjs/gopherjs/compiler.(*funcContext).formatParenExpr(0xc820158370, 0x62f3d0, 0x2, 0xc82010f360, 0x1, 0x1, 0x0)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/expressions.go:1204 +0x58
github.com/gopherjs/gopherjs/compiler.(*funcContext).translateExpr(0xc820158370, 0xe00428, 0xc82010c8a0, 0x909700)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/expressions.go:447 +0x1c097
github.com/gopherjs/gopherjs/compiler.(*funcContext).translateImplicitConversion(0xc820158370, 0xe00428, 0xc82010c8a0, 0xcb46b0, 0x909700, 0x0)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/expressions.go:1110 +0xbb0
github.com/gopherjs/gopherjs/compiler.(*funcContext).translateExpr(0xc820158370, 0xe00460, 0xc8201117a0, 0x909660)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/expressions.go:383 +0xea20
github.com/gopherjs/gopherjs/compiler.(*funcContext).translateImplicitConversion(0xc820158370, 0xe00460, 0xc8201117a0, 0xcb46b0, 0x909660, 0x0)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/expressions.go:1085 +0x291
github.com/gopherjs/gopherjs/compiler.(*funcContext).translateResults(0xc820158370, 0xc82010eaa0, 0x1, 0x1, 0x0, 0x0)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/statements.go:801 +0x141
github.com/gopherjs/gopherjs/compiler.(*funcContext).translateStmt(0xc820158370, 0xe00498, 0xc82010c8c0, 0x0)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/statements.go:285 +0xcc6c
github.com/gopherjs/gopherjs/compiler.(*funcContext).translateStmtList(0xc820158370, 0xc82010eab0, 0x1, 0x1)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/statements.go:24 +0x9e
github.com/gopherjs/gopherjs/compiler.translateFunction.func1()
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/package.go:679 +0x9ba
github.com/gopherjs/gopherjs/compiler.(*funcContext).CatchOutput(0xc820158370, 0x1, 0xc820183810, 0x0, 0x0, 0x0)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/utils.go:64 +0x84
github.com/gopherjs/gopherjs/compiler.translateFunction(0xc82010c8e0, 0x0, 0x0, 0x0, 0xc8201117d0, 0xc820158210, 0xc820111bf0, 0xc820124840, 0xc82010e9b0, 0x5, ...)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/package.go:680 +0x6d0
github.com/gopherjs/gopherjs/compiler.(*funcContext).translateToplevelFunction.func1(0xc82010e9b0, 0x5, 0x0, 0x0, 0x0)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/package.go:562 +0x90a
github.com/gopherjs/gopherjs/compiler.(*funcContext).translateToplevelFunction(0xc820158210, 0xc820111800, 0xc820124840, 0x0, 0x0, 0x0)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/package.go:571 +0x3e2
github.com/gopherjs/gopherjs/compiler.Compile.func9()
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/package.go:340 +0x42
github.com/gopherjs/gopherjs/compiler.Compile.func5(0xc82015e6c0, 0x0, 0x0, 0x0)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/package.go:230 +0xa6
github.com/gopherjs/gopherjs/compiler.Compile(0x6356f8, 0x4, 0xc8201160d0, 0x1, 0x1, 0xc820112480, 0xc82010e840, 0x0, 0x7e94bc36, 0x0, ...)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/compiler/package.go:341 +0x47ec
github.com/gopherjs/gopherjs/build.(*Session).BuildPackage(0xc82010c540, 0xc820114af0, 0x0, 0x0)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/build/build.go:466 +0xfbf
github.com/gopherjs/gopherjs/build.(*Session).BuildFiles(0xc82010c540, 0xc82010e7e0, 0x1, 0x1, 0xc820114a50, 0x44, 0xc82010c2c0, 0x12, 0x0, 0x0)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/build/build.go:341 +0x2c9
main.main.func3.1(0x0, 0x0)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/tool.go:235 +0x473
main.handleError(0xc820185b30, 0xc820112400, 0x0, 0x0)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/tool.go:610 +0x46
main.main.func3(0xc820126540, 0xc82010e7e0, 0x1, 0x1)
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/tool.go:242 +0x5c
github.com/spf13/cobra.(*Command).execute(0xc820126540, 0xc82010e770, 0x1, 0x1, 0x0, 0x0)
    /Users/Dmitri/Dropbox/Work/2013/GoLanding/src/github.com/spf13/cobra/command.go:499 +0x869
github.com/spf13/cobra.(*Command).Execute(0xc820126c40, 0x0, 0x0)
    /Users/Dmitri/Dropbox/Work/2013/GoLanding/src/github.com/spf13/cobra/command.go:582 +0x46a
main.main()
    /Users/Dmitri/Dropbox/Work/2013/GoLand/src/github.com/gopherjs/gopherjs/tool.go:461 +0x13cd

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
    /usr/local/go/src/runtime/asm_amd64.s:1696 +0x1

knfl    fixedbugs/bug180.go 0.020s
    1 knfl

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