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
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).
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