[FE] Prohibit property initializers with context receivers
This commit is contained in:
committed by
TeamCityServer
parent
daa54734e5
commit
d704862582
+6
@@ -10606,6 +10606,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/manyReceivers.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noBackingField.kt")
|
||||
public void testNoBackingField() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/noBackingField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noExplicitReceiver.kt")
|
||||
public void testNoExplicitReceiver() throws Exception {
|
||||
|
||||
@@ -606,6 +606,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<KtProperty> UNNECESSARY_LATEINIT = DiagnosticFactory0.create(WARNING, LATEINIT_MODIFIER);
|
||||
|
||||
DiagnosticFactory0<KtExpression> EXTENSION_PROPERTY_WITH_BACKING_FIELD = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtExpression> CONTEXT_RECEIVERS_WITH_BACKING_FIELD = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtExpression> PROPERTY_INITIALIZER_NO_BACKING_FIELD = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtExpression> PROPERTY_INITIALIZER_IN_INTERFACE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtProperty> PRIVATE_PROPERTY_IN_INTERFACE = DiagnosticFactory0.create(ERROR, PRIVATE_MODIFIER);
|
||||
|
||||
+1
@@ -265,6 +265,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(PROPERTY_INITIALIZER_IN_INTERFACE, "Property initializers are not allowed in interfaces");
|
||||
MAP.put(PRIVATE_PROPERTY_IN_INTERFACE, "Abstract property in an interface cannot be private");
|
||||
MAP.put(EXTENSION_PROPERTY_WITH_BACKING_FIELD, "Extension property cannot be initialized because it has no backing field");
|
||||
MAP.put(CONTEXT_RECEIVERS_WITH_BACKING_FIELD, "Property with context receivers cannot be initialized because it has no backing field");
|
||||
MAP.put(PROPERTY_INITIALIZER_NO_BACKING_FIELD, "Initializer is not allowed here because this property has no backing field");
|
||||
MAP.put(ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, "Abstract property ''{0}'' in non-abstract class ''{1}''", STRING, NAME);
|
||||
MAP.put(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, "Abstract function ''{0}'' in non-abstract class ''{1}''", STRING, NAME);
|
||||
|
||||
@@ -713,6 +713,7 @@ class DeclarationsChecker(
|
||||
isExpect -> trace.report(EXPECTED_PROPERTY_INITIALIZER.on(initializer))
|
||||
!backingFieldRequired -> trace.report(PROPERTY_INITIALIZER_NO_BACKING_FIELD.on(initializer))
|
||||
property.receiverTypeReference != null -> trace.report(EXTENSION_PROPERTY_WITH_BACKING_FIELD.on(initializer))
|
||||
property.contextReceivers.isNotEmpty() -> trace.report(CONTEXT_RECEIVERS_WITH_BACKING_FIELD.on(initializer))
|
||||
}
|
||||
} else if (delegate != null) {
|
||||
if (inInterface) {
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
interface A {
|
||||
fun a(): Int
|
||||
}
|
||||
interface B {
|
||||
fun b(): Int
|
||||
}
|
||||
|
||||
context(A)
|
||||
val a = 1
|
||||
|
||||
context(A, B)
|
||||
var b = 2
|
||||
|
||||
context(A, B)
|
||||
val c get() = <!UNRESOLVED_REFERENCE!>a<!>() + <!UNRESOLVED_REFERENCE!>b<!>()
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
interface A {
|
||||
fun a(): Int
|
||||
}
|
||||
interface B {
|
||||
fun b(): Int
|
||||
}
|
||||
|
||||
context(A)
|
||||
val a = <!CONTEXT_RECEIVERS_WITH_BACKING_FIELD!>1<!>
|
||||
|
||||
context(A, B)
|
||||
var b = <!CONTEXT_RECEIVERS_WITH_BACKING_FIELD!>2<!>
|
||||
|
||||
context(A, B)
|
||||
val c get() = a() + b()
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package
|
||||
|
||||
public val a: kotlin.Int = 1
|
||||
public var b: kotlin.Int
|
||||
public val c: kotlin.Int
|
||||
|
||||
public interface A {
|
||||
public abstract fun a(): kotlin.Int
|
||||
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 B {
|
||||
public abstract fun b(): kotlin.Int
|
||||
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
|
||||
}
|
||||
Generated
+6
@@ -10612,6 +10612,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/manyReceivers.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noBackingField.kt")
|
||||
public void testNoBackingField() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/noBackingField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noExplicitReceiver.kt")
|
||||
public void testNoExplicitReceiver() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user