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

x/tools/cmd/eg: "panic: unreachable" while refactoring struct literals with unkeyed fields #10923

Open
josharian opened this issue May 21, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@josharian
Copy link
Contributor

commented May 21, 2015

This occurred while refactoring cmd/internal/obj's ProgInfo tables not to use unkeyed fields.

$GOPATH/src/egbug/x.go:

package egbug

type T struct {
    X int
}

func NewT(x int) T {
    return T{X: x}
}

func f() {
    var x int
    var _ T = T{x}
}

Template:

package p

import "egbug"

func before(x int) egbug.T { return egbug.T{x} }
func after(x int) egbug.T  { return egbug.NewT(x) }

eg output:

panic: unreachable

goroutine 1 [running]:
golang.org/x/tools/go/types.unreachable()
    golang.org/x/tools/go/types/errors.go:23 +0x6c
golang.org/x/tools/go/types.identical(0x0, 0x0, 0x22086933e0, 0x45a340, 0x0, 0x2208694538)
    golang.org/x/tools/go/types/predicates.go:281 +0x2f4
golang.org/x/tools/go/types.Identical(0x0, 0x0, 0x22086933e0, 0x45a340, 0x578fb646)
    golang.org/x/tools/go/types/predicates.go:115 +0x4f
golang.org/x/tools/go/types.(*operand).assignableTo(0x20858f260, 0x0, 0x22086933e0, 0x45a340, 0x0)
    golang.org/x/tools/go/types/operand.go:214 +0xbe
golang.org/x/tools/go/types.AssignableTo(0x0, 0x0, 0x22086933e0, 0x45a340, 0x0)
    golang.org/x/tools/go/types/api.go:352 +0x8d
golang.org/x/tools/refactor/eg.(*Transformer).matchWildcard(0x2084f4100, 0x2084f3a40, 0x2208693c48, 0x2084ef5c0, 0x2084dd824)
    golang.org/x/tools/refactor/eg/match.go:188 +0x414
golang.org/x/tools/refactor/eg.(*Transformer).matchExpr(0x2084f4100, 0x2208693b68, 0x2084ed6e0, 0x2208693c48, 0x2084ef5c0, 0x2084ef890)
    golang.org/x/tools/refactor/eg/match.go:40 +0x23f
golang.org/x/tools/refactor/eg.(*Transformer).matchExprs(0x2084f4100, 0x2084f0f40, 0x1, 0x1, 0x2084f0a80, 0x1, 0x1, 0x2208693410)
    golang.org/x/tools/refactor/eg/match.go:143 +0xb5
golang.org/x/tools/refactor/eg.(*Transformer).matchExpr(0x2084f4100, 0x2208693c80, 0x2084e9940, 0x2208693c80, 0x2084e9140, 0x2084e9140)
    golang.org/x/tools/refactor/eg/match.go:79 +0xa8c
golang.org/x/tools/refactor/eg.(*Transformer).Transform.func1(0x2b0f20, 0x2084e9140, 0x16, 0x0, 0x0, 0x0)
    golang.org/x/tools/refactor/eg/rewrite.go:58 +0x1cd
golang.org/x/tools/refactor/eg.apply(0x2085918d0, 0x29c7c0, 0x2084f0a90, 0xd4, 0x0, 0x0, 0x0)
    golang.org/x/tools/refactor/eg/rewrite.go:186 +0x2cf
golang.org/x/tools/refactor/eg.(*Transformer).Transform.func1(0x29c7c0, 0x2084f0a90, 0xd4, 0x0, 0x0, 0x0)
    golang.org/x/tools/refactor/eg/rewrite.go:51 +0xc4
golang.org/x/tools/refactor/eg.apply(0x2085918d0, 0x2200c0, 0x2084ecdc8, 0xd7, 0x0, 0x0, 0x0)
    golang.org/x/tools/refactor/eg/rewrite.go:177 +0x42b
golang.org/x/tools/refactor/eg.(*Transformer).Transform.func1(0x2200c0, 0x2084ecdc8, 0xd7, 0x0, 0x0, 0x0)
    golang.org/x/tools/refactor/eg/rewrite.go:51 +0xc4
golang.org/x/tools/refactor/eg.apply(0x2085918d0, 0x2b2900, 0x2084ecdc0, 0x16, 0x0, 0x0, 0x0)
    golang.org/x/tools/refactor/eg/rewrite.go:182 +0x566
golang.org/x/tools/refactor/eg.(*Transformer).Transform.func1(0x2b2900, 0x2084ecdc0, 0x16, 0x0, 0x0, 0x0)
    golang.org/x/tools/refactor/eg/rewrite.go:51 +0xc4
golang.org/x/tools/refactor/eg.apply(0x2085918d0, 0x29c980, 0x2084f0aa0, 0xd4, 0x0, 0x0, 0x0)
    golang.org/x/tools/refactor/eg/rewrite.go:186 +0x2cf
