Inline classes can only implement interfaces
This commit is contained in:
@@ -328,6 +328,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<PsiElement> DELEGATED_PROPERTY_INSIDE_INLINE_CLASS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<KtTypeReference, KotlinType> INLINE_CLASS_HAS_INAPPLICABLE_PARAMETER_TYPE = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INLINE_CLASS_CANNOT_IMPLEMENT_INTERFACE_BY_DELEGATION = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtTypeReference> INLINE_CLASS_CANNOT_EXTEND_CLASSES = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
// Secondary constructors
|
||||
|
||||
|
||||
+1
@@ -657,6 +657,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(DELEGATED_PROPERTY_INSIDE_INLINE_CLASS, "Inline class cannot have delegated properties");
|
||||
MAP.put(INLINE_CLASS_HAS_INAPPLICABLE_PARAMETER_TYPE, "Inline class cannot have value parameter of type ''{0}''", RENDER_TYPE);
|
||||
MAP.put(INLINE_CLASS_CANNOT_IMPLEMENT_INTERFACE_BY_DELEGATION, "Inline class cannot implement an interface by delegation");
|
||||
MAP.put(INLINE_CLASS_CANNOT_EXTEND_CLASSES, "Inline class cannot extend classes");
|
||||
|
||||
MAP.put(VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED, "Variance annotations are only allowed for type parameters of classes and interfaces");
|
||||
MAP.put(BOUND_ON_TYPE_ALIAS_PARAMETER_NOT_ALLOWED, "Bounds are not allowed on type alias parameters");
|
||||
|
||||
+8
@@ -92,6 +92,14 @@ object InlineClassDeclarationChecker : DeclarationChecker {
|
||||
if (supertypeEntry is KtDelegatedSuperTypeEntry) {
|
||||
trace.report(Errors.INLINE_CLASS_CANNOT_IMPLEMENT_INTERFACE_BY_DELEGATION.on(supertypeEntry))
|
||||
return
|
||||
} else {
|
||||
val typeReference = supertypeEntry.typeReference ?: continue
|
||||
val type = trace[BindingContext.TYPE, typeReference] ?: continue
|
||||
val typeDescriptor = type.constructor.declarationDescriptor ?: continue
|
||||
if (!DescriptorUtils.isInterface(typeDescriptor)) {
|
||||
trace.report(Errors.INLINE_CLASS_CANNOT_EXTEND_CLASSES.on(typeReference))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
abstract class AbstractBaseClass
|
||||
|
||||
open class OpenBaseClass
|
||||
|
||||
interface BaseInterface
|
||||
|
||||
inline class TestExtendsAbstractClass(val x: Int) : <!INLINE_CLASS_CANNOT_EXTEND_CLASSES!>AbstractBaseClass<!>()
|
||||
|
||||
inline class TestExtendsOpenClass(val x: Int) : <!INLINE_CLASS_CANNOT_EXTEND_CLASSES!>OpenBaseClass<!>()
|
||||
|
||||
inline class TestImplementsInterface(val x: Int) : BaseInterface
|
||||
Vendored
+45
@@ -0,0 +1,45 @@
|
||||
package
|
||||
|
||||
public abstract class AbstractBaseClass {
|
||||
public constructor AbstractBaseClass()
|
||||
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 interface BaseInterface {
|
||||
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 open class OpenBaseClass {
|
||||
public constructor OpenBaseClass()
|
||||
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 final inline class TestExtendsAbstractClass : AbstractBaseClass {
|
||||
public constructor TestExtendsAbstractClass(/*0*/ x: kotlin.Int)
|
||||
public final val x: kotlin.Int
|
||||
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final inline class TestExtendsOpenClass : OpenBaseClass {
|
||||
public constructor TestExtendsOpenClass(/*0*/ x: kotlin.Int)
|
||||
public final val x: kotlin.Int
|
||||
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final inline class TestImplementsInterface : BaseInterface {
|
||||
public constructor TestImplementsInterface(/*0*/ x: kotlin.Int)
|
||||
public final val x: kotlin.Int
|
||||
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -10867,6 +10867,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
runTest("compiler/testData/diagnostics/tests/inlineClasses/identityComparisonWithInlineClasses.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineClassCanOnlyImplementInterfaces.kt")
|
||||
public void testInlineClassCanOnlyImplementInterfaces() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inlineClasses/inlineClassCanOnlyImplementInterfaces.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineClassCannotImplementInterfaceByDelegation.kt")
|
||||
public void testInlineClassCannotImplementInterfaceByDelegation() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inlineClasses/inlineClassCannotImplementInterfaceByDelegation.kt");
|
||||
|
||||
Generated
+5
@@ -10867,6 +10867,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/inlineClasses/identityComparisonWithInlineClasses.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineClassCanOnlyImplementInterfaces.kt")
|
||||
public void testInlineClassCanOnlyImplementInterfaces() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inlineClasses/inlineClassCanOnlyImplementInterfaces.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineClassCannotImplementInterfaceByDelegation.kt")
|
||||
public void testInlineClassCannotImplementInterfaceByDelegation() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inlineClasses/inlineClassCannotImplementInterfaceByDelegation.kt");
|
||||
|
||||
Reference in New Issue
Block a user