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: passing a generic function as a function argument crashes the compiler #59955

Closed
griesemer opened this issue May 3, 2023 · 2 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Milestone

Comments

@griesemer
Copy link
Contributor

package main

func f(func(int)) {}

func g[P any](P) {}

func main() {
	f(g)
}

crashes with internal compiler error:

$ go run testdata/manual.go 
# command-line-arguments
testdata/manual.go:15:4: internal compiler error: func[P any](P) is not assignable to func(int)

goroutine 1 [running]:
runtime/debug.Stack()
        ../../../../runtime/debug/stack.go:24 +0x64
cmd/compile/internal/base.FatalfAt({0x37e388?, 0x140?}, {0x102e77708, 0x1a}, {0x1400037e408, 0x2, 0x2})
        ../base/print.go:234 +0x1fc
cmd/compile/internal/noder.(*pkgWriter).fatalf(0x1400037e428?, {0x10307fc38?, 0x140003e14f0?}, {0x102e77708, 0x1a}, {0x1400037e408, 0x2, 0x2})
        ../noder/writer.go:116 +0x58
cmd/compile/internal/noder.(*writer).convertExpr(0x1400040adc0, {0x103080aa0, 0x140003f5ac0}, {0x103082860?, 0x140003e14f0}, 0x1)
        ../noder/writer.go:2115 +0x1a8
cmd/compile/internal/noder.(*writer).implicitConvExpr(...)
        ../noder/writer.go:2101
cmd/compile/internal/noder.(*writer).multiExpr(0x1400040adc0, {0x10307fbd8, 0x1400012aa80}, 0x1400037e720, {0x140000326e0, 0x1, 0x1400037e608?})
        ../noder/writer.go:2093 +0x1c0
cmd/compile/internal/noder.(*writer).expr(0x1400040adc0, {0x103082ae0?, 0x1400012aa80?})
        ../noder/writer.go:1930 +0x1384
cmd/compile/internal/noder.(*writer).stmt1(0x1400040adc0, {0x103081e28?, 0x1400006f3a0?})
        ../noder/writer.go:1261 +0x378
cmd/compile/internal/noder.(*writer).stmts(0x1400040adc0, {0x140000326f0, 0x1, 0x1400037ea9e?})
        ../noder/writer.go:1200 +0x64
cmd/compile/internal/noder.(*pkgWriter).bodyIdx(0x14000160180, 0x140003f5c40, 0x140003f59c0, 0x14000110820)
        ../noder/writer.go:1106 +0x16c
cmd/compile/internal/noder.(*writer).funcExt(0x1400040abb0, 0x1400012acb0)
        ../noder/writer.go:1044 +0x2d0
cmd/compile/internal/noder.(*writer).doObj(0x1400040ab00, 0x14000406450?, {0x103085d60, 0x1400012acb0?})
        ../noder/writer.go:804 +0x1a0
cmd/compile/internal/noder.(*pkgWriter).objIdx(0x14000160180, {0x103085d60, 0x1400012acb0})
        ../noder/writer.go:763 +0x66c
cmd/compile/internal/noder.(*pkgWriter).objInstIdx(0x140003ff810?, {0x103085d60, 0x1400012acb0}, 0x0, 0x3?)
        ../noder/writer.go:704 +0x104
cmd/compile/internal/noder.(*writer).obj(0x140003ff810, {0x103085d60?, 0x1400012acb0?}, 0x1400012acb0?)
        ../noder/writer.go:680 +0x34
cmd/compile/internal/noder.writePkgStub({0x0?, {0x0?, 0x0?}}, {0x1400005a450, 0x1, 0x1})
        ../noder/unified.go:231 +0x540
cmd/compile/internal/noder.unified({0x0?, {0x0?, 0x0?}}, {0x1400005a450?, 0x102fd4640?, 0xa50000010359be80?})
        ../noder/unified.go:75 +0x7c
cmd/compile/internal/noder.LoadPackage({0x14000000350, 0x1, 0x1})
        ../noder/noder.go:77 +0x3ac
cmd/compile/internal/gc.Main(0x10307bcb0)
        ../gc/main.go:198 +0xb6c
main.main()
        ../../main.go:57 +0x110

cc: @mdempsky for visibility

@griesemer griesemer added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker labels May 3, 2023
@griesemer griesemer added this to the Go1.21 milestone May 3, 2023
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label May 3, 2023
@griesemer
Copy link
Contributor Author

Once this is fixed, test/fixedbugs/issue59338.go should be updated accordingly (commented out test enabled).

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/492455 mentions this issue: cmd/compile: fix compilation of inferred type arguments

@golang golang locked and limited conversation to collaborators May 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Projects
None yet
Development

No branches or pull requests

2 participants