NI: don't try to infer visible lambda parameters, if there is single one – extension parameter
^KT-37038 Fixed
This commit is contained in:
Generated
+5
@@ -9946,6 +9946,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/expectedTypeWithGenerics.kt");
|
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")
|
@TestMetadata("findViewById.kt")
|
||||||
public void testFindViewById() throws Exception {
|
public void testFindViewById() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/inference/findViewById.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/findViewById.kt");
|
||||||
|
|||||||
+7
-4
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.resolve.calls.inference.components
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.isBuiltinFunctionalType
|
import org.jetbrains.kotlin.builtins.isBuiltinFunctionalType
|
||||||
import org.jetbrains.kotlin.builtins.isBuiltinFunctionalTypeOrSubtype
|
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.components.transformToResolvedLambda
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.*
|
import org.jetbrains.kotlin.resolve.calls.inference.model.*
|
||||||
@@ -172,7 +173,7 @@ class KotlinConstraintSystemCompleter(
|
|||||||
val atomToAnalyze = when (postponedAtom) {
|
val atomToAnalyze = when (postponedAtom) {
|
||||||
is PostponedCallableReferenceAtom -> postponedAtom.preparePostponedAtomWithTypeVariableAsExpectedType(
|
is PostponedCallableReferenceAtom -> postponedAtom.preparePostponedAtomWithTypeVariableAsExpectedType(
|
||||||
c, csBuilder, expectedTypeVariable,
|
c, csBuilder, expectedTypeVariable,
|
||||||
condition = { true },
|
parameterTypes = null,
|
||||||
isSuitable = KotlinType::isBuiltinFunctionalTypeOrSubtype,
|
isSuitable = KotlinType::isBuiltinFunctionalTypeOrSubtype,
|
||||||
typeVariableCreator = { TypeVariableForCallableReferenceReturnType(builtIns, "_Q") },
|
typeVariableCreator = { TypeVariableForCallableReferenceReturnType(builtIns, "_Q") },
|
||||||
newAtomCreator = { returnVariable, expectedType ->
|
newAtomCreator = { returnVariable, expectedType ->
|
||||||
@@ -183,7 +184,7 @@ class KotlinConstraintSystemCompleter(
|
|||||||
)
|
)
|
||||||
is LambdaWithTypeVariableAsExpectedTypeAtom -> postponedAtom.preparePostponedAtomWithTypeVariableAsExpectedType(
|
is LambdaWithTypeVariableAsExpectedTypeAtom -> postponedAtom.preparePostponedAtomWithTypeVariableAsExpectedType(
|
||||||
c, csBuilder, expectedTypeVariable,
|
c, csBuilder, expectedTypeVariable,
|
||||||
condition = { it.atom.parametersTypes?.all { type -> type != null } != true },
|
parameterTypes = postponedAtom.atom.parametersTypes,
|
||||||
isSuitable = KotlinType::isBuiltinFunctionalType,
|
isSuitable = KotlinType::isBuiltinFunctionalType,
|
||||||
typeVariableCreator = { TypeVariableForLambdaReturnType(postponedAtom.atom, builtIns, "_R") },
|
typeVariableCreator = { TypeVariableForLambdaReturnType(postponedAtom.atom, builtIns, "_R") },
|
||||||
newAtomCreator = { returnVariable, expectedType ->
|
newAtomCreator = { returnVariable, expectedType ->
|
||||||
@@ -200,17 +201,19 @@ class KotlinConstraintSystemCompleter(
|
|||||||
c: Context,
|
c: Context,
|
||||||
csBuilder: ConstraintSystemBuilder,
|
csBuilder: ConstraintSystemBuilder,
|
||||||
variable: TypeConstructor,
|
variable: TypeConstructor,
|
||||||
condition: (T) -> Boolean,
|
parameterTypes: Array<out KotlinType?>?,
|
||||||
isSuitable: KotlinType.() -> Boolean,
|
isSuitable: KotlinType.() -> Boolean,
|
||||||
typeVariableCreator: () -> V,
|
typeVariableCreator: () -> V,
|
||||||
newAtomCreator: (V, SimpleType) -> PostponedResolvedAtom
|
newAtomCreator: (V, SimpleType) -> PostponedResolvedAtom
|
||||||
): PostponedResolvedAtom {
|
): PostponedResolvedAtom {
|
||||||
if (!condition(this)) return this
|
|
||||||
val functionalType = resultTypeResolver.findResultType(
|
val functionalType = resultTypeResolver.findResultType(
|
||||||
c,
|
c,
|
||||||
c.notFixedTypeVariables.getValue(variable),
|
c.notFixedTypeVariables.getValue(variable),
|
||||||
TypeVariableDirectionCalculator.ResolveDirection.TO_SUPERTYPE
|
TypeVariableDirectionCalculator.ResolveDirection.TO_SUPERTYPE
|
||||||
) as KotlinType
|
) 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
|
if (!functionalType.isSuitable()) return this
|
||||||
val returnVariable = typeVariableCreator()
|
val returnVariable = typeVariableCreator()
|
||||||
csBuilder.registerVariable(returnVariable)
|
csBuilder.registerVariable(returnVariable)
|
||||||
|
|||||||
+10
@@ -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" }}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_ANONYMOUS_PARAMETER
|
||||||
|
|
||||||
|
fun <T> 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) <!TYPE_MISMATCH!>{{ <!CANNOT_INFER_PARAMETER_TYPE, EXPECTED_PARAMETERS_NUMBER_MISMATCH!>str<!> -> "this" }}<!> else <!TYPE_MISMATCH!>{{ <!CANNOT_INFER_PARAMETER_TYPE, EXPECTED_PARAMETERS_NUMBER_MISMATCH!>str<!> -> "this" }}<!>
|
||||||
|
val x6: String.() -> String = if (true) <!TYPE_MISMATCH!>{{ <!CANNOT_INFER_PARAMETER_TYPE, EXPECTED_PARAMETERS_NUMBER_MISMATCH!>str<!> -> "this" }}<!> else {{ "this" }}
|
||||||
|
val x7: String.() -> String = select({ -> this }, { -> this })
|
||||||
|
val x8: String.() -> String = select({ this }, { this })
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun main(): kotlin.Unit
|
||||||
@@ -9953,6 +9953,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/expectedTypeWithGenerics.kt");
|
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")
|
@TestMetadata("findViewById.kt")
|
||||||
public void testFindViewById() throws Exception {
|
public void testFindViewById() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/inference/findViewById.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/findViewById.kt");
|
||||||
|
|||||||
Generated
+5
@@ -9948,6 +9948,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/expectedTypeWithGenerics.kt");
|
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")
|
@TestMetadata("findViewById.kt")
|
||||||
public void testFindViewById() throws Exception {
|
public void testFindViewById() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/inference/findViewById.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/findViewById.kt");
|
||||||
|
|||||||
+5
-5
@@ -12845,6 +12845,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
public static class InlineClasses extends AbstractLightAnalysisModeTest {
|
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")
|
@TestMetadata("fieldNameClash.kt")
|
||||||
public void ignoreFieldNameClash() throws Exception {
|
public void ignoreFieldNameClash() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/fieldNameClash.kt");
|
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");
|
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")
|
@TestMetadata("boundCallableReferencePassedToInlineFunction.kt")
|
||||||
public void testBoundCallableReferencePassedToInlineFunction() throws Exception {
|
public void testBoundCallableReferencePassedToInlineFunction() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/boundCallableReferencePassedToInlineFunction.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/boundCallableReferencePassedToInlineFunction.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user