Remove constraints containing stub types after completion of the common system of a builder inference call
^KT-49285 Fixed
This commit is contained in:
+6
@@ -18489,6 +18489,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/inference/builderInference/kt48633.kt");
|
runTest("compiler/testData/codegen/box/inference/builderInference/kt48633.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt49285.kt")
|
||||||
|
public void testKt49285() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inference/builderInference/kt49285.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("labaledCall.kt")
|
@TestMetadata("labaledCall.kt")
|
||||||
public void testLabaledCall() throws Exception {
|
public void testLabaledCall() throws Exception {
|
||||||
|
|||||||
@@ -129,6 +129,11 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
|
|||||||
return this.isExtensionFunctionType
|
return this.isExtensionFunctionType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun StubTypeMarker.getOriginalTypeVariable(): TypeVariableTypeConstructorMarker {
|
||||||
|
require(this is ConeStubType)
|
||||||
|
return this.variable.typeConstructor
|
||||||
|
}
|
||||||
|
|
||||||
override fun KotlinTypeMarker.typeDepth() = when (this) {
|
override fun KotlinTypeMarker.typeDepth() = when (this) {
|
||||||
is ConeSimpleKotlinType -> typeDepth()
|
is ConeSimpleKotlinType -> typeDepth()
|
||||||
is ConeFlexibleType -> maxOf(lowerBound().typeDepth(), upperBound().typeDepth())
|
is ConeFlexibleType -> maxOf(lowerBound().typeDepth(), upperBound().typeDepth())
|
||||||
|
|||||||
+2
@@ -19,6 +19,8 @@ interface PostponedArgumentsAnalyzerContext : TypeSystemInferenceExtensionContex
|
|||||||
|
|
||||||
fun hasUpperOrEqualUnitConstraint(type: KotlinTypeMarker): Boolean
|
fun hasUpperOrEqualUnitConstraint(type: KotlinTypeMarker): Boolean
|
||||||
|
|
||||||
|
fun removePostponedTypeVariablesFromConstraints(postponedTypeVariables: Set<TypeConstructorMarker>)
|
||||||
|
|
||||||
// mutable operations
|
// mutable operations
|
||||||
fun addOtherSystem(otherSystem: ConstraintStorage)
|
fun addOtherSystem(otherSystem: ConstraintStorage)
|
||||||
|
|
||||||
|
|||||||
+8
@@ -531,4 +531,12 @@ class NewConstraintSystemImpl(
|
|||||||
it.type.lowerBoundIfFlexible().isUnit()
|
it.type.lowerBoundIfFlexible().isUnit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun removePostponedTypeVariablesFromConstraints(postponedTypeVariables: Set<TypeConstructorMarker>) {
|
||||||
|
for ((_, variableWithConstraints) in storage.notFixedTypeVariables) {
|
||||||
|
variableWithConstraints.removeConstrains { constraint ->
|
||||||
|
constraint.type.contains { it is StubTypeMarker && it.getOriginalTypeVariable() in postponedTypeVariables }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -211,6 +211,8 @@ class PostponedArgumentsAnalyzer(
|
|||||||
// We add <inferred type> <: TypeVariable(T) to be able to contribute type info from several builder inference lambdas
|
// We add <inferred type> <: TypeVariable(T) to be able to contribute type info from several builder inference lambdas
|
||||||
c.getBuilder().addSubtypeConstraint(resultType, variable.defaultType(c), BuilderInferencePosition)
|
c.getBuilder().addSubtypeConstraint(resultType, variable.defaultType(c), BuilderInferencePosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.removePostponedTypeVariablesFromConstraints(postponedVariables.keys)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
// DONT_TARGET_EXACT_BACKEND: WASM
|
||||||
|
// IGNORE_BACKEND_FIR: JVM_IR
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
import kotlin.experimental.ExperimentalTypeInference
|
||||||
|
|
||||||
|
class Foo<T> {
|
||||||
|
fun add(x: T) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalTypeInference::class)
|
||||||
|
fun <K1> myBuilder1(@BuilderInference builder: Foo<K1>.() -> Foo<K1>): Foo<K1> = Foo<K1>().apply { builder() }
|
||||||
|
|
||||||
|
@OptIn(ExperimentalTypeInference::class)
|
||||||
|
fun <K2> myBuilder2(@BuilderInference builder: Foo<K2>.() -> Unit): Foo<K2> = Foo<K2>().apply(builder)
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val result1 = myBuilder1 {
|
||||||
|
add(null)
|
||||||
|
myBuilder2 {
|
||||||
|
add("")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+6
@@ -18363,6 +18363,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/inference/builderInference/kt48633.kt");
|
runTest("compiler/testData/codegen/box/inference/builderInference/kt48633.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt49285.kt")
|
||||||
|
public void testKt49285() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inference/builderInference/kt49285.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("labaledCall.kt")
|
@TestMetadata("labaledCall.kt")
|
||||||
public void testLabaledCall() throws Exception {
|
public void testLabaledCall() throws Exception {
|
||||||
|
|||||||
+6
@@ -18489,6 +18489,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/inference/builderInference/kt48633.kt");
|
runTest("compiler/testData/codegen/box/inference/builderInference/kt48633.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt49285.kt")
|
||||||
|
public void testKt49285() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inference/builderInference/kt49285.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("labaledCall.kt")
|
@TestMetadata("labaledCall.kt")
|
||||||
public void testLabaledCall() throws Exception {
|
public void testLabaledCall() throws Exception {
|
||||||
|
|||||||
+5
@@ -15226,6 +15226,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/inference/builderInference/kt48633.kt");
|
runTest("compiler/testData/codegen/box/inference/builderInference/kt48633.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt49285.kt")
|
||||||
|
public void testKt49285() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inference/builderInference/kt49285.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("labaledCall.kt")
|
@TestMetadata("labaledCall.kt")
|
||||||
public void testLabaledCall() throws Exception {
|
public void testLabaledCall() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inference/builderInference/labaledCall.kt");
|
runTest("compiler/testData/codegen/box/inference/builderInference/labaledCall.kt");
|
||||||
|
|||||||
@@ -226,6 +226,8 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
|
|||||||
|
|
||||||
fun KotlinTypeMarker.getFunctionalTypeFromSupertypes(): KotlinTypeMarker
|
fun KotlinTypeMarker.getFunctionalTypeFromSupertypes(): KotlinTypeMarker
|
||||||
|
|
||||||
|
fun StubTypeMarker.getOriginalTypeVariable(): TypeVariableTypeConstructorMarker
|
||||||
|
|
||||||
fun getFunctionTypeConstructor(parametersNumber: Int, isSuspend: Boolean): TypeConstructorMarker
|
fun getFunctionTypeConstructor(parametersNumber: Int, isSuspend: Boolean): TypeConstructorMarker
|
||||||
|
|
||||||
fun getKFunctionTypeConstructor(parametersNumber: Int, isSuspend: Boolean): TypeConstructorMarker
|
fun getKFunctionTypeConstructor(parametersNumber: Int, isSuspend: Boolean): TypeConstructorMarker
|
||||||
|
|||||||
@@ -94,6 +94,11 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
|||||||
return this is StubTypeForBuilderInference || isDefNotNullStubType<StubTypeForBuilderInference>()
|
return this is StubTypeForBuilderInference || isDefNotNullStubType<StubTypeForBuilderInference>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun StubTypeMarker.getOriginalTypeVariable(): TypeVariableTypeConstructorMarker {
|
||||||
|
require(this is AbstractStubType, this::errorMessage)
|
||||||
|
return this.originalTypeVariable as TypeVariableTypeConstructorMarker
|
||||||
|
}
|
||||||
|
|
||||||
override fun CapturedTypeMarker.lowerType(): KotlinTypeMarker? {
|
override fun CapturedTypeMarker.lowerType(): KotlinTypeMarker? {
|
||||||
require(this is NewCapturedType, this::errorMessage)
|
require(this is NewCapturedType, this::errorMessage)
|
||||||
return this.lowerType
|
return this.lowerType
|
||||||
|
|||||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+5
@@ -13290,6 +13290,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
|||||||
runTest("compiler/testData/codegen/box/inference/builderInference/kt48633.kt");
|
runTest("compiler/testData/codegen/box/inference/builderInference/kt48633.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt49285.kt")
|
||||||
|
public void testKt49285() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inference/builderInference/kt49285.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("labaledCall.kt")
|
@TestMetadata("labaledCall.kt")
|
||||||
public void testLabaledCall() throws Exception {
|
public void testLabaledCall() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inference/builderInference/labaledCall.kt");
|
runTest("compiler/testData/codegen/box/inference/builderInference/labaledCall.kt");
|
||||||
|
|||||||
Generated
+5
@@ -12696,6 +12696,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/inference/builderInference/kt48633.kt");
|
runTest("compiler/testData/codegen/box/inference/builderInference/kt48633.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt49285.kt")
|
||||||
|
public void testKt49285() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inference/builderInference/kt49285.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("labaledCall.kt")
|
@TestMetadata("labaledCall.kt")
|
||||||
public void testLabaledCall() throws Exception {
|
public void testLabaledCall() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inference/builderInference/labaledCall.kt");
|
runTest("compiler/testData/codegen/box/inference/builderInference/labaledCall.kt");
|
||||||
|
|||||||
+7
@@ -14387,6 +14387,13 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/inference/builderInference/kt48633.kt");
|
runTest("compiler/testData/codegen/box/inference/builderInference/kt48633.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt49285.kt")
|
||||||
|
public void testKt49285() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inference/builderInference/kt49285.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
@TestMetadata("labaledCall.kt")
|
@TestMetadata("labaledCall.kt")
|
||||||
public void testLabaledCall() throws Exception {
|
public void testLabaledCall() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inference/builderInference/labaledCall.kt");
|
runTest("compiler/testData/codegen/box/inference/builderInference/labaledCall.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user