diff --git a/compiler/testData/codegen/box/builderInference/issues/kt60447a.kt b/compiler/testData/codegen/box/builderInference/issues/kt60447a.kt new file mode 100644 index 00000000000..71f2e08b7f0 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt60447a.kt @@ -0,0 +1,33 @@ +// ISSUE: KT-60447 + +// IGNORE_LIGHT_ANALYSIS +// IGNORE_BACKEND: ANY +// REASON: red code (see corresponding diagnostic test) + +fun box(): String { + val buildee = build { + class ConcreteType + class TargetType { + fun consumeConcreteType(value: ConcreteType) {} + } + setTypeVariableProducerFunction { TargetType() } + setTypeVariableConsumerFunction { it.consumeConcreteType(ConcreteType()) } + } + val targetType = buildee.typeVariableProducer() + buildee.typeVariableConsumer(targetType) + return "OK" +} + + + + +class Buildee { + var typeVariableConsumer: (TV) -> Unit = {} + var typeVariableProducer: () -> TV = { null!! } + fun setTypeVariableConsumerFunction(consumer: (TV) -> Unit) { typeVariableConsumer = consumer } + fun setTypeVariableProducerFunction(producer: () -> TV) { typeVariableProducer = producer } +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/codegen/box/builderInference/issues/kt60447b.kt b/compiler/testData/codegen/box/builderInference/issues/kt60447b.kt new file mode 100644 index 00000000000..3955492ca31 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt60447b.kt @@ -0,0 +1,34 @@ +// ISSUE: KT-60447 + +// IGNORE_LIGHT_ANALYSIS +// IGNORE_BACKEND: ANY +// REASON: red code (see corresponding diagnostic test) + +fun box(): String { + val buildee = build { + setTypeVariableProducerFunction { TargetType() } + setTypeVariableConsumerFunction { it.consumeConcreteType(ConcreteType()) } + } + val targetType = buildee.typeVariableProducer() + buildee.typeVariableConsumer(targetType) + return "OK" +} + + + + +class ConcreteType +class TargetType { + fun consumeConcreteType(value: ConcreteType) {} +} + +class Buildee { + var typeVariableConsumer: (TV) -> Unit = {} + var typeVariableProducer: () -> TV = { null!! } + fun setTypeVariableConsumerFunction(consumer: (TV) -> Unit) { typeVariableConsumer = consumer } + fun setTypeVariableProducerFunction(producer: () -> TV) { typeVariableProducer = producer } +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt60447a.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt60447a.fir.kt new file mode 100644 index 00000000000..7b4a33d8ca8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt60447a.fir.kt @@ -0,0 +1,30 @@ +// ISSUE: KT-60447 + +fun test() { + val buildee = build { + class ConcreteType + class TargetType { + fun consumeConcreteType(value: ConcreteType) {} + fun targetTypeMemberFunction() {} + } + setTypeVariableProducerFunction { TargetType() } + setTypeVariableConsumerFunction { it.consumeConcreteType(ConcreteType()) } + } + // local class equality check — turns unexpected compile-time behavior into red code + // considered to be non-user-reproducible code for the purposes of these tests + buildee.typeVariableProducer().targetTypeMemberFunction() +} + + + + +class Buildee { + var typeVariableConsumer: (TV) -> Unit = {} + var typeVariableProducer: () -> TV = { null!! } + fun setTypeVariableConsumerFunction(consumer: (TV) -> Unit) { typeVariableConsumer = consumer } + fun setTypeVariableProducerFunction(producer: () -> TV) { typeVariableProducer = producer } +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt60447a.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt60447a.kt new file mode 100644 index 00000000000..5c9d8ace974 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt60447a.kt @@ -0,0 +1,30 @@ +// ISSUE: KT-60447 + +fun test() { + val buildee = build { + class ConcreteType + class TargetType { + fun consumeConcreteType(value: ConcreteType) {} + fun targetTypeMemberFunction() {} + } + setTypeVariableProducerFunction { TargetType() } + setTypeVariableConsumerFunction { it.consumeConcreteType(ConcreteType()) } + } + // local class equality check — turns unexpected compile-time behavior into red code + // considered to be non-user-reproducible code for the purposes of these tests + buildee.typeVariableProducer().targetTypeMemberFunction() +} + + + + +class Buildee { + var typeVariableConsumer: (TV) -> Unit = {} + var typeVariableProducer: () -> TV = { null!! } + fun setTypeVariableConsumerFunction(consumer: (TV) -> Unit) { typeVariableConsumer = consumer } + fun setTypeVariableProducerFunction(producer: () -> TV) { typeVariableProducer = producer } +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt60447b.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt60447b.fir.kt new file mode 100644 index 00000000000..a1197b2792f --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt60447b.fir.kt @@ -0,0 +1,31 @@ +// ISSUE: KT-60447 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + setTypeVariableProducerFunction { TargetType() } + setTypeVariableConsumerFunction { it.consumeConcreteType(ConcreteType()) } + } + // exact type equality check — turns unexpected compile-time behavior into red code + // considered to be non-user-reproducible code for the purposes of these tests + checkExactType>(buildee) +} + + + + +class ConcreteType +class TargetType { + fun consumeConcreteType(value: ConcreteType) {} +} + +class Buildee { + var typeVariableConsumer: (TV) -> Unit = {} + var typeVariableProducer: () -> TV = { null!! } + fun setTypeVariableConsumerFunction(consumer: (TV) -> Unit) { typeVariableConsumer = consumer } + fun setTypeVariableProducerFunction(producer: () -> TV) { typeVariableProducer = producer } +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt60447b.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt60447b.kt new file mode 100644 index 00000000000..f2af8f000e2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt60447b.kt @@ -0,0 +1,31 @@ +// ISSUE: KT-60447 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + setTypeVariableProducerFunction { TargetType() } + setTypeVariableConsumerFunction { it.consumeConcreteType(ConcreteType()) } + } + // exact type equality check — turns unexpected compile-time behavior into red code + // considered to be non-user-reproducible code for the purposes of these tests + checkExactType>(buildee) +} + + + + +class ConcreteType +class TargetType { + fun consumeConcreteType(value: ConcreteType) {} +} + +class Buildee { + var typeVariableConsumer: (TV) -> Unit = {} + var typeVariableProducer: () -> TV = { null!! } + fun setTypeVariableConsumerFunction(consumer: (TV) -> Unit) { typeVariableConsumer = consumer } + fun setTypeVariableProducerFunction(producer: () -> TV) { typeVariableProducer = producer } +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +}