diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java index ef080be1c66..f5dd8b5e26e 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java @@ -7957,6 +7957,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok runTest("compiler/testData/diagnostics/tests/functionLiterals/functionLiteralWithoutArgumentList.kt"); } + @TestMetadata("genericFunctionalTypeOnRHSOfPlusAssign.kt") + public void testGenericFunctionalTypeOnRHSOfPlusAssign() throws Exception { + runTest("compiler/testData/diagnostics/tests/functionLiterals/genericFunctionalTypeOnRHSOfPlusAssign.kt"); + } + @TestMetadata("higherOrderCallMissingParameters.kt") public void testHigherOrderCallMissingParameters() throws Exception { runTest("compiler/testData/diagnostics/tests/functionLiterals/higherOrderCallMissingParameters.kt"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorForStatements.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorForStatements.java index 891bdd51472..e1c13637c82 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorForStatements.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingVisitorForStatements.java @@ -21,6 +21,7 @@ import kotlin.Pair; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.builtins.KotlinBuiltIns; +import org.jetbrains.kotlin.config.LanguageFeature; import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.diagnostics.Errors; import org.jetbrains.kotlin.lexer.KtTokens; @@ -214,8 +215,9 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito context.trace.report(UNRESOLVED_REFERENCE.on(operationSign, operationSign)); temporary.commit(); return rightInfo.clearType(); - } else if (ArgumentTypeResolver.getFunctionLiteralArgumentIfAny(right, context) == null && - ArgumentTypeResolver.getCallableReferenceExpressionIfAny(right, context) == null) { + } else if (!ArgumentTypeResolver.isFunctionLiteralOrCallableReference(right, context) && + !context.languageVersionSettings.supportsFeature(LanguageFeature.AdditionalBuiltInsMembers) + ) { // Cache the type info for the right hand side so that we don't evaluate it twice if there is no valid plusAssign. // We skip over function literals and references, since ArgumentTypeResolver will only resolve the shape of the // function type before attempting to resolve the call. diff --git a/compiler/testData/diagnostics/tests/functionLiterals/genericFunctionalTypeOnRHSOfPlusAssign.kt b/compiler/testData/diagnostics/tests/functionLiterals/genericFunctionalTypeOnRHSOfPlusAssign.kt new file mode 100644 index 00000000000..6d60bef632b --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/genericFunctionalTypeOnRHSOfPlusAssign.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun Iterable.filter(predicate: (T) -> Boolean): List = TODO() +operator fun Collection.plus(elements: Iterable): List = TODO() + +fun stringCollection(): Collection = TODO() + +fun test(c: Collection) { + var variants = stringCollection() + variants += variants.filter { true } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/genericFunctionalTypeOnRHSOfPlusAssign.txt b/compiler/testData/diagnostics/tests/functionLiterals/genericFunctionalTypeOnRHSOfPlusAssign.txt new file mode 100644 index 00000000000..6b11be1d831 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/genericFunctionalTypeOnRHSOfPlusAssign.txt @@ -0,0 +1,6 @@ +package + +public fun stringCollection(): kotlin.collections.Collection +public fun test(/*0*/ c: kotlin.collections.Collection): kotlin.Unit +public fun kotlin.collections.Iterable.filter(/*0*/ predicate: (T) -> kotlin.Boolean): kotlin.collections.List +public operator fun kotlin.collections.Collection.plus(/*0*/ elements: kotlin.collections.Iterable): kotlin.collections.List diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 20b8d1cff42..85c0e3b05f9 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -7964,6 +7964,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/functionLiterals/functionLiteralWithoutArgumentList.kt"); } + @TestMetadata("genericFunctionalTypeOnRHSOfPlusAssign.kt") + public void testGenericFunctionalTypeOnRHSOfPlusAssign() throws Exception { + runTest("compiler/testData/diagnostics/tests/functionLiterals/genericFunctionalTypeOnRHSOfPlusAssign.kt"); + } + @TestMetadata("higherOrderCallMissingParameters.kt") public void testHigherOrderCallMissingParameters() throws Exception { runTest("compiler/testData/diagnostics/tests/functionLiterals/higherOrderCallMissingParameters.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 692b49e56ca..27faa31d7ec 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -7959,6 +7959,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/functionLiterals/functionLiteralWithoutArgumentList.kt"); } + @TestMetadata("genericFunctionalTypeOnRHSOfPlusAssign.kt") + public void testGenericFunctionalTypeOnRHSOfPlusAssign() throws Exception { + runTest("compiler/testData/diagnostics/tests/functionLiterals/genericFunctionalTypeOnRHSOfPlusAssign.kt"); + } + @TestMetadata("higherOrderCallMissingParameters.kt") public void testHigherOrderCallMissingParameters() throws Exception { runTest("compiler/testData/diagnostics/tests/functionLiterals/higherOrderCallMissingParameters.kt");