diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 012838bf62a..26fecc4b0cb 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -14219,6 +14219,30 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47744.kt"); } + @Test + @TestMetadata("kt47986.kt") + public void testKt47986() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47986.kt"); + } + + @Test + @TestMetadata("kt47986_2.kt") + public void testKt47986_2() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47986_2.kt"); + } + + @Test + @TestMetadata("kt47986_3.kt") + public void testKt47986_3() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47986_3.kt"); + } + + @Test + @TestMetadata("kt47986_4.kt") + public void testKt47986_4() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47986_4.kt"); + } + @Test @TestMetadata("kt49285.kt") public void testKt49285() throws Exception { @@ -14255,6 +14279,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt51148.kt"); } + @Test + @TestMetadata("kt51464.kt") + public void testKt51464() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt51464.kt"); + } + @Test @TestMetadata("labaledCall.kt") public void testLabaledCall() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 7d742f23647..2de5921e43a 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -14219,6 +14219,30 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47744.kt"); } + @Test + @TestMetadata("kt47986.kt") + public void testKt47986() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47986.kt"); + } + + @Test + @TestMetadata("kt47986_2.kt") + public void testKt47986_2() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47986_2.kt"); + } + + @Test + @TestMetadata("kt47986_3.kt") + public void testKt47986_3() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47986_3.kt"); + } + + @Test + @TestMetadata("kt47986_4.kt") + public void testKt47986_4() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47986_4.kt"); + } + @Test @TestMetadata("kt49285.kt") public void testKt49285() throws Exception { @@ -14255,6 +14279,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt51148.kt"); } + @Test + @TestMetadata("kt51464.kt") + public void testKt51464() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt51464.kt"); + } + @Test @TestMetadata("labaledCall.kt") public void testLabaledCall() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 4578948dc2f..417263fc525 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -14219,6 +14219,30 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47744.kt"); } + @Test + @TestMetadata("kt47986.kt") + public void testKt47986() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47986.kt"); + } + + @Test + @TestMetadata("kt47986_2.kt") + public void testKt47986_2() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47986_2.kt"); + } + + @Test + @TestMetadata("kt47986_3.kt") + public void testKt47986_3() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47986_3.kt"); + } + + @Test + @TestMetadata("kt47986_4.kt") + public void testKt47986_4() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47986_4.kt"); + } + @Test @TestMetadata("kt49285.kt") public void testKt49285() throws Exception { @@ -14255,6 +14279,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt51148.kt"); } + @Test + @TestMetadata("kt51464.kt") + public void testKt51464() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt51464.kt"); + } + @Test @TestMetadata("labaledCall.kt") public void testLabaledCall() throws Exception { 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 de0f2332942..fc285ce22ea 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 @@ -589,11 +589,17 @@ class BuilderInferenceSession( if (lowerSubstituted == a && upperSubstituted == b) return this + val resultingPosition = if (upperSubstituted == b && position is DeclaredUpperBoundConstraintPosition<*>) { + position + } else { + BuilderInferenceSubstitutionConstraintPositionImpl(lambdaArgument, this) + } + return InitialConstraint( lowerSubstituted, upperSubstituted, constraintKind, - BuilderInferenceSubstitutionConstraintPositionImpl(lambdaArgument, this) + resultingPosition ) } diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/kt47986.kt b/compiler/testData/diagnostics/tests/inference/builderInference/kt47986.kt new file mode 100644 index 00000000000..5544b6bfa77 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/kt47986.kt @@ -0,0 +1,12 @@ +// FIR_IDENTICAL +class Foo + +fun buildFoo(builderAction: Foo.() -> Unit): Foo = Foo() + +fun Foo.bar(x: Int = 1) {} + +fun main() { + val x = buildFoo { + bar() + } +} diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/kt47986.txt b/compiler/testData/diagnostics/tests/inference/builderInference/kt47986.txt new file mode 100644 index 00000000000..e524080b34f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/kt47986.txt @@ -0,0 +1,12 @@ +package + +public fun buildFoo(/*0*/ builderAction: Foo.() -> kotlin.Unit): Foo +public fun main(): kotlin.Unit +public fun Foo.bar(/*0*/ x: kotlin.Int = ...): kotlin.Unit + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/kt47986_2.kt b/compiler/testData/diagnostics/tests/inference/builderInference/kt47986_2.kt new file mode 100644 index 00000000000..a8a7f7f46d1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/kt47986_2.kt @@ -0,0 +1,14 @@ +// FIR_IDENTICAL +class Foo + +fun buildFoo(builderAction: Foo.() -> Unit): Foo = Foo() + +fun Foo.bar() {} + +fun id(x: K) = x + +fun main() { + val x = buildFoo { // can't infer + val y = id(::bar) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/kt47986_2.txt b/compiler/testData/diagnostics/tests/inference/builderInference/kt47986_2.txt new file mode 100644 index 00000000000..9a3f241b665 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/kt47986_2.txt @@ -0,0 +1,13 @@ +package + +public fun buildFoo(/*0*/ builderAction: Foo.() -> kotlin.Unit): Foo +public fun id(/*0*/ x: K): K +public fun main(): kotlin.Unit +public fun Foo.bar(): kotlin.Unit + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/kt47986_3.kt b/compiler/testData/diagnostics/tests/inference/builderInference/kt47986_3.kt new file mode 100644 index 00000000000..e096bb11f3e --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/kt47986_3.kt @@ -0,0 +1,12 @@ +// FIR_IDENTICAL +class Foo + +fun buildFoo(builderAction: Foo.() -> Unit): Foo = Foo() + +fun Foo.bar(x: Int = 1) {} + +fun main() { + val x = buildFoo { + bar() + } +} diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/kt47986_3.txt b/compiler/testData/diagnostics/tests/inference/builderInference/kt47986_3.txt new file mode 100644 index 00000000000..298988be6b1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/kt47986_3.txt @@ -0,0 +1,12 @@ +package + +public fun buildFoo(/*0*/ builderAction: Foo.() -> kotlin.Unit): Foo +public fun main(): kotlin.Unit +public fun Foo.bar(/*0*/ x: kotlin.Int = ...): kotlin.Unit + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/kt47986_4.kt b/compiler/testData/diagnostics/tests/inference/builderInference/kt47986_4.kt new file mode 100644 index 00000000000..9c56154d65a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/kt47986_4.kt @@ -0,0 +1,14 @@ +// FIR_IDENTICAL +class Foo + +fun buildFoo(builderAction: Foo.() -> Unit): Foo = Foo() + +class Bar + +fun , N: Bar> Foo.bar(x: Int = 1) {} + +fun main() { + val x = buildFoo { + bar() + } +} diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/kt47986_4.txt b/compiler/testData/diagnostics/tests/inference/builderInference/kt47986_4.txt new file mode 100644 index 00000000000..23f736d903b --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/kt47986_4.txt @@ -0,0 +1,19 @@ +package + +public fun buildFoo(/*0*/ builderAction: Foo.() -> kotlin.Unit): Foo +public fun main(): kotlin.Unit +public fun , /*1*/ N : Bar> Foo.bar(/*0*/ x: kotlin.Int = ...): kotlin.Unit + +public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/kt51464.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/kt51464.fir.kt new file mode 100644 index 00000000000..47d5840a1e8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/kt51464.fir.kt @@ -0,0 +1,14 @@ +import kotlinx.coroutines.flow.transform + +fun flowOf(value: T): Flow = TODO() + +interface FlowCollector {} + +interface Flow + +fun Flow.transform(transform: FlowCollector.(T) -> Unit): Flow = TODO() + +fun f() { + fun doEmit(collector: FlowCollector) {} + flowOf(1).transform { doEmit(this) } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/kt51464.kt b/compiler/testData/diagnostics/tests/inference/builderInference/kt51464.kt new file mode 100644 index 00000000000..50ede69999f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/kt51464.kt @@ -0,0 +1,12 @@ +fun flowOf(value: T): Flow = TODO() + +interface FlowCollector {} + +interface Flow + +fun Flow.transform(transform: FlowCollector.(T) -> Unit): Flow = TODO() + +fun f() { + fun doEmit(collector: FlowCollector) {} + flowOf(1).transform { doEmit(this) } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/kt51464.txt b/compiler/testData/diagnostics/tests/inference/builderInference/kt51464.txt new file mode 100644 index 00000000000..bacf81a98bc --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/kt51464.txt @@ -0,0 +1,17 @@ +package + +public fun f(): kotlin.Unit +public fun flowOf(/*0*/ value: T): Flow +public fun Flow.transform(/*0*/ transform: FlowCollector.(T) -> kotlin.Unit): Flow + +public interface Flow { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface FlowCollector { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 3284e1f69d5..9338cdc879e 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -14225,6 +14225,30 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47744.kt"); } + @Test + @TestMetadata("kt47986.kt") + public void testKt47986() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47986.kt"); + } + + @Test + @TestMetadata("kt47986_2.kt") + public void testKt47986_2() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47986_2.kt"); + } + + @Test + @TestMetadata("kt47986_3.kt") + public void testKt47986_3() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47986_3.kt"); + } + + @Test + @TestMetadata("kt47986_4.kt") + public void testKt47986_4() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt47986_4.kt"); + } + @Test @TestMetadata("kt49285.kt") public void testKt49285() throws Exception { @@ -14261,6 +14285,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt51148.kt"); } + @Test + @TestMetadata("kt51464.kt") + public void testKt51464() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/kt51464.kt"); + } + @Test @TestMetadata("labaledCall.kt") public void testLabaledCall() throws Exception {