Allow to use collection literals only in annotations
This commit is contained in:
+4
@@ -1517,6 +1517,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
public KotlinTypeInfo visitCollectionLiteralExpression(
|
public KotlinTypeInfo visitCollectionLiteralExpression(
|
||||||
@NotNull KtCollectionLiteralExpression expression, ExpressionTypingContext context
|
@NotNull KtCollectionLiteralExpression expression, ExpressionTypingContext context
|
||||||
) {
|
) {
|
||||||
|
if (!isInsideAnnotationEntryOrClass(expression)) {
|
||||||
|
context.trace.report(UNSUPPORTED.on(expression, "Collection literals outside of annotations"));
|
||||||
|
}
|
||||||
|
|
||||||
checkSupportsArrayLiterals(expression, context);
|
checkSupportsArrayLiterals(expression, context);
|
||||||
return resolveCollectionLiteralSpecialMethod(expression, context);
|
return resolveCollectionLiteralSpecialMethod(expression, context);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
// !CHECK_TYPE
|
// !CHECK_TYPE
|
||||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNSUPPORTED
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
val a = <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>[]<!>
|
val a = <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>[]<!>
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNSUPPORTED
|
||||||
|
|
||||||
fun basicTypes() {
|
fun basicTypes() {
|
||||||
val a: IntArray = [1]
|
val a: IntArray = [1]
|
||||||
|
|||||||
Vendored
+1
-1
@@ -14,5 +14,5 @@ fun test2() {}
|
|||||||
fun test3() {}
|
fun test3() {}
|
||||||
|
|
||||||
fun test4() {
|
fun test4() {
|
||||||
[1, 2]
|
<!UNSUPPORTED!>[1, 2]<!>
|
||||||
}
|
}
|
||||||
|
|||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
fun test(): Array<Int> {
|
||||||
|
<!UNSUPPORTED!>[1, 2]<!>
|
||||||
|
<!UNSUPPORTED!>[1, 2]<!>[0]
|
||||||
|
<!UNSUPPORTED!>[1, 2]<!>.get(0)
|
||||||
|
|
||||||
|
foo(<!UNSUPPORTED!>[""]<!>)
|
||||||
|
|
||||||
|
val <!UNUSED_VARIABLE!>p<!> = <!UNSUPPORTED!>[1, 2]<!> <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>+<!> <!UNSUPPORTED!>[3, 4]<!>
|
||||||
|
|
||||||
|
return <!UNSUPPORTED!>[1, 2]<!>
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo(<!UNUSED_PARAMETER!>a<!>: Array<String> = <!UNSUPPORTED!>[""]<!>) {}
|
||||||
|
|
||||||
|
class A(val a: Array<Int> = <!UNSUPPORTED!>[]<!>)
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun foo(/*0*/ a: kotlin.Array<kotlin.String> = ...): kotlin.Unit
|
||||||
|
public fun test(): kotlin.Array<kotlin.Int>
|
||||||
|
|
||||||
|
public final class A {
|
||||||
|
public constructor A(/*0*/ a: kotlin.Array<kotlin.Int> = ...)
|
||||||
|
public final val a: kotlin.Array<kotlin.Int>
|
||||||
|
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
|
||||||
|
}
|
||||||
@@ -3381,6 +3381,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/collectionLiterals/noArrayLiteralsInAnnotationsFeature.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/collectionLiterals/noArrayLiteralsInAnnotationsFeature.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noCollectionLiterals.kt")
|
||||||
|
public void testNoCollectionLiterals() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/collectionLiterals/noCollectionLiterals.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/diagnostics/tests/constructorConsistency")
|
@TestMetadata("compiler/testData/diagnostics/tests/constructorConsistency")
|
||||||
|
|||||||
Reference in New Issue
Block a user