87904fd766
The main reason of this commit is the fact that it makes no sense to create type checker forks in case of two or more types which equal each other. Also, this commit fixes the test taken from KT-59514 (see interconnectedGenerics.kt test changed in this commit). In this particular case we have a subType of C.WithL<Pr!, En<Pr>!>, and a superType of R<T> with a superType constructor R. In findCorrespondingSupertypes we get *two* similar supertypes here, both have a string representation of: R<Il<@EnhancedNullability En<Pr>!>!>. If we create two forks because of it, we get NEW_INFERENCE_ERROR with the following subtyping violation: Il<@EnhancedNullability En<Pr>!>! <: En<Pr>!. NEW_INFERENCE_ERROR happens because we make a redundant fork in that case, but the forks should still work despite it (see KT-62333). These two types appear due to the content of FirCorrespondingSupertypeCache. For a key C.WithL and a superType R it stores the following pair of supertypes: - R<Il<@EnhancedNullability S>!> - R<Il<(@EnhancedNullability S & Any, @EnhancedNullability S?)>!> After substitution of S to En<Pr>! they become similar. NB: if we change jspecify severity level from strict to warn, then 'R<Il<(S & Any, S?)>!>' is the only remaining supertype, and @EnhancedNullability annotation is no more in use. The type hierarchy in this example looks like: WithL<T, S> <: CanWithB<T, S>, R.F<S, Il<S>> CanWithB<T, S> <: R.F<S, Il<S>> R.F<S, Il<S>> <: R<Il<S>> So R is reachable by two different ways, via CanWithB and directly via R.F. #KT-59514 Fixed