[FE] Allow declare sealed class inheritors as inner or nested classes
#KT-13495
This commit is contained in:
committed by
TeamCityServer
parent
f5f1984a60
commit
70c61be1ef
@@ -56,6 +56,7 @@ import org.jetbrains.kotlin.util.ReenteringLazyValueComputationException;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static org.jetbrains.kotlin.config.LanguageFeature.FreedomForSealedClasses;
|
||||||
import static org.jetbrains.kotlin.config.LanguageFeature.TopLevelSealedInheritance;
|
import static org.jetbrains.kotlin.config.LanguageFeature.TopLevelSealedInheritance;
|
||||||
import static org.jetbrains.kotlin.diagnostics.Errors.*;
|
import static org.jetbrains.kotlin.diagnostics.Errors.*;
|
||||||
import static org.jetbrains.kotlin.resolve.BindingContext.*;
|
import static org.jetbrains.kotlin.resolve.BindingContext.*;
|
||||||
@@ -635,7 +636,12 @@ public class BodyResolver {
|
|||||||
containingDescriptor = containingDescriptor.getContainingDeclaration();
|
containingDescriptor = containingDescriptor.getContainingDeclaration();
|
||||||
}
|
}
|
||||||
if (containingDescriptor == null) {
|
if (containingDescriptor == null) {
|
||||||
trace.report(SEALED_SUPERTYPE.on(typeReference));
|
if (
|
||||||
|
!languageVersionSettings.supportsFeature(FreedomForSealedClasses) ||
|
||||||
|
DescriptorUtils.isLocal(supertypeOwner)
|
||||||
|
) {
|
||||||
|
trace.report(SEALED_SUPERTYPE.on(typeReference));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
trace.report(SEALED_SUPERTYPE_IN_LOCAL_CLASS.on(typeReference));
|
trace.report(SEALED_SUPERTYPE_IN_LOCAL_CLASS.on(typeReference));
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ class Container {
|
|||||||
class C : <!HIDDEN, SEALED_SUPERTYPE!>Base<!>()
|
class C : <!HIDDEN, SEALED_SUPERTYPE!>Base<!>()
|
||||||
|
|
||||||
inner class D : <!HIDDEN, SEALED_SUPERTYPE!>Base<!>()
|
inner class D : <!HIDDEN, SEALED_SUPERTYPE!>Base<!>()
|
||||||
|
|
||||||
|
val anon = object : <!HIDDEN, SEALED_SUPERTYPE_IN_LOCAL_CLASS!>Base<!>() {} // Should be an error
|
||||||
|
|
||||||
|
fun someFun() {
|
||||||
|
class LocalClass : <!HIDDEN, SEALED_SUPERTYPE_IN_LOCAL_CLASS!>Base<!>() {} // Should be an error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FILE: d.kt
|
// FILE: d.kt
|
||||||
@@ -26,5 +32,7 @@ fun test(base: Base) {
|
|||||||
val x = when (base) {
|
val x = when (base) {
|
||||||
is Base.A -> 1
|
is Base.A -> 1
|
||||||
is B -> 2
|
is B -> 2
|
||||||
|
is Container.C -> 3
|
||||||
|
is Container.D -> 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,15 @@ class B : Base()
|
|||||||
// FILE: c.kt
|
// FILE: c.kt
|
||||||
|
|
||||||
class Container {
|
class Container {
|
||||||
class C : <!SEALED_SUPERTYPE!>Base<!>()
|
class C : Base()
|
||||||
|
|
||||||
inner class D : <!SEALED_SUPERTYPE!>Base<!>()
|
inner class D : Base()
|
||||||
|
|
||||||
|
val anon = object : <!SEALED_SUPERTYPE!>Base<!>() {} // Should be an error
|
||||||
|
|
||||||
|
fun someFun() {
|
||||||
|
class LocalClass : <!SEALED_SUPERTYPE!>Base<!>() {} // Should be an error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FILE: d.kt
|
// FILE: d.kt
|
||||||
@@ -26,5 +32,7 @@ fun test(base: Base) {
|
|||||||
val x = when (base) {
|
val x = when (base) {
|
||||||
is Base.A -> 1
|
is Base.A -> 1
|
||||||
is B -> 2
|
is B -> 2
|
||||||
|
is Container.C -> 3
|
||||||
|
is Container.D -> 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,10 @@ public sealed class Base {
|
|||||||
|
|
||||||
public final class Container {
|
public final class Container {
|
||||||
public constructor Container()
|
public constructor Container()
|
||||||
|
public final val anon: Base
|
||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
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 hashCode(): kotlin.Int
|
||||||
|
public final fun someFun(): kotlin.Unit
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
|
||||||
public final class C : Base {
|
public final class C : Base {
|
||||||
|
|||||||
Reference in New Issue
Block a user