Local delegated properties moved to language feature option
This commit is contained in:
@@ -393,6 +393,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<KtPropertyDelegate> ABSTRACT_DELEGATED_PROPERTY = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtPropertyAccessor> ACCESSOR_FOR_DELEGATED_PROPERTY = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtPropertyDelegate> DELEGATED_PROPERTY_IN_INTERFACE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtPropertyDelegate> LOCAL_VARIABLE_WITH_DELEGATE = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<KtProperty> PROPERTY_WITH_NO_TYPE_NO_INITIALIZER = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
|
||||
|
||||
+1
@@ -217,6 +217,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(ABSTRACT_DELEGATED_PROPERTY, "Delegated property cannot be abstract");
|
||||
MAP.put(ACCESSOR_FOR_DELEGATED_PROPERTY, "Delegated property cannot have accessors with non-default implementations");
|
||||
MAP.put(DELEGATED_PROPERTY_IN_INTERFACE, "Delegated properties are not allowed in interfaces");
|
||||
MAP.put(LOCAL_VARIABLE_WITH_DELEGATE, "Local variables are not allowed to have delegates");
|
||||
|
||||
MAP.put(INAPPLICABLE_LATEINIT_MODIFIER, "''lateinit'' modifier {0}", STRING);
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageFeatureSettings
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
||||
@@ -40,7 +42,8 @@ class LocalVariableResolver(
|
||||
private val dataFlowAnalyzer: DataFlowAnalyzer,
|
||||
private val annotationResolver: AnnotationResolver,
|
||||
private val variableTypeResolver: VariableTypeResolver,
|
||||
private val delegatedPropertyResolver: DelegatedPropertyResolver
|
||||
private val delegatedPropertyResolver: DelegatedPropertyResolver,
|
||||
private val languageFeatureSettings: LanguageFeatureSettings
|
||||
) {
|
||||
|
||||
fun process(
|
||||
@@ -68,13 +71,19 @@ class LocalVariableResolver(
|
||||
val propertyDescriptor = resolveLocalVariableDescriptor(scope, property, context.dataFlowInfo, context.trace)
|
||||
|
||||
val delegateExpression = property.delegateExpression
|
||||
if (delegateExpression != null && propertyDescriptor is VariableDescriptorWithAccessors) {
|
||||
delegatedPropertyResolver.resolvePropertyDelegate(typingContext.dataFlowInfo,
|
||||
property,
|
||||
propertyDescriptor,
|
||||
delegateExpression,
|
||||
typingContext.scope,
|
||||
typingContext.trace);
|
||||
if (delegateExpression != null) {
|
||||
if (!languageFeatureSettings.supportsFeature(LanguageFeature.LocalDelegatedProperties)) {
|
||||
context.trace.report(LOCAL_VARIABLE_WITH_DELEGATE.on(property.delegate!!))
|
||||
}
|
||||
|
||||
if (propertyDescriptor is VariableDescriptorWithAccessors) {
|
||||
delegatedPropertyResolver.resolvePropertyDelegate(typingContext.dataFlowInfo,
|
||||
property,
|
||||
propertyDescriptor,
|
||||
delegateExpression,
|
||||
typingContext.scope,
|
||||
typingContext.trace);
|
||||
}
|
||||
}
|
||||
|
||||
val initializer = property.initializer
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// !LANGUAGE: -LocalDelegatedProperties
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class Delegate {
|
||||
operator fun getValue(t: Any?, p: KProperty<*>): Int = 1
|
||||
}
|
||||
|
||||
fun foo(): Int {
|
||||
val prop: Int <!LOCAL_VARIABLE_WITH_DELEGATE!>by Delegate()<!>
|
||||
|
||||
val prop2: Int <!LOCAL_VARIABLE_WITH_DELEGATE!>by <!DELEGATE_SPECIAL_FUNCTION_MISSING!>123<!><!>
|
||||
|
||||
return prop + prop2
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
public fun foo(): kotlin.Int
|
||||
|
||||
public final class Delegate {
|
||||
public constructor Delegate()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final operator fun getValue(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
// !LANGUAGE: -LocalDelegatedProperties
|
||||
|
||||
// FILE: script.kts
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class Delegate {
|
||||
operator fun getValue(t: Any?, p: KProperty<*>): Int = 1
|
||||
}
|
||||
|
||||
fun foo(): Int {
|
||||
val prop: Int <!LOCAL_VARIABLE_WITH_DELEGATE!>by Delegate()<!>
|
||||
|
||||
val prop2: Int <!LOCAL_VARIABLE_WITH_DELEGATE!>by <!DELEGATE_SPECIAL_FUNCTION_MISSING!>123<!><!>
|
||||
|
||||
return prop + prop2
|
||||
}
|
||||
|
||||
|
||||
val prop: Int by Delegate()
|
||||
|
||||
val prop2: Int by <!DELEGATE_SPECIAL_FUNCTION_MISSING!>123<!>
|
||||
|
||||
prop + prop2
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
package
|
||||
|
||||
public final class Script {
|
||||
public constructor Script(/*0*/ args: kotlin.Array<kotlin.String>)
|
||||
public final val args: kotlin.Array<kotlin.String>
|
||||
public final val prop: kotlin.Int
|
||||
public final val prop2: kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public final class Delegate {
|
||||
public constructor Delegate()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final operator fun getValue(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.reflect.KProperty<*>): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
@@ -18219,6 +18219,18 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/sourceCompatibility"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("noLocalDelegatedProperty.kt")
|
||||
public void testNoLocalDelegatedProperty() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/sourceCompatibility/noLocalDelegatedProperty.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("noLocalDelegatedPropertyInScript.kt")
|
||||
public void testNoLocalDelegatedPropertyInScript() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/sourceCompatibility/noLocalDelegatedPropertyInScript.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("noTopLevelSealedInheritance.kt")
|
||||
public void testNoTopLevelSealedInheritance() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/sourceCompatibility/noTopLevelSealedInheritance.kt");
|
||||
|
||||
Reference in New Issue
Block a user