FIR: Make synthetic type variables fix to self-stub type if no info

This commit is contained in:
Simon Ogorodnik
2021-11-17 17:37:59 +03:00
committed by teamcity
parent 8ae37a3dd2
commit 11ec23e5dc
9 changed files with 80 additions and 2 deletions
@@ -4973,6 +4973,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/kt41917.kt");
}
@Test
@TestMetadata("mapValuesLazy.kt")
public void testMapValuesLazy() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/mapValuesLazy.kt");
}
@Test
@TestMetadata("nullableTypeDelegate.kt")
public void testNullableTypeDelegate() throws Exception {
@@ -0,0 +1,16 @@
FILE: mapValuesLazy.kt
public abstract interface TDat : R|kotlin/Any| {
}
public final fun resolve(str: R|kotlin/String|): R|TDat| {
^resolve Null(null)!!
}
public final val recProp: R|kotlin/collections/Map<kotlin/String, TDat>|by R|kotlin/lazy|<R|kotlin/collections/Map<kotlin/String, TDat>|>(<L> = lazy@fun <anonymous>(): R|kotlin/collections/Map<kotlin/String, TDat>| <inline=NoInline> {
^ R|kotlin/collections/mapOf|<R|kotlin/String|, R|kotlin/String|>(String().R|kotlin/to|<R|kotlin/String|, R|kotlin/String|>(String())).R|kotlin/collections/mapValues|<R|kotlin/String|, R|kotlin/String|, R|TDat|>(<L> = mapValues@fun <anonymous>(it: R|kotlin/collections/Map.Entry<kotlin/String, kotlin/String>|): R|TDat| <inline=Inline, kind=UNKNOWN> {
^ R|/resolve|(R|<local>/it|.R|SubstitutionOverride<kotlin/collections/Map.Entry.value: R|kotlin/String|>|)
}
)
}
)
public get(): R|kotlin/collections/Map<kotlin/String, TDat>| {
^ D|/recProp|.R|kotlin/getValue|<R|kotlin/collections/Map<kotlin/String, TDat>|>(Null(null), ::R|/recProp|)
}
@@ -0,0 +1,12 @@
interface TDat
fun resolve(str: String): TDat = null!!
val recProp by lazy {
mapOf(
"" to ""
).mapValues {
resolve(it.value)
}
}
@@ -4973,6 +4973,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/kt41917.kt");
}
@Test
@TestMetadata("mapValuesLazy.kt")
public void testMapValuesLazy() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/mapValuesLazy.kt");
}
@Test
@TestMetadata("nullableTypeDelegate.kt")
public void testNullableTypeDelegate() throws Exception {
@@ -4973,6 +4973,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/kt41917.kt");
}
@Test
@TestMetadata("mapValuesLazy.kt")
public void testMapValuesLazy() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/mapValuesLazy.kt");
}
@Test
@TestMetadata("nullableTypeDelegate.kt")
public void testNullableTypeDelegate() throws Exception {
@@ -11,13 +11,19 @@ import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents
import org.jetbrains.kotlin.fir.resolve.calls.Candidate
import org.jetbrains.kotlin.fir.resolve.calls.ResolutionContext
import org.jetbrains.kotlin.fir.resolve.calls.candidate
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionContext
import org.jetbrains.kotlin.types.model.StubTypeMarker
import org.jetbrains.kotlin.types.model.TypeVariableMarker
abstract class AbstractManyCandidatesInferenceSession(
protected val resolutionContext: ResolutionContext
) : FirInferenceSession() {
private val errorCalls: MutableList<FirResolvable> = mutableListOf()
override fun fixSyntheticTypeVariableWithNotEnoughInformation(
typeVariable: TypeVariableMarker,
completionContext: ConstraintSystemCompletionContext
) {
}
protected val partiallyResolvedCalls: MutableList<Pair<FirResolvable, Candidate>> = mutableListOf()
private val completedCalls: MutableSet<FirResolvable> = mutableSetOf()
@@ -226,9 +226,13 @@ class ConstraintSystemCompleter(private val components: BodyResolveComponents, p
val variableWithConstraints = notFixedTypeVariables.getValue(variableForFixation.variable)
if (variableForFixation.hasProperConstraint || context.inferenceSession.isSyntheticTypeVariable(variableWithConstraints.typeVariable)) {
if (variableForFixation.hasProperConstraint) {
fixVariable(asConstraintSystemCompletionContext(), topLevelType, variableWithConstraints, postponedArguments)
return true
} else if (context.inferenceSession.isSyntheticTypeVariable(variableWithConstraints.typeVariable)) {
val variable = variableWithConstraints.typeVariable as ConeTypeVariable
context.inferenceSession.fixSyntheticTypeVariableWithNotEnoughInformation(variable, asConstraintSystemCompletionContext())
return true
} else {
processVariableWhenNotEnoughInformation(this, variableWithConstraints, topLevelAtoms)
}
@@ -9,12 +9,14 @@ import org.jetbrains.kotlin.fir.declarations.FirProperty
import org.jetbrains.kotlin.fir.expressions.FirResolvable
import org.jetbrains.kotlin.fir.expressions.FirStatement
import org.jetbrains.kotlin.fir.resolve.calls.*
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeFixVariableConstraintPosition
import org.jetbrains.kotlin.fir.resolve.substitution.AbstractConeSubstitutor
import org.jetbrains.kotlin.fir.resolve.substitution.ChainedSubstitutor
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
import org.jetbrains.kotlin.resolve.calls.inference.buildAbstractResultingSubstitutor
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionContext
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionMode
import org.jetbrains.kotlin.resolve.calls.inference.model.*
import org.jetbrains.kotlin.types.model.*
@@ -162,6 +164,17 @@ class FirDelegatedPropertyInferenceSession(
return typeVariable in syntheticTypeVariableByTypeVariable.values
}
override fun fixSyntheticTypeVariableWithNotEnoughInformation(
typeVariable: TypeVariableMarker,
completionContext: ConstraintSystemCompletionContext
) {
completionContext.fixVariable(
typeVariable,
stubTypeBySyntheticTypeVariable[typeVariable]!!,
ConeFixVariableConstraintPosition(typeVariable)
)
}
fun completeCandidates(): List<FirResolvable> {
@Suppress("UNCHECKED_CAST")
val notCompletedCalls = partiallyResolvedCalls.mapNotNull { partiallyResolvedCall ->
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.fir.resolve.calls.Candidate
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.ConeStubType
import org.jetbrains.kotlin.fir.types.ConeTypeVariableTypeConstructor
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionContext
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionMode
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl
@@ -33,6 +34,10 @@ abstract class FirInferenceSession {
abstract fun registerStubTypes(map: Map<TypeVariableMarker, StubTypeMarker>)
abstract fun isSyntheticTypeVariable(typeVariable: TypeVariableMarker): Boolean
abstract fun fixSyntheticTypeVariableWithNotEnoughInformation(
typeVariable: TypeVariableMarker,
completionContext: ConstraintSystemCompletionContext
)
abstract fun inferPostponedVariables(
lambda: ResolvedLambdaAtom,
@@ -64,6 +69,10 @@ abstract class FirStubInferenceSession : FirInferenceSession() {
override fun registerStubTypes(map: Map<TypeVariableMarker, StubTypeMarker>) {}
override fun isSyntheticTypeVariable(typeVariable: TypeVariableMarker): Boolean = false
override fun fixSyntheticTypeVariableWithNotEnoughInformation(
typeVariable: TypeVariableMarker,
completionContext: ConstraintSystemCompletionContext
) {}
override fun createSyntheticStubTypes(system: NewConstraintSystemImpl): Map<TypeConstructorMarker, ConeStubType> = emptyMap()