Skip to content

cmd/compile, go/types: ICE due to recursive unification inside func literals #57155

@findleyr

Description

@findleyr

The following valid Go code causes the type checker to panic, at 1.19 and tip. At 1.18 it merely causes a confusing compilation error (because we cautiously didn't panic at the unification depth limit).

func f[P *Q, Q any](P, Q) {
	func() {
		_ = f[P]
	}()
}

https://go.dev/play/p/9-OrhazCB7t?v=gotip

The reason is that function literal type-checking clobbers the environment used to detect self-recursive instantiation in https://go.dev/cl/385494.

This seems like a panic that would not be that hard to encounter, though it is clearly not a burning fire since it has been present since the initial launch of generics.

I think we should probably fix for 1.20, and perhaps backport.

CC @griesemer

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions