diff --git a/compiler/fir/resolve/testData/resolve/companionObjectCall.kt b/compiler/fir/resolve/testData/resolve/companionObjectCall.kt new file mode 100644 index 00000000000..1ee59420868 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/companionObjectCall.kt @@ -0,0 +1,47 @@ +// UNEXPECTED BEHAVIOUR +// Issue: KT-37056 +class A() + +// TESTCASE NUMBER: 1 +fun case1(a: A?) { + val test = a?.let { + + Case1.invoke(it) //resolved to private constructor + + Case1(it) //resolved to private constructor + + Case1(A()) //resolved to private constructor + } + + Case1(A()) //resolved to private constructor + Case1(a = A()) //resolved to private constructor +} + +class Case1 private constructor(val a: String) { + companion object { + operator fun invoke(a: A) = "" + } +} + +// TESTCASE NUMBER: 2 +fun case2(a: A){ + Case2(a) + Case2(a = a) +} + +class Case2 { + companion object { + operator fun invoke(a: A) = "" + } +} + +// TESTCASE NUMBER: 3 +fun case3(a: A){ + Case3.Companion(a) //ok resolved to (2) + Case3.Companion(parameterA = a) //ok resolved to (2) +} +class Case3 { + companion object { + operator fun invoke(parameterA: A) = "" //(2) + } +} \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/companionObjectCall.txt b/compiler/fir/resolve/testData/resolve/companionObjectCall.txt new file mode 100644 index 00000000000..2a874b5cb8b --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/companionObjectCall.txt @@ -0,0 +1,79 @@ +FILE: companionObjectCall.kt + public final class A : R|kotlin/Any| { + public constructor(): R|A| { + super() + } + + } + public final fun case1(a: R|A?|): R|kotlin/Unit| { + lval test: R|kotlin/Nothing?| = R|/a|?.R|kotlin/let|( = let@fun (it: R|A|): R|kotlin/Nothing| { + Q|Case1|.R|/Case1.Companion.invoke|(R|/it|) + #(R|/it|) + ^ #(R|/A.A|()) + } + ) + #(R|/A.A|()) + #(a = R|/A.A|()) + } + public final class Case1 : R|kotlin/Any| { + private constructor(a: R|kotlin/String|): R|Case1| { + super() + } + + public final val a: R|kotlin/String| = R|/a| + public get(): R|kotlin/String| + + public final companion object Companion : R|kotlin/Any| { + private constructor(): R|Case1.Companion| { + super() + } + + public final operator fun invoke(a: R|A|): R|kotlin/String| { + ^invoke String() + } + + } + + } + public final fun case2(a: R|A|): R|kotlin/Unit| { + #(R|/a|) + #(a = R|/a|) + } + public final class Case2 : R|kotlin/Any| { + public constructor(): R|Case2| { + super() + } + + public final companion object Companion : R|kotlin/Any| { + private constructor(): R|Case2.Companion| { + super() + } + + public final operator fun invoke(a: R|A|): R|kotlin/String| { + ^invoke String() + } + + } + + } + public final fun case3(a: R|A|): R|kotlin/Unit| { + Q|Case3|.R|/Case3.Companion|.R|/Case3.Companion.invoke|(R|/a|) + Q|Case3|.R|/Case3.Companion|.R|/Case3.Companion.invoke|(parameterA = R|/a|) + } + public final class Case3 : R|kotlin/Any| { + public constructor(): R|Case3| { + super() + } + + public final companion object Companion : R|kotlin/Any| { + private constructor(): R|Case3.Companion| { + super() + } + + public final operator fun invoke(parameterA: R|A|): R|kotlin/String| { + ^invoke String() + } + + } + + } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index d11e8f8b599..520c073e471 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -48,6 +48,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/resolve/testData/resolve/companion.kt"); } + @TestMetadata("companionObjectCall.kt") + public void testCompanionObjectCall() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/companionObjectCall.kt"); + } + @TestMetadata("companionUsesNested.kt") public void testCompanionUsesNested() throws Exception { runTest("compiler/fir/resolve/testData/resolve/companionUsesNested.kt"); diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index 6126fb37f5a..6bb37555d5d 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -48,6 +48,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/resolve/testData/resolve/companion.kt"); } + @TestMetadata("companionObjectCall.kt") + public void testCompanionObjectCall() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/companionObjectCall.kt"); + } + @TestMetadata("companionUsesNested.kt") public void testCompanionUsesNested() throws Exception { runTest("compiler/fir/resolve/testData/resolve/companionUsesNested.kt");