Local interfaces are forbidden now
This commit is contained in:
@@ -246,6 +246,7 @@ public interface Errors {
|
||||
// Objects
|
||||
|
||||
DiagnosticFactory1<JetObjectDeclaration, ClassDescriptor> LOCAL_OBJECT_NOT_ALLOWED = DiagnosticFactory1.create(ERROR, DECLARATION_NAME);
|
||||
DiagnosticFactory1<JetClass, ClassDescriptor> LOCAL_INTERFACE_NOT_ALLOWED = DiagnosticFactory1.create(ERROR, DECLARATION_NAME);
|
||||
|
||||
// Type parameter declarations
|
||||
|
||||
|
||||
+1
@@ -292,6 +292,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(DEPRECATED_SYMBOL_WITH_MESSAGE, "''{0}'' is deprecated. {1}", DEPRECATION_RENDERER, STRING);
|
||||
|
||||
MAP.put(LOCAL_OBJECT_NOT_ALLOWED, "Named object ''{0}'' is a singleton and cannot be local. Try to use anonymous object instead", NAME);
|
||||
MAP.put(LOCAL_INTERFACE_NOT_ALLOWED, "''{0}'' is an interface so it cannot be local. Try to use anonymous object or abstract class instead", NAME);
|
||||
MAP.put(ENUM_CLASS_CONSTRUCTOR_CALL, "Enum types cannot be instantiated");
|
||||
MAP.put(SEALED_CLASS_CONSTRUCTOR_CALL, "Sealed types cannot be instantiated");
|
||||
|
||||
|
||||
@@ -287,6 +287,9 @@ public class DeclarationsChecker {
|
||||
|
||||
if (aClass.isInterface()) {
|
||||
checkConstructorInTrait(aClass);
|
||||
if (aClass.isLocal() && !(classDescriptor.getContainingDeclaration() instanceof ClassDescriptor)) {
|
||||
trace.report(LOCAL_INTERFACE_NOT_ALLOWED.on(aClass, classDescriptor));
|
||||
}
|
||||
}
|
||||
else if (classDescriptor.getKind() == ClassKind.ANNOTATION_CLASS) {
|
||||
checkAnnotationClassWithBody(aClass);
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
interface A : Collection<String>
|
||||
interface B : List<String>
|
||||
interface C : Map<Long, Double>
|
||||
interface D : Map.Entry<Any, Nothing>
|
||||
interface E : Iterator<Int>
|
||||
|
||||
fun box(): String {
|
||||
interface F : A, B, C, D, E
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
interface Interface {
|
||||
fun foo(x: Int): Int
|
||||
}
|
||||
|
||||
fun withLocalClasses(param: Int): Interface {
|
||||
open class LocalBase {
|
||||
open val param: Int
|
||||
get() = 100
|
||||
}
|
||||
|
||||
interface LocalInterface : Interface {
|
||||
override fun foo(x: Int): Int =
|
||||
x + param
|
||||
}
|
||||
|
||||
return object : LocalBase(), LocalInterface {
|
||||
override fun foo(x: Int): Int =
|
||||
x + super.param
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val t = withLocalClasses(1)
|
||||
|
||||
val test1 = t.foo(10)
|
||||
if (test1 != 110) return "Fail: t.foo(10)==$test1"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
fun box(): String {
|
||||
interface L1 {
|
||||
fun foo(): String
|
||||
abstract class L1 {
|
||||
abstract fun foo(): String
|
||||
}
|
||||
|
||||
open class L2(val s: String) : L1 {
|
||||
open class L2(val s: String) : L1() {
|
||||
override fun foo() = s
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
fun box(): String {
|
||||
interface A {
|
||||
fun foo() = "OK"
|
||||
}
|
||||
|
||||
class B : A
|
||||
|
||||
return B().foo()
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
|
||||
fun foo() {
|
||||
<!LOCAL_INTERFACE_NOT_ALLOWED!>interface a<!> {}
|
||||
val b = object {
|
||||
<!NESTED_CLASS_NOT_ALLOWED!>interface c<!> {}
|
||||
}
|
||||
class A {
|
||||
<!NESTED_CLASS_NOT_ALLOWED!>interface d<!> {}
|
||||
}
|
||||
val f = {
|
||||
<!LOCAL_INTERFACE_NOT_ALLOWED!>interface e<!> {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
public fun foo(): kotlin.Unit
|
||||
Vendored
+1
-1
@@ -8,7 +8,7 @@ fun withLocalClasses(param: Int): Interface {
|
||||
get() = 100
|
||||
}
|
||||
|
||||
interface LocalInterface : Interface {
|
||||
<!LOCAL_INTERFACE_NOT_ALLOWED!>interface LocalInterface<!> : Interface {
|
||||
override fun foo(x: Int): Int =
|
||||
x + param
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,6 +7,6 @@ fun foo() {
|
||||
}
|
||||
}
|
||||
|
||||
<!NON_TOPLEVEL_CLASS_DECLARATION!>interface T<!> {
|
||||
<!LOCAL_INTERFACE_NOT_ALLOWED, NON_TOPLEVEL_CLASS_DECLARATION!>interface T<!> {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,6 +325,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("localInterfaces.kt")
|
||||
public void testLocalInterfaces() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/localInterfaces.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("MultilineStringTemplates.kt")
|
||||
public void testMultilineStringTemplates() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/MultilineStringTemplates.kt");
|
||||
|
||||
@@ -92,20 +92,6 @@ public class KotlinSyntheticClassAnnotationTest extends CodegenTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
public void testLocalTraitImpl() {
|
||||
doTestKotlinSyntheticClass(
|
||||
"fun foo() { interface Local { fun bar() = 42 } }",
|
||||
"Local$DefaultImpls.class"
|
||||
);
|
||||
}
|
||||
|
||||
public void testLocalTraitInterface() {
|
||||
doTestKotlinClass(
|
||||
"fun foo() { interface Local { fun bar() = 42 } }",
|
||||
"Local.class"
|
||||
);
|
||||
}
|
||||
|
||||
public void testInnerClassOfLocalClass() {
|
||||
doTestKotlinClass(
|
||||
"fun foo() { class Local { inner class Inner } }",
|
||||
|
||||
-18
@@ -778,12 +778,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("dontGenerateBodyInTrait.kt")
|
||||
public void testDontGenerateBodyInTrait() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/builtinStubMethods/dontGenerateBodyInTrait.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("implementationInTrait.kt")
|
||||
public void testImplementationInTrait() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/builtinStubMethods/implementationInTrait.kt");
|
||||
@@ -7432,12 +7426,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("unqualifiedSuperWithLocalClass.kt")
|
||||
public void testUnqualifiedSuperWithLocalClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/super/unqualifiedSuperWithLocalClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("unqualifiedSuperWithMethodsOfAny.kt")
|
||||
public void testUnqualifiedSuperWithMethodsOfAny() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/super/unqualifiedSuperWithMethodsOfAny.kt");
|
||||
@@ -7681,12 +7669,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt5495.kt")
|
||||
public void testKt5495() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/traits/kt5495.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("multiple.kt")
|
||||
public void testMultiple() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/traits/multiple.kt");
|
||||
|
||||
@@ -23,9 +23,6 @@ fun f() {
|
||||
class MyLocalClass {
|
||||
}
|
||||
|
||||
interface MyLocalTrait {
|
||||
}
|
||||
|
||||
val myAnonymousObject = object {
|
||||
}
|
||||
|
||||
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
fun foo() {
|
||||
open class Z(p: Int)
|
||||
interface T;
|
||||
|
||||
{
|
||||
<selection>class A: Z(1), T</selection>
|
||||
}
|
||||
|
||||
{
|
||||
class B: Z(1), T
|
||||
}
|
||||
|
||||
{
|
||||
class C: Z(1)
|
||||
}
|
||||
|
||||
{
|
||||
class D: Z(2), T
|
||||
}
|
||||
|
||||
{
|
||||
class E: T
|
||||
}
|
||||
}
|
||||
Vendored
-3
@@ -1,3 +0,0 @@
|
||||
class A: Z(1), T
|
||||
|
||||
class B: Z(1), T
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
fun foo() {
|
||||
<selection>{
|
||||
open class Z<T>(p: T)
|
||||
interface T
|
||||
class A: Z<Int>(1), T
|
||||
}</selection>
|
||||
|
||||
{
|
||||
open class Z<A>(r: A)
|
||||
interface T
|
||||
class B: Z<Int>(1), T
|
||||
}
|
||||
|
||||
{
|
||||
open class T<A>(r: A)
|
||||
interface Z
|
||||
class C: T<Int>(1), Z
|
||||
}
|
||||
|
||||
{
|
||||
open class Z<T>(q: T)
|
||||
interface T
|
||||
class D: Z<Int>(2), T
|
||||
}
|
||||
|
||||
{
|
||||
open class Z<T>(q: T)
|
||||
class E: Z<Int>(1)
|
||||
}
|
||||
|
||||
{
|
||||
open class Z<A>(r: A)
|
||||
interface T
|
||||
class F: Z<String>("1"), T
|
||||
}
|
||||
|
||||
{
|
||||
open class Z(r: Int)
|
||||
interface T
|
||||
class B: Z(1), T
|
||||
}
|
||||
}
|
||||
Vendored
-17
@@ -1,17 +0,0 @@
|
||||
{
|
||||
open class Z<T>(p: T)
|
||||
interface T
|
||||
class A: Z<Int>(1), T
|
||||
}
|
||||
|
||||
{
|
||||
open class Z<A>(r: A)
|
||||
interface T
|
||||
class B: Z<Int>(1), T
|
||||
}
|
||||
|
||||
{
|
||||
open class T<A>(r: A)
|
||||
interface Z
|
||||
class C: T<Int>(1), Z
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
fun foo() {
|
||||
open class Z(p: Int)
|
||||
interface T
|
||||
interface U;
|
||||
|
||||
{
|
||||
<selection>class A: Z(1), T, U</selection>
|
||||
}
|
||||
|
||||
{
|
||||
class B: Z(1), U, T
|
||||
}
|
||||
|
||||
{
|
||||
class C: Z(1)
|
||||
}
|
||||
|
||||
{
|
||||
class D: Z(1), T
|
||||
}
|
||||
|
||||
{
|
||||
class E: Z(1), U
|
||||
}
|
||||
}
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
class A: Z(1), T, U
|
||||
|
||||
class B: Z(1), U, T
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun foo() {
|
||||
interface T
|
||||
abstract class T
|
||||
|
||||
<selection>fun bar1<A, B, C>(a: A, b: B, c: C): A where B: A, C: B, C: T = c</selection>
|
||||
|
||||
|
||||
@@ -179,12 +179,6 @@ public class JetPsiUnifierTestGenerated extends AbstractJetPsiUnifierTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("commonSuperclasses.kt")
|
||||
public void testCommonSuperclasses() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/unifier/equivalence/declarations/classesAndObjects/commonSuperclasses.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("delegation.kt")
|
||||
public void testDelegation() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/unifier/equivalence/declarations/classesAndObjects/delegation.kt");
|
||||
@@ -209,23 +203,11 @@ public class JetPsiUnifierTestGenerated extends AbstractJetPsiUnifierTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("matchedSuperclasses.kt")
|
||||
public void testMatchedSuperclasses() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/unifier/equivalence/declarations/classesAndObjects/matchedSuperclasses.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("members.kt")
|
||||
public void testMembers() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/unifier/equivalence/declarations/classesAndObjects/members.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("superTypeOrder.kt")
|
||||
public void testSuperTypeOrder() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/unifier/equivalence/declarations/classesAndObjects/superTypeOrder.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/unifier/equivalence/declarations/localCallables")
|
||||
|
||||
@@ -10,12 +10,12 @@ import bar.*
|
||||
fun localFun() = b
|
||||
fun /*p:local.declarations*/Int.localExtFun() = localFun()
|
||||
|
||||
interface LocalI {
|
||||
var a: /*p:local.declarations*/Int
|
||||
fun foo()
|
||||
abstract class LocalI {
|
||||
abstract var a: /*p:local.declarations*/Int
|
||||
abstract fun foo()
|
||||
}
|
||||
|
||||
class LocalC : LocalI {
|
||||
class LocalC : LocalI() {
|
||||
override var a = 1
|
||||
|
||||
override fun foo() {}
|
||||
|
||||
Reference in New Issue
Block a user