[FE] Inline classes cannot have context receivers
This commit is contained in:
committed by
TeamCityServer
parent
d704862582
commit
1a0aab4a44
+6
@@ -10612,6 +10612,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/noBackingField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noContextReceiversOnInlineClasses.kt")
|
||||
public void testNoContextReceiversOnInlineClasses() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/noContextReceiversOnInlineClasses.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noExplicitReceiver.kt")
|
||||
public void testNoExplicitReceiver() throws Exception {
|
||||
|
||||
@@ -385,6 +385,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<PsiElement> INNER_CLASS_INSIDE_VALUE_CLASS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> VALUE_CLASS_CANNOT_BE_CLONEABLE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INLINE_CLASS_DEPRECATED = DiagnosticFactory0.create(WARNING);
|
||||
DiagnosticFactory0<KtContextReceiverList> INLINE_CLASS_CANNOT_HAVE_CONTEXT_RECEIVERS = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
// Result class
|
||||
|
||||
|
||||
+1
@@ -761,6 +761,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(INNER_CLASS_INSIDE_VALUE_CLASS, "Value class cannot have inner classes");
|
||||
MAP.put(VALUE_CLASS_CANNOT_BE_CLONEABLE, "Value class cannot be Cloneable");
|
||||
MAP.put(INLINE_CLASS_DEPRECATED, "'inline' modifier is deprecated. Use 'value' instead");
|
||||
MAP.put(INLINE_CLASS_CANNOT_HAVE_CONTEXT_RECEIVERS, "Inline classes cannot have context receivers");
|
||||
|
||||
MAP.put(RESULT_CLASS_IN_RETURN_TYPE, "'kotlin.Result' cannot be used as a return type");
|
||||
MAP.put(RESULT_CLASS_WITH_NULLABLE_OPERATOR, "Expression of type 'kotlin.Result' cannot be used as a left operand of ''{0}''", STRING);
|
||||
|
||||
+6
@@ -58,6 +58,12 @@ object InlineClassDeclarationChecker : DeclarationChecker {
|
||||
return
|
||||
}
|
||||
|
||||
if (declaration.contextReceivers.isNotEmpty()) {
|
||||
val contextReceiverList = declaration.getContextReceiverList()
|
||||
requireNotNull(contextReceiverList) { "Declaration cannot have context receivers with no context receiver list" }
|
||||
trace.report(Errors.INLINE_CLASS_CANNOT_HAVE_CONTEXT_RECEIVERS.on(contextReceiverList))
|
||||
}
|
||||
|
||||
val modalityModifier = declaration.modalityModifier()
|
||||
if (modalityModifier != null && descriptor.modality != Modality.FINAL) {
|
||||
trace.report(Errors.VALUE_CLASS_NOT_FINAL.on(modalityModifier))
|
||||
|
||||
@@ -188,6 +188,22 @@ abstract class KtClassOrObject :
|
||||
return parts.joinToString(separator = ".")
|
||||
}
|
||||
|
||||
fun getContextReceiverList(): KtContextReceiverList? {
|
||||
val stub = stub
|
||||
if (stub != null) {
|
||||
return getStubOrPsiChild(KtStubElementTypes.CONTEXT_RECEIVER_LIST)
|
||||
}
|
||||
var node = node.firstChildNode
|
||||
while (node != null) {
|
||||
val tt = node.elementType
|
||||
if (tt === KtNodeTypes.CONTEXT_RECEIVER_LIST) {
|
||||
return node.psi as KtContextReceiverList
|
||||
}
|
||||
node = node.treeNext
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getContextReceivers(): List<KtContextReceiver> {
|
||||
val stub = stub
|
||||
if (stub != null) {
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// !LANGUAGE: +InlineClasses, -JvmInlineValueClasses
|
||||
|
||||
class A
|
||||
|
||||
context(A)
|
||||
inline class B(val x: Int)
|
||||
compiler/testData/diagnostics/tests/extensions/contextReceivers/noContextReceiversOnInlineClasses.kt
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// !LANGUAGE: +InlineClasses, -JvmInlineValueClasses
|
||||
|
||||
class A
|
||||
|
||||
<!INLINE_CLASS_CANNOT_HAVE_CONTEXT_RECEIVERS!>context(A)<!>
|
||||
inline class B(val x: Int)
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
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 B {
|
||||
public constructor B(/*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
|
||||
}
|
||||
Generated
+6
@@ -10618,6 +10618,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/noBackingField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noContextReceiversOnInlineClasses.kt")
|
||||
public void testNoContextReceiversOnInlineClasses() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/noContextReceiversOnInlineClasses.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noExplicitReceiver.kt")
|
||||
public void testNoExplicitReceiver() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user