diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index e62f6a935dc..0106735d7d8 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -9946,6 +9946,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/inference/expectedTypeWithGenerics.kt"); } + @TestMetadata("extensionLambdasAndArrow.kt") + public void testExtensionLambdasAndArrow() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.kt"); + } + @TestMetadata("findViewById.kt") public void testFindViewById() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/findViewById.kt"); diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/KotlinConstraintSystemCompleter.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/KotlinConstraintSystemCompleter.kt index e5de822c5d6..46601ad60bb 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/KotlinConstraintSystemCompleter.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/KotlinConstraintSystemCompleter.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.resolve.calls.inference.components import org.jetbrains.kotlin.builtins.isBuiltinFunctionalType import org.jetbrains.kotlin.builtins.isBuiltinFunctionalTypeOrSubtype +import org.jetbrains.kotlin.builtins.isExtensionFunctionType import org.jetbrains.kotlin.resolve.calls.components.transformToResolvedLambda import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder import org.jetbrains.kotlin.resolve.calls.inference.model.* @@ -172,7 +173,7 @@ class KotlinConstraintSystemCompleter( val atomToAnalyze = when (postponedAtom) { is PostponedCallableReferenceAtom -> postponedAtom.preparePostponedAtomWithTypeVariableAsExpectedType( c, csBuilder, expectedTypeVariable, - condition = { true }, + parameterTypes = null, isSuitable = KotlinType::isBuiltinFunctionalTypeOrSubtype, typeVariableCreator = { TypeVariableForCallableReferenceReturnType(builtIns, "_Q") }, newAtomCreator = { returnVariable, expectedType -> @@ -183,7 +184,7 @@ class KotlinConstraintSystemCompleter( ) is LambdaWithTypeVariableAsExpectedTypeAtom -> postponedAtom.preparePostponedAtomWithTypeVariableAsExpectedType( c, csBuilder, expectedTypeVariable, - condition = { it.atom.parametersTypes?.all { type -> type != null } != true }, + parameterTypes = postponedAtom.atom.parametersTypes, isSuitable = KotlinType::isBuiltinFunctionalType, typeVariableCreator = { TypeVariableForLambdaReturnType(postponedAtom.atom, builtIns, "_R") }, newAtomCreator = { returnVariable, expectedType -> @@ -200,17 +201,19 @@ class KotlinConstraintSystemCompleter( c: Context, csBuilder: ConstraintSystemBuilder, variable: TypeConstructor, - condition: (T) -> Boolean, + parameterTypes: Array?, isSuitable: KotlinType.() -> Boolean, typeVariableCreator: () -> V, newAtomCreator: (V, SimpleType) -> PostponedResolvedAtom ): PostponedResolvedAtom { - if (!condition(this)) return this val functionalType = resultTypeResolver.findResultType( c, c.notFixedTypeVariables.getValue(variable), TypeVariableDirectionCalculator.ResolveDirection.TO_SUPERTYPE ) as KotlinType + val isExtensionWithoutParameters = + functionalType.isExtensionFunctionType && functionalType.arguments.size == 2 && parameterTypes?.isEmpty() == true + if (parameterTypes?.all { type -> type != null } == true && !isExtensionWithoutParameters) return this if (!functionalType.isSuitable()) return this val returnVariable = typeVariableCreator() csBuilder.registerVariable(returnVariable) diff --git a/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.fir.kt b/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.fir.kt new file mode 100644 index 00000000000..4a7820d4273 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.fir.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_ANONYMOUS_PARAMETER + +fun main() { + val x1: String.() -> String = if (true) {{ this }} else {{ this }} + val x2: String.() -> String = if (true) {{ -> this }} else {{ -> this }} + val x3: () -> String = if (true) {{ -> "this" }} else {{ -> "this" }} + val x4: String.() -> String = if (true) {{ str: String -> "this" }} else {{ str: String -> "this" }} + val x5: String.() -> String = if (true) {{ str -> "this" }} else {{ str -> "this" }} + val x6: String.() -> String = if (true) {{ str -> "this" }} else {{ "this" }} +} diff --git a/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.kt b/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.kt new file mode 100644 index 00000000000..1f8163060a5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_ANONYMOUS_PARAMETER + +fun select(vararg x: T) = x[0] + +fun main() { + val x1: String.() -> String = if (true) {{ this }} else {{ this }} + val x2: String.() -> String = if (true) {{ -> this }} else {{ -> this }} + val x3: () -> String = if (true) {{ -> "this" }} else {{ -> "this" }} + val x4: String.() -> String = if (true) {{ str: String -> "this" }} else {{ str: String -> "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 }) + val x8: String.() -> String = select({ this }, { this }) +} diff --git a/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.txt b/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.txt new file mode 100644 index 00000000000..a9fef69810f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.txt @@ -0,0 +1,3 @@ +package + +public fun main(): kotlin.Unit diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index ebc3da54f93..ecc1aa61a08 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -9953,6 +9953,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali runTest("compiler/testData/diagnostics/tests/inference/expectedTypeWithGenerics.kt"); } + @TestMetadata("extensionLambdasAndArrow.kt") + public void testExtensionLambdasAndArrow() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.kt"); + } + @TestMetadata("findViewById.kt") public void testFindViewById() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/findViewById.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 38bee4b8325..e7711db9e30 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -9948,6 +9948,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/inference/expectedTypeWithGenerics.kt"); } + @TestMetadata("extensionLambdasAndArrow.kt") + public void testExtensionLambdasAndArrow() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.kt"); + } + @TestMetadata("findViewById.kt") public void testFindViewById() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/findViewById.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index a01ed915ce1..245cdbd0ff0 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -12845,6 +12845,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public static class InlineClasses extends AbstractLightAnalysisModeTest { + @TestMetadata("anySuperCall.kt") + public void ignoreAnySuperCall() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/anySuperCall.kt"); + } + @TestMetadata("fieldNameClash.kt") public void ignoreFieldNameClash() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/fieldNameClash.kt"); @@ -12873,11 +12878,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inlineClasses/annotatedMemberExtensionProperty.kt"); } - @TestMetadata("anySuperCall.kt") - public void testAnySuperCall() throws Exception { - runTest("compiler/testData/codegen/box/inlineClasses/anySuperCall.kt"); - } - @TestMetadata("boundCallableReferencePassedToInlineFunction.kt") public void testBoundCallableReferencePassedToInlineFunction() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/boundCallableReferencePassedToInlineFunction.kt");