Allow to use collection literals only in annotations

This commit is contained in:
Mikhail Zarechenskiy
2017-03-21 03:11:54 +03:00
parent bfe2ddf7c1
commit a2ea518b1a
7 changed files with 40 additions and 3 deletions
@@ -1517,6 +1517,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
public KotlinTypeInfo visitCollectionLiteralExpression(
@NotNull KtCollectionLiteralExpression expression, ExpressionTypingContext context
) {
if (!isInsideAnnotationEntryOrClass(expression)) {
context.trace.report(UNSUPPORTED.on(expression, "Collection literals outside of annotations"));
}
checkSupportsArrayLiterals(expression, context);
return resolveCollectionLiteralSpecialMethod(expression, context);
}
@@ -1,5 +1,5 @@
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_VARIABLE
// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNSUPPORTED
fun test() {
val a = <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>[]<!>
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNSUPPORTED
fun basicTypes() {
val a: IntArray = [1]
@@ -14,5 +14,5 @@ fun test2() {}
fun test3() {}
fun test4() {
[1, 2]
<!UNSUPPORTED!>[1, 2]<!>
}
@@ -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!>[]<!>)
@@ -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");
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")