[FE] Prohibit sealed fun interfaces
#KT-44947 Fixed
This commit is contained in:
+6
@@ -24496,6 +24496,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/sealed/interfaces/inheritorInDifferentModule.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("sealedFunInterface.kt")
|
||||
public void testSealedFunInterface() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/sealed/interfaces/sealedFunInterface.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("sealedInterfacesDisabled.kt")
|
||||
public void testSealedInterfacesDisabled() throws Exception {
|
||||
|
||||
+8
-2
@@ -14,10 +14,16 @@ import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
|
||||
object SealedInterfaceAllowedChecker : DeclarationChecker {
|
||||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
|
||||
if (context.languageVersionSettings.supportsFeature(LanguageFeature.SealedInterfaces)) return
|
||||
if (descriptor !is ClassDescriptor) return
|
||||
if (descriptor.kind != ClassKind.INTERFACE) return
|
||||
val keyword = declaration.modifierList?.getModifier(KtTokens.SEALED_KEYWORD) ?: return
|
||||
context.trace.report(Errors.UNSUPPORTED_FEATURE.on(keyword, LanguageFeature.SealedInterfaces to context.languageVersionSettings))
|
||||
val diagnostic = if (context.languageVersionSettings.supportsFeature(LanguageFeature.SealedInterfaces)) {
|
||||
if (descriptor.isFun) {
|
||||
Errors.UNSUPPORTED.on(keyword, "sealed fun interfaces")
|
||||
} else return
|
||||
} else {
|
||||
Errors.UNSUPPORTED_FEATURE.on(keyword, LanguageFeature.SealedInterfaces to context.languageVersionSettings)
|
||||
}
|
||||
context.trace.report(diagnostic)
|
||||
}
|
||||
}
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
sealed fun interface A { // error
|
||||
fun foo()
|
||||
}
|
||||
|
||||
sealed interface Base {
|
||||
sealed fun interface Derived : Base { // error
|
||||
fun foo()
|
||||
}
|
||||
}
|
||||
|
||||
sealed interface IBase {
|
||||
fun interface IDerived : IBase { // OK
|
||||
fun foo()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<!UNSUPPORTED!>sealed<!> fun interface A { // error
|
||||
fun foo()
|
||||
}
|
||||
|
||||
sealed interface Base {
|
||||
<!UNSUPPORTED!>sealed<!> fun interface Derived : Base { // error
|
||||
fun foo()
|
||||
}
|
||||
}
|
||||
|
||||
sealed interface IBase {
|
||||
fun interface IDerived : IBase { // OK
|
||||
fun foo()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package
|
||||
|
||||
public sealed fun interface A {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public sealed interface Base {
|
||||
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
|
||||
|
||||
public sealed fun interface Derived : Base {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
|
||||
public sealed interface IBase {
|
||||
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
|
||||
|
||||
public fun interface IDerived : IBase {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
Generated
+6
@@ -24586,6 +24586,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/sealed/interfaces/inheritorInDifferentModule.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("sealedFunInterface.kt")
|
||||
public void testSealedFunInterface() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/sealed/interfaces/sealedFunInterface.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("sealedInterfacesDisabled.kt")
|
||||
public void testSealedInterfacesDisabled() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user