Skip to content
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

cmd/go2go: panic if using a method on undefined type #39672

Closed
gertcuykens opened this issue Jun 18, 2020 · 5 comments
Closed

cmd/go2go: panic if using a method on undefined type #39672

gertcuykens opened this issue Jun 18, 2020 · 5 comments
Assignees
Milestone

Comments

@gertcuykens
Copy link
Contributor

@gertcuykens gertcuykens commented Jun 18, 2020

Follow up on #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
@griesemer
Copy link
Contributor

@griesemer griesemer commented Jun 18, 2020

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.

@griesemer griesemer added this to the Unreleased milestone Jun 18, 2020
@zeebo
Copy link
Contributor

@zeebo zeebo commented Jun 18, 2020

This looks like the same bug as #39634 (comment) which is caused by the method not having a body (the top frame in the stack trace is instantiateBlockStmt).

@griesemer
Copy link
Contributor

@griesemer griesemer commented Jun 18, 2020

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.

@gopherbot
Copy link

@gopherbot gopherbot commented Jun 18, 2020

Change https://golang.org/cl/238761 mentions this issue: [dev.go2go] go/go2go: don't crash on functions/methods with no body

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jun 18, 2020

Thanks. Fixed on the dev.go2go branch.

gopherbot pushed a commit that referenced this issue Jun 18, 2020
Fixes #39672

Change-Id: Ia9fa4e7d5090200d7c2b4f654ac7ee42d7d79732
Reviewed-on: https://go-review.googlesource.com/c/go/+/238761
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.