Check modifiers applicability on destructured lambda parameters
#KT-14502 Fixed
This commit is contained in:
@@ -80,6 +80,7 @@ public class DescriptorResolver {
|
||||
private final LanguageVersionSettings languageVersionSettings;
|
||||
private final FunctionsTypingVisitor functionsTypingVisitor;
|
||||
private final DestructuringDeclarationResolver destructuringDeclarationResolver;
|
||||
private final ModifiersChecker modifiersChecker;
|
||||
|
||||
public DescriptorResolver(
|
||||
@NotNull AnnotationResolver annotationResolver,
|
||||
@@ -92,7 +93,8 @@ public class DescriptorResolver {
|
||||
@NotNull OverloadChecker overloadChecker,
|
||||
@NotNull LanguageVersionSettings languageVersionSettings,
|
||||
@NotNull FunctionsTypingVisitor functionsTypingVisitor,
|
||||
@NotNull DestructuringDeclarationResolver destructuringDeclarationResolver
|
||||
@NotNull DestructuringDeclarationResolver destructuringDeclarationResolver,
|
||||
@NotNull ModifiersChecker modifiersChecker
|
||||
) {
|
||||
this.annotationResolver = annotationResolver;
|
||||
this.builtIns = builtIns;
|
||||
@@ -105,6 +107,7 @@ public class DescriptorResolver {
|
||||
this.languageVersionSettings = languageVersionSettings;
|
||||
this.functionsTypingVisitor = functionsTypingVisitor;
|
||||
this.destructuringDeclarationResolver = destructuringDeclarationResolver;
|
||||
this.modifiersChecker = modifiersChecker;
|
||||
}
|
||||
|
||||
public List<KotlinType> resolveSupertypes(
|
||||
@@ -300,6 +303,8 @@ public class DescriptorResolver {
|
||||
scope, destructuringDeclaration, new TransientReceiver(type), /* initializer = */ null,
|
||||
ExpressionTypingContext.newContext(trace, scope, DataFlowInfoFactory.EMPTY, TypeUtils.NO_EXPECTED_TYPE)
|
||||
);
|
||||
|
||||
modifiersChecker.withTrace(trace).checkModifiersForDestructuringDeclaration(destructuringDeclaration);
|
||||
}
|
||||
else {
|
||||
destructuringVariables = null;
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
data class A(val x: Int, val y: String)
|
||||
|
||||
fun foo(block: (A) -> Unit) { }
|
||||
|
||||
@Target(AnnotationTarget.VALUE_PARAMETER)
|
||||
annotation class Ann
|
||||
|
||||
fun bar() {
|
||||
foo { (<!WRONG_MODIFIER_TARGET!>private<!> <!WRONG_MODIFIER_TARGET!>inline<!> a, <!WRONG_ANNOTATION_TARGET!>@Ann<!> b) ->
|
||||
a checkType { _<Int>() }
|
||||
b checkType { _<String>() }
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
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
|
||||
}
|
||||
|
||||
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.VALUE_PARAMETER}) public final annotation class Ann : kotlin.Annotation {
|
||||
public constructor Ann()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -7712,6 +7712,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("modifiers.kt")
|
||||
public void testModifiers() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/modifiers.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("noExpectedType.kt")
|
||||
public void testNoExpectedType() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/noExpectedType.kt");
|
||||
|
||||
Reference in New Issue
Block a user