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/compile: assertion failure compiling embedded method on parameterized type #47797

Closed
griesemer opened this issue Aug 18, 2021 · 2 comments
Closed
Assignees
Milestone

Comments

@griesemer
Copy link
Contributor

@griesemer griesemer commented Aug 18, 2021

package p

type Foo[T any] struct {
        Val T
}

func (f Foo[T]) Bat() {}

type Bar struct {
        Foo[int]
}

func foo() {
        var b Bar
        b.Bat()
}

Compiling produces:

$ go tool compile -G=3 testdata/manual.go2 
testdata/manual.go2:15:9: internal compiler error: assertion failed

goroutine 1 [running]:
runtime/debug.Stack()
        /Users/gri/goroot/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x0, 0x0}, {0x18f1141, 0x10}, {0x0, 0x0, 0x0})
        /Users/gri/goroot/src/cmd/compile/internal/base/print.go:227 +0x154
cmd/compile/internal/base.Fatalf(...)
        /Users/gri/goroot/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/base.Assert(...)
        /Users/gri/goroot/src/cmd/compile/internal/base/print.go:239
cmd/compile/internal/noder.assert(...)
        /Users/gri/goroot/src/cmd/compile/internal/noder/stencil.go:27
cmd/compile/internal/noder.(*irgen).genericSubst(0xc000134300, 0xc0004194f0, 0xc00040fba0, {0x1fb5e30, 0x0, 0x0}, 0x1, 0xc000117dc0)
        /Users/gri/goroot/src/cmd/compile/internal/noder/stencil.go:658 +0x2eb
cmd/compile/internal/noder.(*irgen).getInstantiation(0xc000134300, 0xc00040fba0, {0x1fb5e30, 0x0, 0x0}, 0x58)
        /Users/gri/goroot/src/cmd/compile/internal/noder/stencil.go:600 +0x33d
cmd/compile/internal/noder.(*irgen).stencil.func1({0x1a5d3f8, 0xc00036e360})
        /Users/gri/goroot/src/cmd/compile/internal/noder/stencil.go:109 +0x2df
cmd/compile/internal/ir.Visit.func1({0x1a5d3f8, 0xc00036e360})
        /Users/gri/goroot/src/cmd/compile/internal/ir/visit.go:105 +0x30
cmd/compile/internal/ir.doNodes({0xc000117c80, 0x3, 0x0}, 0xc00000dcb0)
        /Users/gri/goroot/src/cmd/compile/internal/ir/node_gen.go:1512 +0x67
cmd/compile/internal/ir.(*Func).doChildren(0x1a5dd58, 0xc000410840)
        /Users/gri/goroot/src/cmd/compile/internal/ir/func.go:152 +0x2e
cmd/compile/internal/ir.DoChildren(...)
        /Users/gri/goroot/src/cmd/compile/internal/ir/visit.go:94
cmd/compile/internal/ir.Visit.func1({0x1a5dd58, 0xc000410840})
        /Users/gri/goroot/src/cmd/compile/internal/ir/visit.go:106 +0x57
cmd/compile/internal/ir.Visit({0x1a5dd58, 0xc000410840}, 0xc000117d80)
        /Users/gri/goroot/src/cmd/compile/internal/ir/visit.go:108 +0xb8
cmd/compile/internal/noder.(*irgen).stencil(0xc000134300)
        /Users/gri/goroot/src/cmd/compile/internal/noder/stencil.go:91 +0x26a
cmd/compile/internal/noder.(*irgen).generate(0xc000134300, {0xc00000e448, 0x1, 0x203000})
        /Users/gri/goroot/src/cmd/compile/internal/noder/irgen.go:265 +0x272
cmd/compile/internal/noder.check2({0xc00000e448, 0x1, 0x1})
        /Users/gri/goroot/src/cmd/compile/internal/noder/irgen.go:92 +0x16d
cmd/compile/internal/noder.LoadPackage({0xc00001e1d0, 0x1, 0x0})
        /Users/gri/goroot/src/cmd/compile/internal/noder/noder.go:90 +0x365
cmd/compile/internal/gc.Main(0x1918120)
        /Users/gri/goroot/src/cmd/compile/internal/gc/main.go:190 +0xaf3
main.main()
        /Users/gri/goroot/src/cmd/compile/main.go:55 +0xdd

cc: @danscales

@griesemer griesemer added this to the Go1.18 milestone Aug 18, 2021
@griesemer griesemer changed the title cmd/compile: assertion failure compiling generic code cmd/compile: assertion failure compiling embedded method on parameterized type Aug 18, 2021
@WangLeonard
Copy link

@WangLeonard WangLeonard commented Aug 19, 2021

Hi, I try to fix this problem in https://go-review.googlesource.com/c/go/+/343532
I think we need to add Expr and corresponding Inferred to check.Inferred at a suitable location,
But I haven't found this suitable location (Cannot get Expr, Signature and tArgs at the same time)
After I circumvented this problem, a new problem appeared
In cmd/compile/internal/gc/export.go/dumpexport functionn.Type().HasTParam() is true and it will call base.Fatalf

Maybe I still need some time to complete this fix, or trouble danscales to continue to fix it,
Hope my analysis is helpful to you.

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Sep 9, 2021

Change https://golang.org/cl/348549 mentions this issue: cmd/compile: fix wrong instantiated type for embedded receiver

Loading

@gopherbot gopherbot closed this in 2481f6e Sep 9, 2021
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
4 participants