From 33dcbaac16dc6bee384ef560872f8ed5695423bd Mon Sep 17 00:00:00 2001 From: "Denis.Zharkov" Date: Tue, 29 Nov 2022 13:54:07 +0100 Subject: [PATCH] K2: Change resolution rules of when/if expressions with expected type When expected type is known, use it as expected type for branch bodies. While it indeed becomes different from the usual select call resolution, where expected type is applied only after completion starts, it helps to support, e.g. callable references resolution just as powerful as it was in K1. Also, in some cases where diagnostics have been changed, they become a bit more helpful since they are reported closer to the problematic places cannotCastToFunction.kt test has been removed because it relied on the case erroneously supported by the hack removed from the FirCallResolver in this commit. ^KT-45989 Fixed ^KT-55936 Fixed ^KT-56445 Fixed ^KT-54709 Related ^KT-55931 Related --- ...CompilerTestFE10TestdataTestGenerated.java | 12 ++++++++ ...irOldFrontendDiagnosticsTestGenerated.java | 12 ++++++++ ...DiagnosticsWithLightTreeTestGenerated.java | 12 ++++++++ .../FirBlackBoxCodegenTestGenerated.java | 6 ---- .../jetbrains/kotlin/fir/FirCallResolver.kt | 12 -------- ...ControlFlowStatementsResolveTransformer.kt | 8 ++++- .../codegen/box/fir/cannotCastToFunction.kt | 22 -------------- .../adaptationByExpectTypeOutsideCall.fir.kt | 30 +++++++++++++++++++ .../adaptationByExpectTypeOutsideCall.kt | 30 +++++++++++++++++++ .../adapted/adaptationInWhenWithMapOf.kt | 14 +++++++++ .../adapted/noKFunctionForAdaptation.fir.kt | 2 +- .../ifElseIntersection.fir.kt | 2 +- .../specialConstructsAndPlatformTypes.fir.kt | 4 +-- .../tests/functionLiterals/kt56138.fir.kt | 4 +-- .../diagnostics/tests/generics/kt53656.fir.kt | 2 +- .../conversionLastStatementInLambda.fir.kt | 10 +++---- .../conversionLastStatementInLambda.kt | 4 +-- .../inference/coercionToUnit/kt30242.fir.kt | 2 +- .../inference/extensionLambdasAndArrow.fir.kt | 2 +- ...lCallWithMaterializeAndExpectedType.fir.kt | 7 ----- ...ecialCallWithMaterializeAndExpectedType.kt | 1 + .../diagnostics/tests/when/kt9929.fir.kt | 8 ++--- .../diagnostics/tests/when/kt9972.fir.kt | 8 ++--- .../when/whenAndLambdaWithExpectedType.fir.kt | 5 ++-- .../test/runners/DiagnosticTestGenerated.java | 12 ++++++++ .../IrBlackBoxCodegenTestGenerated.java | 6 ---- 26 files changed, 156 insertions(+), 81 deletions(-) delete mode 100644 compiler/testData/codegen/box/fir/cannotCastToFunction.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/adapted/adaptationByExpectTypeOutsideCall.fir.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/adapted/adaptationByExpectTypeOutsideCall.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/adapted/adaptationInWhenWithMapOf.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.fir.kt 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 4b552610d25..b231510df52 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 @@ -3106,6 +3106,18 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag @TestMetadata("compiler/testData/diagnostics/tests/callableReference/adapted") @TestDataPath("$PROJECT_ROOT") public class Adapted { + @Test + @TestMetadata("adaptationByExpectTypeOutsideCall.kt") + public void testAdaptationByExpectTypeOutsideCall() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/adapted/adaptationByExpectTypeOutsideCall.kt"); + } + + @Test + @TestMetadata("adaptationInWhenWithMapOf.kt") + public void testAdaptationInWhenWithMapOf() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/adapted/adaptationInWhenWithMapOf.kt"); + } + @Test public void testAllFilesPresentInAdapted() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/callableReference/adapted"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); 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 c5164b4bce0..3ac14a19342 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 @@ -3112,6 +3112,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti @TestMetadata("compiler/testData/diagnostics/tests/callableReference/adapted") @TestDataPath("$PROJECT_ROOT") public class Adapted { + @Test + @TestMetadata("adaptationByExpectTypeOutsideCall.kt") + public void testAdaptationByExpectTypeOutsideCall() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/adapted/adaptationByExpectTypeOutsideCall.kt"); + } + + @Test + @TestMetadata("adaptationInWhenWithMapOf.kt") + public void testAdaptationInWhenWithMapOf() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/adapted/adaptationInWhenWithMapOf.kt"); + } + @Test public void testAllFilesPresentInAdapted() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/callableReference/adapted"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); 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 c6eb59bd4e5..d062af2bba8 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 @@ -3106,6 +3106,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac @TestMetadata("compiler/testData/diagnostics/tests/callableReference/adapted") @TestDataPath("$PROJECT_ROOT") public class Adapted { + @Test + @TestMetadata("adaptationByExpectTypeOutsideCall.kt") + public void testAdaptationByExpectTypeOutsideCall() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/adapted/adaptationByExpectTypeOutsideCall.kt"); + } + + @Test + @TestMetadata("adaptationInWhenWithMapOf.kt") + public void testAdaptationInWhenWithMapOf() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/adapted/adaptationInWhenWithMapOf.kt"); + } + @Test public void testAllFilesPresentInAdapted() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/callableReference/adapted"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 58387997112..7d19f82a003 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -18337,12 +18337,6 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/fir/callableReferenceToStaticFunction.kt"); } - @Test - @TestMetadata("cannotCastToFunction.kt") - public void testCannotCastToFunction() throws Exception { - runTest("compiler/testData/codegen/box/fir/cannotCastToFunction.kt"); - } - @Test @TestMetadata("cannotCastToFunctionInIf.kt") public void testCannotCastToFunctionInIf() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt index 42206d21366..aa0a8a239c4 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt @@ -407,18 +407,6 @@ class FirCallResolver( } val chosenCandidate = reducedCandidates.single() - if (!resolvedCallableReferenceAtom.hasBeenPostponed && - expectedType is ConeTypeVariableType && - chosenCandidate.symbol.fir.let { func -> - func is FirSimpleFunction && func.valueParameters.any { param -> - param.defaultValue != null - } - } - ) { - resolvedCallableReferenceAtom.hasBeenPostponed = true - return applicability to true - } - constraintSystemBuilder.runTransaction { chosenCandidate.outerConstraintBuilderEffect!!(this) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirControlFlowStatementsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirControlFlowStatementsResolveTransformer.kt index 2d3d6f41fa3..b6763e1b199 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirControlFlowStatementsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirControlFlowStatementsResolveTransformer.kt @@ -74,7 +74,13 @@ class FirControlFlowStatementsResolveTransformer(transformer: FirAbstractBodyRes // when with one branch cannot be completed if it's not already complete in the first place } else -> { - whenExpression = whenExpression.transformBranches(transformer, ResolutionMode.ContextDependent) + whenExpression = whenExpression.transformBranches( + transformer, + data.takeIf { + val expectedType = it.expectedType + expectedType != null && expectedType !is FirImplicitTypeRef + } ?: ResolutionMode.ContextDependent, + ) whenExpression = syntheticCallGenerator.generateCalleeForWhenExpression(whenExpression, resolutionContext) ?: run { whenExpression = whenExpression.transformSingle(whenExhaustivenessTransformer, null) diff --git a/compiler/testData/codegen/box/fir/cannotCastToFunction.kt b/compiler/testData/codegen/box/fir/cannotCastToFunction.kt deleted file mode 100644 index ff80ba14927..00000000000 --- a/compiler/testData/codegen/box/fir/cannotCastToFunction.kt +++ /dev/null @@ -1,22 +0,0 @@ -// TARGET_BACKEND: JVM_IR -// IGNORE_BACKEND_K1: JVM_IR - -open class IrElement - -fun IrElement.dumpKotlinLike(options: String = ""): String = "O" - -fun IrElement.dump(normalizeNames: Boolean = false, stableOrder: Boolean = false): String = "K" - -fun select(flag: Boolean, a: T, b: T): T = - if (flag) a else b - -fun dump(data: IrElement, dumpStrategy: String): String { - // Note: K1 reports TYPE_MISMATCH here (see also cannotCastToFunctionInIf.kt working both in K1/K2) - val dump: IrElement.() -> String = select(dumpStrategy == "KotlinLike", IrElement::dumpKotlinLike, IrElement::dump) - return data.dump() -} - -fun box(): String { - val element = IrElement() - return dump(element, "KotlinLike") + dump(element, "OtherStrategy") -} diff --git a/compiler/testData/diagnostics/tests/callableReference/adapted/adaptationByExpectTypeOutsideCall.fir.kt b/compiler/testData/diagnostics/tests/callableReference/adapted/adaptationByExpectTypeOutsideCall.fir.kt new file mode 100644 index 00000000000..5b1ec176079 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/adapted/adaptationByExpectTypeOutsideCall.fir.kt @@ -0,0 +1,30 @@ +// SKIP_TXT +fun baz(options: String = ""): String = "" +fun bar(normalizeNames: Boolean = false): String = "" + +fun select(x: E, y: E) = x +fun id(e: E): E = e + +fun runForString(x: () -> String) {} + +val cs: CharSequence = "" + +fun foo(dumpStrategy: String) { + val dump0: () -> String = ::baz // TYPE_MISMATCH + val dump1: () -> String = id(::baz) // TYPE_MISMATCH + // OK, TYPE_MISMATCH IN K2 + val dump2: () -> String = if (dumpStrategy == "KotlinLike") ::baz else ::bar + val dump3: () -> String = select(::baz, ::bar) // TYPE_MISMATCH + + var dump4: () -> String = if (dumpStrategy == "KotlinLike") ::baz else ::bar + dump4.invoke() + dump4 = if (dumpStrategy == "KotlinLike") ::baz else ::bar + + var dump5: () -> CharSequence = { cs } + expectString(dump5.invoke()) + dump5 = if (dumpStrategy == "KotlinLike") ::baz else ::bar + // `dump5` should have smart cast to () -> String + expectString(dump5.invoke()) +} + +fun expectString(x: String) {} diff --git a/compiler/testData/diagnostics/tests/callableReference/adapted/adaptationByExpectTypeOutsideCall.kt b/compiler/testData/diagnostics/tests/callableReference/adapted/adaptationByExpectTypeOutsideCall.kt new file mode 100644 index 00000000000..669141773a5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/adapted/adaptationByExpectTypeOutsideCall.kt @@ -0,0 +1,30 @@ +// SKIP_TXT +fun baz(options: String = ""): String = "" +fun bar(normalizeNames: Boolean = false): String = "" + +fun select(x: E, y: E) = x +fun id(e: E): E = e + +fun runForString(x: () -> String) {} + +val cs: CharSequence = "" + +fun foo(dumpStrategy: String) { + val dump0: () -> String = ::baz // TYPE_MISMATCH + val dump1: () -> String = id(::baz) // TYPE_MISMATCH + // OK, TYPE_MISMATCH IN K2 + val dump2: () -> String = if (dumpStrategy == "KotlinLike") ::baz else ::bar + val dump3: () -> String = select(::baz, ::bar) // TYPE_MISMATCH + + var dump4: () -> String = if (dumpStrategy == "KotlinLike") ::baz else ::bar + dump4.invoke() + dump4 = if (dumpStrategy == "KotlinLike") ::baz else ::bar + + var dump5: () -> CharSequence = { cs } + expectString(dump5.invoke()) + dump5 = if (dumpStrategy == "KotlinLike") ::baz else ::bar + // `dump5` should have smart cast to () -> String + expectString(dump5.invoke()) +} + +fun expectString(x: String) {} diff --git a/compiler/testData/diagnostics/tests/callableReference/adapted/adaptationInWhenWithMapOf.kt b/compiler/testData/diagnostics/tests/callableReference/adapted/adaptationInWhenWithMapOf.kt new file mode 100644 index 00000000000..3302e08d02e --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/adapted/adaptationInWhenWithMapOf.kt @@ -0,0 +1,14 @@ +// FIR_IDENTICAL +// SKIP_TXT +// WITH_STDLIB +// ISSUE: KT-56445 + +fun foo(x: Int?, y: Int = 1) {} +fun bar() {} + +fun test() { + mapOf( // String, KFunction + "a" to ::foo, + "b" to ::bar, + ) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/adapted/noKFunctionForAdaptation.fir.kt b/compiler/testData/diagnostics/tests/callableReference/adapted/noKFunctionForAdaptation.fir.kt index 33e6272e914..0cf63308253 100644 --- a/compiler/testData/diagnostics/tests/callableReference/adapted/noKFunctionForAdaptation.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/adapted/noKFunctionForAdaptation.fir.kt @@ -10,7 +10,7 @@ fun dump(dumpStrategy: String) { val f0: Function0 = returnAdapter(::foo) val f1: Function0 = ::foo - val f2: Function0 = if (dumpStrategy == "KotlinLike") ::foo else ::bar + val f2: Function0 = if (dumpStrategy == "KotlinLike") ::foo else ::bar } fun returnAdapter(a: kotlin.reflect.KFunction0) = a diff --git a/compiler/testData/diagnostics/tests/controlStructures/ifElseIntersection.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/ifElseIntersection.fir.kt index ba8d25dc29a..bc955bc78e2 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/ifElseIntersection.fir.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/ifElseIntersection.fir.kt @@ -26,7 +26,7 @@ fun bind2(r: Option): Option { fun bind3(r: Option): Option { return if (r is Some) { // Diagnoses an error correctly - if (true) None() else r + if (true) None() else r } else r } diff --git a/compiler/testData/diagnostics/tests/controlStructures/specialConstructsAndPlatformTypes.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/specialConstructsAndPlatformTypes.fir.kt index c41c7dd1439..f0e6fc7ae31 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/specialConstructsAndPlatformTypes.fir.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/specialConstructsAndPlatformTypes.fir.kt @@ -29,11 +29,11 @@ val testSafeCall4: String? = J.m[""]?.let { it.toString() } val testIf1: String = if (true) J.s else J.s val testIf2: String? = if (true) J.s else J.s -val testIf3: String = if (true) J.m[""] else J.m[""] +val testIf3: String = if (true) J.m[""] else J.m[""] val testIf4: String? = if (true) J.m[""] else J.m[""] val testWhen1: String = when { else -> J.s } val testWhen2: String? = when { else -> J.s } -val testWhen3: String = when { else -> J.m[""] } +val testWhen3: String = when { else -> J.m[""] } val testWhen4: String? = when { else -> J.m[""] } diff --git a/compiler/testData/diagnostics/tests/functionLiterals/kt56138.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/kt56138.fir.kt index a2a0e904dec..153260195e0 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/kt56138.fir.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/kt56138.fir.kt @@ -30,8 +30,8 @@ fun test_3(b: Boolean) { } val x3: String.() -> String = if (b) { - { x -> "x" } + { x -> "x" } } else { - { x -> "x" } + { x -> "x" } } } diff --git a/compiler/testData/diagnostics/tests/generics/kt53656.fir.kt b/compiler/testData/diagnostics/tests/generics/kt53656.fir.kt index bb429822a01..d8858e99ac8 100644 --- a/compiler/testData/diagnostics/tests/generics/kt53656.fir.kt +++ b/compiler/testData/diagnostics/tests/generics/kt53656.fir.kt @@ -5,7 +5,7 @@ interface Entity abstract class SecuredEntity(val entity: E) where E : Entity, E : SecurityCodeAware<*,*> interface SecurityCodeAware> where E : Entity, E : SecurityCodeAware fun > SecurityCodeAware.secured() : R where E : Entity, E : SecurityCodeAware = when(this) { - is Order -> SecuredOrder(this) + is Order -> SecuredOrder(this) else -> null!! } class Order : Entity diff --git a/compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambda.fir.kt b/compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambda.fir.kt index 7aa57a311c0..815b69bdd8e 100644 --- a/compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambda.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambda.fir.kt @@ -1,5 +1,5 @@ // SKIP_TXT -// ISSUE: KT-55729 +// ISSUE: KT-55729, KT-55931, KT-55936 fun main(b: Boolean) { callWithLambda { @@ -9,16 +9,16 @@ fun main(b: Boolean) { callWithLambda { // Unit conversion should work (for K2 see KT-55936) - if (b) ::test1 else ::test2 + if (b) ::test1 else ::test2 } callWithLambda { - // That hasn't been working ever in K1 nor K2 - if (b) { + // Doesn't work in K1, but does in K2 (see KT-55931) + if (b) { ::test1 } else { ::test2 - } + } } callWithLambda { diff --git a/compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambda.kt b/compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambda.kt index cf436ad4f03..c5129aefdef 100644 --- a/compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambda.kt +++ b/compiler/testData/diagnostics/tests/inference/callableReferences/conversionLastStatementInLambda.kt @@ -1,5 +1,5 @@ // SKIP_TXT -// ISSUE: KT-55729 +// ISSUE: KT-55729, KT-55931, KT-55936 fun main(b: Boolean) { callWithLambda { @@ -13,7 +13,7 @@ fun main(b: Boolean) { } callWithLambda { - // That hasn't been working ever in K1 nor K2 + // Doesn't work in K1, but does in K2 (see KT-55931) if (b) { ::test1 } else { diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/kt30242.fir.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/kt30242.fir.kt index 7919750eacd..ebd632abde3 100644 --- a/compiler/testData/diagnostics/tests/inference/coercionToUnit/kt30242.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/kt30242.fir.kt @@ -48,7 +48,7 @@ fun bar(block: () -> String) {} fun test_5(b: Boolean) { bar { if (b) { - println("meh") + println("meh") } } } diff --git a/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.fir.kt b/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.fir.kt index 52b6b6cd38b..7f163d1b549 100644 --- a/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.fir.kt @@ -8,7 +8,7 @@ fun main() { val x3: () -> String = if (true) {{ -> "this" }} else {{ -> "this" }} val x4: String.() -> String = if (true) {{ str: String -> "this" }} else {{ str: String -> "this" }} val x41: String.(String) -> String = if (true) {{ str: String, str2: String -> "this" }} else {{ str: String, str2: String -> "this" }} - val x42: String.(String) -> String = if (true) {{ str, str2 -> "this" }} else {{ str, str2 -> "this" }} + val x42: String.(String) -> String = if (true) {{ str, str2 -> "this" }} else {{ str, str2 -> "this" }} val x5: String.() -> String = if (true) {{ str -> "this" }} else {{ str -> "this" }} val x6: String.() -> String = if (true) {{ str -> "this" }} else {{ "this" }} val x7: String.() -> String = select({ -> this }, { -> this }) diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.fir.kt deleted file mode 100644 index 9a6d6b72fc1..00000000000 --- a/compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.fir.kt +++ /dev/null @@ -1,7 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_VARIABLE - -fun foo() { - val s: String? = if (true) materialize() else null -} - -fun materialize(): K = TODO() diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.kt b/compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.kt index e52674c522d..57c9839179b 100644 --- a/compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.kt +++ b/compiler/testData/diagnostics/tests/inference/nothingType/specialCallWithMaterializeAndExpectedType.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_VARIABLE fun foo() { diff --git a/compiler/testData/diagnostics/tests/when/kt9929.fir.kt b/compiler/testData/diagnostics/tests/when/kt9929.fir.kt index e88d4f36ec5..1b0d08a2db3 100644 --- a/compiler/testData/diagnostics/tests/when/kt9929.fir.kt +++ b/compiler/testData/diagnostics/tests/when/kt9929.fir.kt @@ -1,9 +1,9 @@ -val test: Int = if (true) { - when (2) { +val test: Int = if (true) { + when (2) { 1 -> 1 else -> null - } + } } else { 2 -} +} diff --git a/compiler/testData/diagnostics/tests/when/kt9972.fir.kt b/compiler/testData/diagnostics/tests/when/kt9972.fir.kt index defc2e4fe83..84fdfb84adf 100644 --- a/compiler/testData/diagnostics/tests/when/kt9972.fir.kt +++ b/compiler/testData/diagnostics/tests/when/kt9972.fir.kt @@ -11,17 +11,17 @@ fun test1(): Int { val x: String = if (true) { - when { - true -> Any() + when { + true -> Any() else -> null - } + } } else "" return x.hashCode() } fun test2(): Int { val x: String = when { - true -> Any() + true -> Any() else -> null } ?: return 0 return x.hashCode() diff --git a/compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.fir.kt b/compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.fir.kt index 939e379cccf..45a2c4589cc 100644 --- a/compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.fir.kt +++ b/compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.fir.kt @@ -28,8 +28,7 @@ val test3: (String) -> Boolean = } val test4: (String) -> Boolean = - when { + when { true -> { s1, s2 -> true } else -> null!! - } - + } 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 830658ef427..4072b774ad4 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 @@ -3112,6 +3112,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { @TestMetadata("compiler/testData/diagnostics/tests/callableReference/adapted") @TestDataPath("$PROJECT_ROOT") public class Adapted { + @Test + @TestMetadata("adaptationByExpectTypeOutsideCall.kt") + public void testAdaptationByExpectTypeOutsideCall() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/adapted/adaptationByExpectTypeOutsideCall.kt"); + } + + @Test + @TestMetadata("adaptationInWhenWithMapOf.kt") + public void testAdaptationInWhenWithMapOf() throws Exception { + runTest("compiler/testData/diagnostics/tests/callableReference/adapted/adaptationInWhenWithMapOf.kt"); + } + @Test public void testAllFilesPresentInAdapted() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/callableReference/adapted"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index a2f3516ac18..7e86d21702d 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -18337,12 +18337,6 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/fir/callableReferenceToStaticFunction.kt"); } - @Test - @TestMetadata("cannotCastToFunction.kt") - public void testCannotCastToFunction() throws Exception { - runTest("compiler/testData/codegen/box/fir/cannotCastToFunction.kt"); - } - @Test @TestMetadata("cannotCastToFunctionInIf.kt") public void testCannotCastToFunctionInIf() throws Exception {