Nested classes are no more allowed inside any anonymous objects or local classes #KT-13510 Fixed
(cherry picked from commit 5c3ec6c)
This commit is contained in:
committed by
Mikhail Glukhikh
parent
f8039249c6
commit
cd717467f0
@@ -94,7 +94,7 @@ public class ModifiersChecker {
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
if (!(containingDeclaration instanceof ClassDescriptor)) return false;
|
||||
ClassDescriptor containingClass = (ClassDescriptor) containingDeclaration;
|
||||
return containingClass.isInner() || containingClass.getContainingDeclaration() instanceof FunctionDescriptor;
|
||||
return containingClass.isInner() || DescriptorUtils.isLocal(containingClass);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+2
-1
@@ -1,7 +1,8 @@
|
||||
// KT-6026 Exception on instantiating a nested class in an anonymous object
|
||||
|
||||
val oo = object {
|
||||
class Nested
|
||||
// Forbidden in KT-13510
|
||||
<!NESTED_CLASS_NOT_ALLOWED!>class Nested<!>
|
||||
|
||||
fun f1() = Nested(<!TOO_MANY_ARGUMENTS!>11<!>)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
class X {
|
||||
val foo = object {
|
||||
<!NESTED_CLASS_NOT_ALLOWED!>class Foo<!>
|
||||
}
|
||||
|
||||
fun test() {
|
||||
object {
|
||||
<!NESTED_CLASS_NOT_ALLOWED!>class Foo<!>
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package
|
||||
|
||||
public final class X {
|
||||
public constructor X()
|
||||
public final val foo: kotlin.Any
|
||||
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 final fun test(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -12510,6 +12510,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nestedClassInAnonymousObject.kt")
|
||||
public void testNestedClassInAnonymousObject() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/objects/nestedClassInAnonymousObject.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("objectInsideFun.kt")
|
||||
public void testObjectInsideFun() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/objects/objectInsideFun.kt");
|
||||
|
||||
Reference in New Issue
Block a user