From 11ec23e5dc1e67d4e333b9261040f1aee7bd91f5 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Wed, 17 Nov 2021 17:37:59 +0300 Subject: [PATCH] FIR: Make synthetic type variables fix to self-stub type if no info --- ...iagnosisCompilerFirTestdataTestGenerated.java | 6 ++++++ .../delegates/mapValuesLazy.fir.txt | 16 ++++++++++++++++ .../resolveWithStdlib/delegates/mapValuesLazy.kt | 12 ++++++++++++ .../test/runners/FirDiagnosticTestGenerated.java | 6 ++++++ ...FirDiagnosticsWithLightTreeTestGenerated.java | 6 ++++++ .../AbstractManyCandidatesInferenceSession.kt | 8 +++++++- .../inference/ConstraintSystemCompleter.kt | 6 +++++- .../FirDelegatedPropertyInferenceSession.kt | 13 +++++++++++++ .../fir/resolve/inference/FirInferenceSession.kt | 9 +++++++++ 9 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/mapValuesLazy.fir.txt create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/mapValuesLazy.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java index d5e3cef98d0..bb644a4ee78 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java @@ -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 { diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/mapValuesLazy.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/mapValuesLazy.fir.txt new file mode 100644 index 00000000000..96d82d14010 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/mapValuesLazy.fir.txt @@ -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|by R|kotlin/lazy||>( = lazy@fun (): R|kotlin/collections/Map| { + ^ R|kotlin/collections/mapOf|(String().R|kotlin/to|(String())).R|kotlin/collections/mapValues|( = mapValues@fun (it: R|kotlin/collections/Map.Entry|): R|TDat| { + ^ R|/resolve|(R|/it|.R|SubstitutionOverride|) + } + ) + } + ) + public get(): R|kotlin/collections/Map| { + ^ D|/recProp|.R|kotlin/getValue||>(Null(null), ::R|/recProp|) + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/mapValuesLazy.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/mapValuesLazy.kt new file mode 100644 index 00000000000..5dba4d2a94d --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/mapValuesLazy.kt @@ -0,0 +1,12 @@ +interface TDat + +fun resolve(str: String): TDat = null!! + +val recProp by lazy { + mapOf( + "" to "" + ).mapValues { + resolve(it.value) + } +} + diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java index cd1e0a4c819..808bdf7b5e2 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java @@ -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 { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java index 1b901f1795c..0758f6661eb 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java @@ -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 { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/AbstractManyCandidatesInferenceSession.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/AbstractManyCandidatesInferenceSession.kt index 1369b867472..be442c98682 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/AbstractManyCandidatesInferenceSession.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/AbstractManyCandidatesInferenceSession.kt @@ -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 = mutableListOf() + override fun fixSyntheticTypeVariableWithNotEnoughInformation( + typeVariable: TypeVariableMarker, + completionContext: ConstraintSystemCompletionContext + ) { + } + protected val partiallyResolvedCalls: MutableList> = mutableListOf() private val completedCalls: MutableSet = mutableSetOf() diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt index 6802a13dcbb..c640acd1781 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt @@ -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) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirDelegatedPropertyInferenceSession.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirDelegatedPropertyInferenceSession.kt index 8e91ced3956..f54bc37c451 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirDelegatedPropertyInferenceSession.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirDelegatedPropertyInferenceSession.kt @@ -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 { @Suppress("UNCHECKED_CAST") val notCompletedCalls = partiallyResolvedCalls.mapNotNull { partiallyResolvedCall -> diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirInferenceSession.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirInferenceSession.kt index bdb3a9b09a8..cb861207de6 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirInferenceSession.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirInferenceSession.kt @@ -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) 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) {} override fun isSyntheticTypeVariable(typeVariable: TypeVariableMarker): Boolean = false + override fun fixSyntheticTypeVariableWithNotEnoughInformation( + typeVariable: TypeVariableMarker, + completionContext: ConstraintSystemCompletionContext + ) {} override fun createSyntheticStubTypes(system: NewConstraintSystemImpl): Map = emptyMap()