go/types, types2: consider only calling under at top-level in unification #59750
Labels
FrozenDueToAge
generics
Issue is related to generics
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
TypeInference
Issue is related to generic type inference
Milestone
This is a follow-up on #59740.
Per e-mail from @findleyr :
I think these types of problems can only arise when we allow taking 'under' when we shouldn't. Consider the abbreviated sequence below.
That 'under' in step 4 is not actually valid. The function types of step 1 are only assignable to each other if they are identical, at which point the 'under' transformation should be invalid.
I think the trick of taking 'under' is just a lossy encoding of the assignability condition for function argument type inference, and should not be a part of the core unification step.
Investigation: a quick change to the code shows:
If we only call "under" at the top level this case fails with an error message (as predicted):
type func(F[int]) of f does not match F[T] (cannot infer T)
Some existing tests fail, too, though just about a dozen or so. I've done a cursory examination and it might be possible to address them by being slightly more careful about the under calls (e.g., also allow them at the top-level after looking up a type parameter value).
Simply not panicking (but silently return) when we reach the recursion stack limit (i.e., setting panicAtUnificationDepthLimit to false) produces the same error:
type func(F[int]) of f does not match F[T] (cannot infer T)
We should investigate if we can solve #59740 more correctly by using a more careful approach to calling
under
.The text was updated successfully, but these errors were encountered: