diff --git a/compiler/frontend/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/frontend/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index 86bb5dcbda5..5a63d29bc8a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -27,7 +27,8 @@ enum class LanguageFeature(val sinceVersion: LanguageVersion) { Coroutines(KOTLIN_1_1), AdditionalBuiltInsMembers(KOTLIN_1_1), DataClassInheritance(KOTLIN_1_1), - InlineProperties(KOTLIN_1_1) + InlineProperties(KOTLIN_1_1), + DestructuringLambdaParameters(KOTLIN_1_1), ; companion object { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java index 13026154cac..aa12fd776b2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java @@ -291,6 +291,10 @@ public class DescriptorResolver { List destructuringVariables; if (destructuringDeclaration != null) { + if (!languageVersionSettings.supportsFeature(LanguageFeature.DestructuringLambdaParameters)) { + trace.report(Errors.UNSUPPORTED_FEATURE.on(valueParameter, LanguageFeature.DestructuringLambdaParameters)); + } + destructuringVariables = destructuringDeclarationResolver.resolveLocalVariablesFromDestructuringDeclaration( scope, destructuringDeclaration, new TransientReceiver(type), /* initializer = */ null, ExpressionTypingContext.newContext(trace, scope, DataFlowInfoFactory.EMPTY, TypeUtils.NO_EXPECTED_TYPE) diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unsupportedFeature.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unsupportedFeature.kt new file mode 100644 index 00000000000..12927b9cdc1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unsupportedFeature.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: -DestructuringLambdaParameters +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_PARAMETER +data class A(val x: Int, val y: String) + +fun foo(block: (A) -> Unit) { } + +fun bar() { + foo { (a, b) -> + a checkType { _() } + b checkType { _() } + } +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unsupportedFeature.txt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unsupportedFeature.txt new file mode 100644 index 00000000000..9ddbb77f5c6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unsupportedFeature.txt @@ -0,0 +1,16 @@ +package + +public fun bar(): kotlin.Unit +public fun foo(/*0*/ block: (A) -> kotlin.Unit): kotlin.Unit + +public final data class A { + public constructor A(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.String) + public final val x: kotlin.Int + public final val y: kotlin.String + public final operator /*synthesized*/ fun component1(): kotlin.Int + public final operator /*synthesized*/ fun component2(): kotlin.String + public final /*synthesized*/ fun copy(/*0*/ x: kotlin.Int = ..., /*1*/ y: kotlin.String = ...): A + public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 35c3988e518..fb02ce60a9a 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -7519,6 +7519,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/simple.kt"); doTest(fileName); } + + @TestMetadata("unsupportedFeature.kt") + public void testUnsupportedFeature() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unsupportedFeature.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/diagnostics/tests/functionLiterals/return")