golang.org/x/tools/refactor/eg.(*Transformer).Transform.func1(0x29c980, 0x2084f0aa0, 0xd4, 0x0, 0x0, 0x0)
    golang.org/x/tools/refactor/eg/rewrite.go:51 +0xc4
golang.org/x/tools/refactor/eg.apply(0x2085918d0, 0x2201e0, 0x2084ef5f8, 0xd7, 0x0, 0x0, 0x0)
    golang.org/x/tools/refactor/eg/rewrite.go:177 +0x42b
golang.org/x/tools/refactor/eg.(*Transformer).Transform.func1(0x2201e0, 0x2084ef5f8, 0xd7, 0x0, 0x0, 0x0)
    golang.org/x/tools/refactor/eg/rewrite.go:51 +0xc4
golang.org/x/tools/refactor/eg.apply(0x2085918d0, 0x2b0740, 0x2084ef640, 0xd6, 0x0, 0x0, 0x0)
    golang.org/x/tools/refactor/eg/rewrite.go:182 +0x566
golang.org/x/tools/refactor/eg.(*Transformer).Transform.func1(0x2b0740, 0x2084ef640, 0xd6, 0x0, 0x0, 0x0)
    golang.org/x/tools/refactor/eg/rewrite.go:51 +0xc4
golang.org/x/tools/refactor/eg.apply(0x2085918d0, 0x2b1820, 0x2084ef620, 0x16, 0x0, 0x0, 0x0)
    golang.org/x/tools/refactor/eg/rewrite.go:182 +0x566
golang.org/x/tools/refactor/eg.(*Transformer).Transform.func1(0x2b1820, 0x2084ef620, 0x16, 0x0, 0x0, 0x0)
    golang.org/x/tools/refactor/eg/rewrite.go:51 +0xc4
golang.org/x/tools/refactor/eg.apply(0x2085918d0, 0x29c6e0, 0x2084ef660, 0xd4, 0x0, 0x0, 0x0)
    golang.org/x/tools/refactor/eg/rewrite.go:186 +0x2cf
golang.org/x/tools/refactor/eg.(*Transformer).Transform.func1(0x29c6e0, 0x2084ef660, 0xd4, 0x0, 0x0, 0x0)
    golang.org/x/tools/refactor/eg/rewrite.go:51 +0xc4
golang.org/x/tools/refactor/eg.apply(0x2085918d0, 0x220060, 0x208564398, 0xd7, 0x0, 0x0, 0x0)
    golang.org/x/tools/refactor/eg/rewrite.go:177 +0x42b
golang.org/x/tools/refactor/eg.(*Transformer).Transform.func1(0x220060, 0x208564398, 0xd7, 0x0, 0x0, 0x0)
    golang.org/x/tools/refactor/eg/rewrite.go:51 +0xc4
golang.org/x/tools/refactor/eg.apply(0x2085918d0, 0x29d080, 0x208564380, 0x16, 0x0, 0x0, 0x0)
    golang.org/x/tools/refactor/eg/rewrite.go:182 +0x566
golang.org/x/tools/refactor/eg.(*Transformer).Transform(0x2084f4100, 0x20856aa40, 0x2084f3130, 0x208564380, 0x0)
    golang.org/x/tools/refactor/eg/rewrite.go:83 +0x529
main.doMain(0x0, 0x0)
    golang.org/x/tools/cmd/eg/eg.go:113 +0x8f5
main.main()
    golang.org/x/tools/cmd/eg/eg.go:49 +0x27

@josharian josharian added this to the Unreleased milestone May 21, 2015

@josharian

This comment has been minimized.

Copy link
Contributor Author

commented May 21, 2015

Actually, marking this as Go1.5Maybe and cc'ing @griesemer, since it is a panic: unreachable from within go/types via exported APIs. I suspect that the change in go/types is probably just docs and/or a different panic message.

@josharian josharian modified the milestones: Go1.5Maybe, Unreleased May 21, 2015

@josharian josharian changed the title x/tools/cmd/eg: panic: unreachable refactoring struct literals with unkeyed fields x/tools/cmd/eg: "panic: unreachable" while refactoring struct literals with unkeyed fields May 22, 2015

@alandonovan

This comment has been minimized.

Copy link
Contributor

commented May 22, 2015

Thanks for the minimized test case. This is indeed an eg bug, caused by unifying a wildcard with a *ast.KeyValueExpr (which has no type).

The crash in go/types API is because IsAssignable is called with a nil argument. Let's call this an undocumented implicit precondition and say that it is working as intended.

Fix pending for eg.

@josharian josharian modified the milestones: Unreleased, Go1.5Maybe May 22, 2015

alandonovan added a commit to golang/tools that referenced this issue May 29, 2015

refactor/eg: fix crash while unifying wildcard with KeyValueExpr, whi…
…ch has no type

+ tests.

Fixes issue golang/go#10923

Change-Id: I0813cdfbb447bbd9f579bb1998b355a3179a7e79
Reviewed-on: https://go-review.googlesource.com/10332
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.