[FE 1.0] Introduce builder inference stub types checker which may report more precise and clear errors due to resolution ambiguity

^KT-49828 Fixed
This commit is contained in:
Victor Petukhov
2022-01-10 14:16:42 +03:00
committed by teamcity
parent dcc42d66c3
commit 455b3143e7
25 changed files with 884 additions and 71 deletions
@@ -78,14 +78,14 @@ class ClassicTypeSystemContextForCS(
override fun createStubTypeForBuilderInference(typeVariable: TypeVariableMarker): StubTypeMarker {
return StubTypeForBuilderInference(
typeVariable.freshTypeConstructor() as TypeConstructor,
typeVariable.freshTypeConstructor() as NewTypeVariableConstructor,
typeVariable.defaultType().isMarkedNullable()
)
}
override fun createStubTypeForTypeVariablesInSubtyping(typeVariable: TypeVariableMarker): StubTypeMarker {
return StubTypeForTypeVariablesInSubtyping(
typeVariable.freshTypeConstructor() as TypeConstructor,
typeVariable.freshTypeConstructor() as NewTypeVariableConstructor,
typeVariable.defaultType().isMarkedNullable()
)
}
@@ -34,8 +34,7 @@ class TypeVariableTypeConstructor(
private val builtIns: KotlinBuiltIns,
val debugName: String,
override val originalTypeParameter: TypeParameterDescriptor?
) : TypeConstructor,
NewTypeVariableConstructor, TypeVariableTypeConstructorMarker {
) : NewTypeVariableConstructor, TypeVariableTypeConstructorMarker {
override fun getParameters(): List<TypeParameterDescriptor> = emptyList()
override fun getSupertypes(): Collection<KotlinType> = emptyList()
override fun isFinal(): Boolean = false
@@ -59,11 +59,11 @@ interface LambdaKotlinCallArgument : PostponableKotlinCallArgument {
*/
var hasBuilderInferenceAnnotation: Boolean
get() = false
set(@Suppress("UNUSED_PARAMETER") value) {}
set(_) {}
var builderInferenceSession: InferenceSession?
get() = null
set(@Suppress("UNUSED_PARAMETER") value) {}
set(_) {}
/**
* parametersTypes == null means, that there is no declared arguments
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.util
import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableTypeConstructor
import org.jetbrains.kotlin.resolve.calls.inference.model.typeForTypeVariable
import org.jetbrains.kotlin.types.model.TypeSubstitutorMarker
fun NewConstraintSystem.buildNotFixedVariablesToPossibleResultType(resolutionCallbacks: KotlinResolutionCallbacks): TypeSubstitutorMarker =
asConstraintSystemCompleterContext().typeSubstitutorByTypeConstructor(
getBuilder().currentStorage().notFixedTypeVariables.mapValues {
val typeVariable = it.key as TypeVariableTypeConstructor
resolutionCallbacks.findResultType(this, typeVariable) ?: typeVariable.typeForTypeVariable()
}
)