NI: Fix regression for star-projections approximation

See the test added

^KT-35703 Fixed
This commit is contained in:
Denis Zharkov
2020-01-10 16:06:15 +03:00
parent 7255ee0a5b
commit 4202c9c1a4
13 changed files with 92 additions and 13 deletions
@@ -0,0 +1,20 @@
// SKIP_TXT
// !LANGUAGE: +NewInference
// See KT-14453 and KT-35703
val <T : Any> KClass1<T>.primaryConstructor: KFunction1<T>? get() = null!!
interface KClass1<F : Any>
interface KFunction1<out R>
fun f(type: KClass1<*>): KFunction1<Any>? =
// What happens here:
// 1. Create captured type for type argument T (it's built upon star-projection from `KClass<*>` that's argument is <: Any)
// 2. Approximate resulting descriptor, now it 'KClass1<*>.primaryConstructor: KFunction1<*>'
// Note that star-projection in 'KFunction1<*>' is obtained from KClass and its `projectionType` is Any (not-nullable).
// Of course that situation is already strange
// 3. When checking subtyping after call completion we get that 'KFunction1<*>' is not a subtype of 'KFunction1<Any>' in new type checker.
// The answer is correct, but this old type checker used `projectionType` for this and it was resulting in KFunction1<*> <: KFunction1<Any>
//
// So to fix the issue we use 'out starProjectionType' instead of star-projection itself in approximation
// Note that in new inference there should be no approximation for IN-position types (they must remain captured)
type.primaryConstructor
@@ -0,0 +1,20 @@
// SKIP_TXT
// !LANGUAGE: +NewInference
// See KT-14453 and KT-35703
val <T : Any> KClass1<T>.primaryConstructor: KFunction1<T>? get() = null!!
interface KClass1<F : Any>
interface KFunction1<out R>
fun f(type: KClass1<*>): KFunction1<Any>? =
// What happens here:
// 1. Create captured type for type argument T (it's built upon star-projection from `KClass<*>` that's argument is <: Any)
// 2. Approximate resulting descriptor, now it 'KClass1<*>.primaryConstructor: KFunction1<*>'
// Note that star-projection in 'KFunction1<*>' is obtained from KClass and its `projectionType` is Any (not-nullable).
// Of course that situation is already strange
// 3. When checking subtyping after call completion we get that 'KFunction1<*>' is not a subtype of 'KFunction1<Any>' in new type checker.
// The answer is correct, but this old type checker used `projectionType` for this and it was resulting in KFunction1<*> <: KFunction1<Any>
//
// So to fix the issue we use 'out starProjectionType' instead of star-projection itself in approximation
// Note that in new inference there should be no approximation for IN-position types (they must remain captured)
type.primaryConstructor