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: "interface is nil, not interface {}" panic in generic code #47925

Closed
mdempsky opened this issue Aug 23, 2021 · 3 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mdempsky
Copy link
Member

Reported on Discord, this programs fails with a runtime panic with -G=3:

package main

type myifacer[T any] interface{ do(T) error }

type stuff[T any] struct{}

func (s stuff[T]) run() interface{} {
	var i myifacer[T]
	return i
}

func main() {
	stuff[int]{}.run()
}

It works with go2go and GOEXPERIMENT=unified.

/cc @danscales @randall77

@mdempsky mdempsky added the NeedsFix The path to resolution is known, but the work has not been done. label Aug 23, 2021
@mdempsky mdempsky added this to the Go1.18 milestone Aug 23, 2021
@danscales
Copy link
Contributor

@randall77 Looks like my change here: https://go-review.googlesource.com/c/go/+/342009/4/src/cmd/compile/internal/noder/stencil.go
doesn't quite work if the source interface is nil, since type assertions fail for nil values. Is there any simple/clean way to fix this approach, besides putting a nil check around the code?

If only adding a nil check will work, then I think I will just go back to my other implementation https://go-review.googlesource.com/c/go/+/342009/2/src/cmd/compile/internal/noder/stencil.go (which you also thought was fine) that explicitly gets the runtime type from the itab. That approach works with the above test case. I will make it so we share the itabType() code with walk.go, rather than duplicating.

@danscales danscales self-assigned this Aug 24, 2021
@randall77
Copy link
Contributor

I have a fix for this, at least in part. It's more complicated than either of the above suggestions.
When converting from an interface, we need to use the runtime type from the type word of the interface, not from the dictionary. The dictionary can only provide the interface type for itabs, if the result is a nonempty interface.

@gopherbot
Copy link

Change https://golang.org/cl/344830 mentions this issue: cmd/compile: fix stenciling of conversions between interfaces

@danscales danscales assigned randall77 and unassigned danscales Aug 25, 2021
@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants