Follow up on https://github.com/golang/go/issues/39664
Did a git pull, but still find a way to let it panic by accident, I was trying to correct Robert version so it would compile but failed to do so.
package main
type T(type _) struct {}
func (e T(int)) m()
func _() {
var x interface { m() }
x = T(int){}
_ = x
}
go tool go2go run hello.go2
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x1211069]
goroutine 1 [running]:
go/go2go.(*translator).instantiateBlockStmt(0xc0001876f8, 0xc00010f3b0, 0x0, 0xc00011a280)
/usr/local/go/src/go/go2go/instantiate.go:500 +0x29
go/go2go.(*translator).instantiateTypeDecl(0xc0001876f8, 0x0, 0xc00011a3a0, 0xc000128240, 0xc000108430, 0x1, 0x1, 0xc0001085a0, 0x1, 0x1, ...)
/usr/local/go/src/go/go2go/instantiate.go:211 +0x64e
go/go2go.(*translator).translateTypeInstantiation(0xc0001876f8, 0xc000106480)
/usr/local/go/src/go/go2go/rewrite.go:809 +0x4d8
go/go2go.(*translator).translateExpr(0xc0001876f8, 0xc000106480)
/usr/local/go/src/go/go2go/rewrite.go:617 +0x3bb
go/go2go.(*translator).translateExpr(0xc0001876f8, 0xc000108440)
/usr/local/go/src/go/go2go/rewrite.go:572 +0xf9
go/go2go.(*translator).translateExprList(0xc0001876f8, 0xc000108440, 0x1, 0x1)
/usr/local/go/src/go/go2go/rewrite.go:694 +0x46
go/go2go.(*translator).translateStmt(0xc0001876f8, 0xc000106550)
/usr/local/go/src/go/go2go/rewrite.go:495 +0x29d
go/go2go.(*translator).translateBlockStmt(0xc0001876f8, 0xc00010eb70)
/usr/local/go/src/go/go2go/rewrite.go:456 +0x52
go/go2go.(*translator).translateFuncDecl(0xc0001876f8, 0xc0001065a0)
/usr/local/go/src/go/go2go/rewrite.go:449 +0xc5
go/go2go.(*translator).translate(0xc0001876f8, 0xc000132180)
/usr/local/go/src/go/go2go/rewrite.go:376 +0x391
go/go2go.rewriteAST(0xc000106240, 0xc00011f360, 0x0, 0x0, 0xc00011f5e0, 0xc000132180, 0x1a43a01, 0xc000106280, 0x140f7e0)
/usr/local/go/src/go/go2go/rewrite.go:188 +0x109
go/go2go.rewriteFile(0xc0001700a0, 0x43, 0xc000106240, 0xc00011f360, 0x0, 0x0, 0xc00011f5e0, 0xc000170230, 0x4e, 0xc000132180, ...)
/usr/local/go/src/go/go2go/rewrite.go:151 +0xb8
go/go2go.rewriteFilesInPath(0xc00011f360, 0x0, 0x0, 0xc0001700a0, 0x43, 0xc0001082e0, 0x1, 0x1, 0x0, 0x0, ...)
/usr/local/go/src/go/go2go/go2go.go:104 +0xc11
go/go2go.rewriteToPkgs(0xc00011f360, 0x0, 0x0, 0xc0001700a0, 0x43, 0xc00010e050, 0xc0001700a0, 0x43, 0x7ffeefbff78e, 0xa)
/usr/local/go/src/go/go2go/go2go.go:46 +0x165
go/go2go.Rewrite(...)
/usr/local/go/src/go/go2go/go2go.go:30
main.translate(0xc00011f360, 0xc0001700a0, 0x43)
/usr/local/go/src/cmd/go2go/translate.go:15 +0x47
main.main()
/usr/local/go/src/cmd/go2go/main.go:53 +0xb0f
Thanks. The type-checker is happy with this, but the translator is not. ~Possibly it has trouble with the receiver of m declaring an int type parameter.~
Edited: The problem is the missing method body.
This looks like the same bug as https://github.com/golang/go/issues/39634#issuecomment-645630176 which is caused by the method not having a body (the top frame in the stack trace is instantiateBlockStmt).
Indeed. It has nothing to do with the receiver, it's that the method doesn't have a body. Will be fixed in the translator.
Change https://golang.org/cl/238761 mentions this issue: [dev.go2go] go/go2go: don't crash on functions/methods with no body
Thanks. Fixed on the dev.go2go branch.
Most helpful comment
Thanks. The type-checker is happy with this, but the translator is not. ~Possibly it has trouble with the receiver of
mdeclaring aninttype parameter.~Edited: The problem is the missing method body.