From 9f6a81278657908362706495b58802e81e780b02 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Fri, 19 Nov 2021 04:19:18 +0300 Subject: [PATCH] Fix multiple registration of same type variable in builder inference --- .../inference/BuilderInferenceSession.kt | 8 +++---- .../stubTypes/commonSuperTypeContravariant.kt | 24 +++++++++---------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/BuilderInferenceSession.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/BuilderInferenceSession.kt index f10a37c0364..72f7d473908 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/BuilderInferenceSession.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/BuilderInferenceSession.kt @@ -325,14 +325,12 @@ class BuilderInferenceSession( shouldIntegrateAllConstraints: Boolean ) { storage.notFixedTypeVariables.values.forEach { - if (it.typeVariable.freshTypeConstructor(commonSystem.typeSystemContext) !in commonSystem.allTypeVariables) { - commonSystem.registerVariable(it.typeVariable) - } + commonSystem.registerTypeVariableIfNotPresent(it.typeVariable) } for (parentSession in findAllParentBuildInferenceSessions()) { for ((variable, stubType) in parentSession.stubsForPostponedVariables) { - commonSystem.registerVariable(variable) + commonSystem.registerTypeVariableIfNotPresent(variable) commonSystem.addSubtypeConstraint( variable.defaultType, stubType, @@ -378,7 +376,7 @@ class BuilderInferenceSession( if (shouldIntegrateAllConstraints) { for ((variableConstructor, type) in storage.fixedTypeVariables) { val typeVariable = storage.allTypeVariables.getValue(variableConstructor) - commonSystem.registerVariable(typeVariable) + commonSystem.registerTypeVariableIfNotPresent(typeVariable) commonSystem.addEqualityConstraint((typeVariable as NewTypeVariable).defaultType, type, BuilderInferencePosition) } } diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeContravariant.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeContravariant.kt index bccf7a00a0c..312c306726c 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeContravariant.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeContravariant.kt @@ -47,24 +47,24 @@ fun test() { build2 { emit(1) - select1(this@build.get(), ; In")!>getIn()) - select1(get(), ; In!")!>Test.foo(this@build.getIn())) - select1(Test.foo(this@build.get()), ; In!")!>Test.foo(getIn())) - select1(Test.foo(get()), ; In")!>this@build.getIn()) - select2(this@build.get(), ; In")!>getIn()) + select1(this@build.get(), ; In")!>getIn()) + select1(get(), ; In!")!>Test.foo(this@build.getIn())) + select1(Test.foo(this@build.get()), ; In!")!>Test.foo(getIn())) + select1(Test.foo(get()), ; In")!>this@build.getIn()) + select2(this@build.get(), ; In")!>getIn()) select2(get(), ; In!")!>Test.foo(this@build.getIn())) - select2(Test.foo(this@build.get()), ; In!")!>Test.foo(getIn())) + select2(Test.foo(this@build.get()), ; In!")!>Test.foo(getIn())) select2(Test.foo(get()), ; In")!>this@build.getIn()) - select3(this@build.get(), ; In")!>getIn()) + select3(this@build.get(), ; In")!>getIn()) select3(get(), ; In!")!>Test.foo(this@build.getIn())) - select3(Test.foo(this@build.get()), ; In!")!>Test.foo(getIn())) + select3(Test.foo(this@build.get()), ; In!")!>Test.foo(getIn())) select3(Test.foo(get()), ; In")!>this@build.getIn()) - select4(this@build.get(), ; In")!>getIn()) + select4(this@build.get(), ; In")!>getIn()) select4(get(), ; In!")!>Test.foo(this@build.getIn())) - select4(Test.foo(this@build.get()), ; In!")!>Test.foo(getIn())) - select4(Test.foo(get()), ; In")!>this@build.getIn()) + select4(Test.foo(this@build.get()), ; In!")!>Test.foo(getIn())) + select4(Test.foo(get()), ; In")!>this@build.getIn()) - select4(id(Test.foo(this@build.get())), ; In")!>getIn()) + select4(id(Test.foo(this@build.get())), ; In")!>getIn()) "" } ""