Support platform/impl modifiers for properties
Do not allow platform properties to have backing fields, initializers, be delegated, lateinit or const, or have accessors with bodies
This commit is contained in:
+2
-1
@@ -77,7 +77,8 @@ public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implem
|
|||||||
) {
|
) {
|
||||||
super(containingDeclaration, null, Annotations.Companion.getEMPTY(), Modality.FINAL, Visibilities.LOCAL,
|
super(containingDeclaration, null, Annotations.Companion.getEMPTY(), Modality.FINAL, Visibilities.LOCAL,
|
||||||
original.isVar(), Name.identifier("access$" + nameSuffix),
|
original.isVar(), Name.identifier("access$" + nameSuffix),
|
||||||
Kind.DECLARATION, SourceElement.NO_SOURCE, /* lateInit = */ false, /* isConst = */ false);
|
Kind.DECLARATION, SourceElement.NO_SOURCE, /* lateInit = */ false, /* isConst = */ false,
|
||||||
|
/* isPlatform = */ false, /* isImpl = */ false);
|
||||||
|
|
||||||
this.calleeDescriptor = original;
|
this.calleeDescriptor = original;
|
||||||
this.superCallTarget = superCallTarget;
|
this.superCallTarget = superCallTarget;
|
||||||
|
|||||||
+4
-3
@@ -278,9 +278,10 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
|
|||||||
name: Name,
|
name: Name,
|
||||||
kind: CallableMemberDescriptor.Kind,
|
kind: CallableMemberDescriptor.Kind,
|
||||||
source: SourceElement
|
source: SourceElement
|
||||||
) : SyntheticJavaPropertyDescriptor, PropertyDescriptorImpl(containingDeclaration, original, annotations,
|
) : SyntheticJavaPropertyDescriptor, PropertyDescriptorImpl(
|
||||||
modality, visibility, isVar, name, kind, source,
|
containingDeclaration, original, annotations, modality, visibility, isVar, name, kind, source,
|
||||||
/* lateInit = */ false, /* isConst = */ false) {
|
/* lateInit = */ false, /* isConst = */ false, /* isPlatform = */ false, /* isImpl = */ false
|
||||||
|
) {
|
||||||
|
|
||||||
override var getMethod: FunctionDescriptor by Delegates.notNull()
|
override var getMethod: FunctionDescriptor by Delegates.notNull()
|
||||||
private set
|
private set
|
||||||
|
|||||||
@@ -494,6 +494,8 @@ public interface Errors {
|
|||||||
DiagnosticFactory0<KtDeclaration> PLATFORM_DECLARATION_WITH_BODY = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
DiagnosticFactory0<KtDeclaration> PLATFORM_DECLARATION_WITH_BODY = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||||
DiagnosticFactory0<KtParameter> PLATFORM_DECLARATION_WITH_DEFAULT_PARAMETER = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<KtParameter> PLATFORM_DECLARATION_WITH_DEFAULT_PARAMETER = DiagnosticFactory0.create(ERROR);
|
||||||
|
|
||||||
|
DiagnosticFactory0<KtExpression> PLATFORM_PROPERTY_INITIALIZER = DiagnosticFactory0.create(ERROR);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Errors/warnings inside code blocks
|
// Errors/warnings inside code blocks
|
||||||
|
|||||||
+2
@@ -260,6 +260,8 @@ public class DefaultErrorMessages {
|
|||||||
MAP.put(PLATFORM_DECLARATION_WITH_BODY, "Platform declaration must not have a body");
|
MAP.put(PLATFORM_DECLARATION_WITH_BODY, "Platform declaration must not have a body");
|
||||||
MAP.put(PLATFORM_DECLARATION_WITH_DEFAULT_PARAMETER, "Platform declaration cannot have parameters with default values");
|
MAP.put(PLATFORM_DECLARATION_WITH_DEFAULT_PARAMETER, "Platform declaration cannot have parameters with default values");
|
||||||
|
|
||||||
|
MAP.put(PLATFORM_PROPERTY_INITIALIZER, "Platform property cannot have an initializer");
|
||||||
|
|
||||||
MAP.put(PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT, "Projections are not allowed on type arguments of functions and properties");
|
MAP.put(PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT, "Projections are not allowed on type arguments of functions and properties");
|
||||||
MAP.put(SUPERTYPE_NOT_INITIALIZED, "This type has a constructor, and thus must be initialized here");
|
MAP.put(SUPERTYPE_NOT_INITIALIZED, "This type has a constructor, and thus must be initialized here");
|
||||||
MAP.put(NOTHING_TO_OVERRIDE, "''{0}'' overrides nothing", NAME);
|
MAP.put(NOTHING_TO_OVERRIDE, "''{0}'' overrides nothing", NAME);
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.kotlin.resolve
|
package org.jetbrains.kotlin.resolve
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet
|
import com.google.common.collect.ImmutableSet
|
||||||
import com.google.common.collect.Sets
|
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||||
@@ -650,17 +649,19 @@ class DeclarationsChecker(
|
|||||||
|
|
||||||
val initializer = property.initializer
|
val initializer = property.initializer
|
||||||
val delegate = property.delegate
|
val delegate = property.delegate
|
||||||
|
val isPlatform = propertyDescriptor.isPlatform
|
||||||
if (initializer != null) {
|
if (initializer != null) {
|
||||||
if (inTrait) {
|
if (inTrait) {
|
||||||
trace.report(PROPERTY_INITIALIZER_IN_INTERFACE.on(initializer))
|
trace.report(PROPERTY_INITIALIZER_IN_INTERFACE.on(initializer))
|
||||||
}
|
}
|
||||||
else {
|
else if (isPlatform) {
|
||||||
if (!backingFieldRequired) {
|
trace.report(PLATFORM_PROPERTY_INITIALIZER.on(initializer))
|
||||||
trace.report(PROPERTY_INITIALIZER_NO_BACKING_FIELD.on(initializer))
|
}
|
||||||
}
|
else if (!backingFieldRequired) {
|
||||||
else if (property.receiverTypeReference != null) {
|
trace.report(PROPERTY_INITIALIZER_NO_BACKING_FIELD.on(initializer))
|
||||||
trace.report(EXTENSION_PROPERTY_WITH_BACKING_FIELD.on(initializer))
|
}
|
||||||
}
|
else if (property.receiverTypeReference != null) {
|
||||||
|
trace.report(EXTENSION_PROPERTY_WITH_BACKING_FIELD.on(initializer))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (delegate != null) {
|
else if (delegate != null) {
|
||||||
@@ -670,7 +671,7 @@ class DeclarationsChecker(
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val isUninitialized = trace.bindingContext.get(BindingContext.IS_UNINITIALIZED, propertyDescriptor) ?: false
|
val isUninitialized = trace.bindingContext.get(BindingContext.IS_UNINITIALIZED, propertyDescriptor) ?: false
|
||||||
if (backingFieldRequired && !inTrait && !propertyDescriptor.isLateInit && isUninitialized) {
|
if (backingFieldRequired && !inTrait && !propertyDescriptor.isLateInit && !isPlatform && isUninitialized) {
|
||||||
if (containingDeclaration !is ClassDescriptor || hasAccessorImplementation) {
|
if (containingDeclaration !is ClassDescriptor || hasAccessorImplementation) {
|
||||||
trace.report(MUST_BE_INITIALIZED.on(property))
|
trace.report(MUST_BE_INITIALIZED.on(property))
|
||||||
}
|
}
|
||||||
@@ -681,11 +682,9 @@ class DeclarationsChecker(
|
|||||||
else if (noExplicitTypeOrGetterType(property)) {
|
else if (noExplicitTypeOrGetterType(property)) {
|
||||||
trace.report(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER.on(property))
|
trace.report(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER.on(property))
|
||||||
}
|
}
|
||||||
if (backingFieldRequired && !inTrait && propertyDescriptor.isLateInit && !isUninitialized) {
|
if (backingFieldRequired && !inTrait && propertyDescriptor.isLateInit && !isUninitialized &&
|
||||||
if (trace[MUST_BE_LATEINIT, propertyDescriptor] ?: false) {}
|
trace[MUST_BE_LATEINIT, propertyDescriptor] != true) {
|
||||||
else {
|
trace.report(UNNECESSARY_LATEINIT.on(property))
|
||||||
trace.report(UNNECESSARY_LATEINIT.on(property))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -800,11 +799,18 @@ class DeclarationsChecker(
|
|||||||
private fun checkAccessor(
|
private fun checkAccessor(
|
||||||
propertyDescriptor: PropertyDescriptor,
|
propertyDescriptor: PropertyDescriptor,
|
||||||
accessor: KtPropertyAccessor?,
|
accessor: KtPropertyAccessor?,
|
||||||
accessorDescriptor: PropertyAccessorDescriptor?) {
|
accessorDescriptor: PropertyAccessorDescriptor?
|
||||||
|
) {
|
||||||
if (accessor == null || accessorDescriptor == null) return
|
if (accessor == null || accessorDescriptor == null) return
|
||||||
|
if (propertyDescriptor.isPlatform && accessor.hasBody()) {
|
||||||
|
trace.report(PLATFORM_DECLARATION_WITH_BODY.on(accessor))
|
||||||
|
}
|
||||||
|
|
||||||
val accessorModifierList = accessor.modifierList ?: return
|
val accessorModifierList = accessor.modifierList ?: return
|
||||||
val tokens = modifiersChecker.getTokensCorrespondingToModifiers(accessorModifierList,
|
val tokens = modifiersChecker.getTokensCorrespondingToModifiers(
|
||||||
Sets.newHashSet(KtTokens.PUBLIC_KEYWORD, KtTokens.PROTECTED_KEYWORD, KtTokens.PRIVATE_KEYWORD, KtTokens.INTERNAL_KEYWORD))
|
accessorModifierList,
|
||||||
|
setOf(KtTokens.PUBLIC_KEYWORD, KtTokens.PROTECTED_KEYWORD, KtTokens.PRIVATE_KEYWORD, KtTokens.INTERNAL_KEYWORD)
|
||||||
|
)
|
||||||
if (accessor.isGetter) {
|
if (accessor.isGetter) {
|
||||||
if (accessorDescriptor.visibility != propertyDescriptor.visibility) {
|
if (accessorDescriptor.visibility != propertyDescriptor.visibility) {
|
||||||
reportVisibilityModifierDiagnostics(tokens.values, Errors.GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY)
|
reportVisibilityModifierDiagnostics(tokens.values, Errors.GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY)
|
||||||
|
|||||||
@@ -808,7 +808,10 @@ public class DescriptorResolver {
|
|||||||
CallableMemberDescriptor.Kind.DECLARATION,
|
CallableMemberDescriptor.Kind.DECLARATION,
|
||||||
KotlinSourceElementKt.toSourceElement(property),
|
KotlinSourceElementKt.toSourceElement(property),
|
||||||
modifierList != null && modifierList.hasModifier(KtTokens.LATEINIT_KEYWORD),
|
modifierList != null && modifierList.hasModifier(KtTokens.LATEINIT_KEYWORD),
|
||||||
modifierList != null && modifierList.hasModifier(KtTokens.CONST_KEYWORD)
|
modifierList != null && modifierList.hasModifier(KtTokens.CONST_KEYWORD),
|
||||||
|
modifierList != null && modifierList.hasModifier(KtTokens.PLATFORM_KEYWORD) ||
|
||||||
|
containingDeclaration instanceof ClassDescriptor && ((ClassDescriptor) containingDeclaration).isPlatform(),
|
||||||
|
modifierList != null && modifierList.hasModifier(KtTokens.IMPL_KEYWORD)
|
||||||
);
|
);
|
||||||
wrapper.setDescriptor(propertyDescriptor);
|
wrapper.setDescriptor(propertyDescriptor);
|
||||||
|
|
||||||
@@ -1123,7 +1126,9 @@ public class DescriptorResolver {
|
|||||||
CallableMemberDescriptor.Kind.DECLARATION,
|
CallableMemberDescriptor.Kind.DECLARATION,
|
||||||
KotlinSourceElementKt.toSourceElement(parameter),
|
KotlinSourceElementKt.toSourceElement(parameter),
|
||||||
/* lateInit = */ false,
|
/* lateInit = */ false,
|
||||||
/* isConst = */ false
|
/* isConst = */ false,
|
||||||
|
/* isPlatform = */ false,
|
||||||
|
/* isImpl = */ false
|
||||||
);
|
);
|
||||||
propertyWrapper.setDescriptor(propertyDescriptor);
|
propertyWrapper.setDescriptor(propertyDescriptor);
|
||||||
propertyDescriptor.setType(type, Collections.<TypeParameterDescriptor>emptyList(),
|
propertyDescriptor.setType(type, Collections.<TypeParameterDescriptor>emptyList(),
|
||||||
|
|||||||
@@ -85,14 +85,14 @@ class LocalVariableResolver(
|
|||||||
propertyDescriptor,
|
propertyDescriptor,
|
||||||
delegateExpression,
|
delegateExpression,
|
||||||
typingContext.scope,
|
typingContext.scope,
|
||||||
typingContext.trace);
|
typingContext.trace)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val initializer = property.initializer
|
val initializer = property.initializer
|
||||||
var typeInfo: KotlinTypeInfo
|
var typeInfo: KotlinTypeInfo
|
||||||
if (initializer != null) {
|
if (initializer != null) {
|
||||||
val outType = propertyDescriptor.getType()
|
val outType = propertyDescriptor.type
|
||||||
typeInfo = facade.getTypeInfo(initializer, context.replaceExpectedType(outType))
|
typeInfo = facade.getTypeInfo(initializer, context.replaceExpectedType(outType))
|
||||||
val dataFlowInfo = typeInfo.dataFlowInfo
|
val dataFlowInfo = typeInfo.dataFlowInfo
|
||||||
val type = typeInfo.type
|
val type = typeInfo.type
|
||||||
@@ -146,7 +146,9 @@ class LocalVariableResolver(
|
|||||||
CallableMemberDescriptor.Kind.DECLARATION,
|
CallableMemberDescriptor.Kind.DECLARATION,
|
||||||
variable.toSourceElement(),
|
variable.toSourceElement(),
|
||||||
/* lateInit = */ false,
|
/* lateInit = */ false,
|
||||||
/* isConst = */ false
|
/* isConst = */ false,
|
||||||
|
/* isPlatform = */ false,
|
||||||
|
/* isImpl = */ false
|
||||||
)
|
)
|
||||||
// For a local variable the type must not be deferred
|
// For a local variable the type must not be deferred
|
||||||
type = variableTypeAndInitializerResolver.resolveType(propertyDescriptor, scope, variable, dataFlowInfo, trace, local = true)
|
type = variableTypeAndInitializerResolver.resolveType(propertyDescriptor, scope, variable, dataFlowInfo, trace, local = true)
|
||||||
|
|||||||
@@ -90,8 +90,8 @@ object ModifierCheckerCore {
|
|||||||
CONST_KEYWORD to EnumSet.of(MEMBER_PROPERTY, TOP_LEVEL_PROPERTY),
|
CONST_KEYWORD to EnumSet.of(MEMBER_PROPERTY, TOP_LEVEL_PROPERTY),
|
||||||
OPERATOR_KEYWORD to EnumSet.of(FUNCTION),
|
OPERATOR_KEYWORD to EnumSet.of(FUNCTION),
|
||||||
INFIX_KEYWORD to EnumSet.of(FUNCTION),
|
INFIX_KEYWORD to EnumSet.of(FUNCTION),
|
||||||
PLATFORM_KEYWORD to EnumSet.of(FUNCTION, CLASS_ONLY, OBJECT, INTERFACE, INNER_CLASS, ENUM_CLASS, ANNOTATION_CLASS), // TODO
|
PLATFORM_KEYWORD to EnumSet.of(FUNCTION, TOP_LEVEL_PROPERTY_WITHOUT_FIELD_OR_DELEGATE, CLASS_ONLY, OBJECT, INTERFACE, INNER_CLASS, ENUM_CLASS, ANNOTATION_CLASS), // TODO
|
||||||
IMPL_KEYWORD to EnumSet.of(FUNCTION, CLASS_ONLY, OBJECT, INTERFACE, INNER_CLASS, ENUM_CLASS, ANNOTATION_CLASS) // TODO
|
IMPL_KEYWORD to EnumSet.of(FUNCTION, TOP_LEVEL_PROPERTY_WITHOUT_FIELD_OR_DELEGATE, CLASS_ONLY, OBJECT, INTERFACE, INNER_CLASS, ENUM_CLASS, ANNOTATION_CLASS) // TODO
|
||||||
)
|
)
|
||||||
|
|
||||||
val featureDependencies = mapOf(
|
val featureDependencies = mapOf(
|
||||||
|
|||||||
@@ -97,7 +97,9 @@ class DynamicCallableDescriptors(storageManager: StorageManager, builtIns: Kotli
|
|||||||
CallableMemberDescriptor.Kind.DECLARATION,
|
CallableMemberDescriptor.Kind.DECLARATION,
|
||||||
SourceElement.NO_SOURCE,
|
SourceElement.NO_SOURCE,
|
||||||
/* lateInit = */ false,
|
/* lateInit = */ false,
|
||||||
/* isConst = */ false
|
/* isConst = */ false,
|
||||||
|
/* isPlatform = */ false,
|
||||||
|
/* isImpl = */ false
|
||||||
)
|
)
|
||||||
propertyDescriptor.setType(
|
propertyDescriptor.setType(
|
||||||
dynamicType,
|
dynamicType,
|
||||||
|
|||||||
+8
-8
@@ -20,10 +20,8 @@ import org.jetbrains.kotlin.descriptors.*
|
|||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl
|
||||||
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
||||||
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.org.objectweb.asm.commons.Method
|
|
||||||
|
|
||||||
interface JvmDescriptorWithExtraFlags {
|
interface JvmDescriptorWithExtraFlags {
|
||||||
val extraFlags: Int
|
val extraFlags: Int
|
||||||
@@ -41,10 +39,12 @@ class JvmPropertyDescriptorImpl(
|
|||||||
kind: CallableMemberDescriptor.Kind,
|
kind: CallableMemberDescriptor.Kind,
|
||||||
source: SourceElement,
|
source: SourceElement,
|
||||||
isLateInit: Boolean,
|
isLateInit: Boolean,
|
||||||
isConst: Boolean
|
isConst: Boolean,
|
||||||
|
isPlatform: Boolean,
|
||||||
|
isImpl: Boolean
|
||||||
) : JvmDescriptorWithExtraFlags, PropertyDescriptorImpl(
|
) : JvmDescriptorWithExtraFlags, PropertyDescriptorImpl(
|
||||||
containingDeclaration, original, annotations, modality, visibility, isVar,
|
containingDeclaration, original, annotations, modality, visibility, isVar,
|
||||||
name, kind, source, isLateInit, isConst
|
name, kind, source, isLateInit, isConst, isPlatform, isImpl
|
||||||
) {
|
) {
|
||||||
override fun createSubstitutedCopy(
|
override fun createSubstitutedCopy(
|
||||||
newOwner: DeclarationDescriptor,
|
newOwner: DeclarationDescriptor,
|
||||||
@@ -55,7 +55,7 @@ class JvmPropertyDescriptorImpl(
|
|||||||
): PropertyDescriptorImpl =
|
): PropertyDescriptorImpl =
|
||||||
JvmPropertyDescriptorImpl(
|
JvmPropertyDescriptorImpl(
|
||||||
newOwner, original, annotations, newModality, newVisibility, extraFlags, isVar, name, kind,
|
newOwner, original, annotations, newModality, newVisibility, extraFlags, isVar, name, kind,
|
||||||
SourceElement.NO_SOURCE, isLateInit, isConst
|
SourceElement.NO_SOURCE, isLateInit, isConst, isPlatform, isImpl
|
||||||
)
|
)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -71,7 +71,7 @@ class JvmPropertyDescriptorImpl(
|
|||||||
): PropertyDescriptorImpl =
|
): PropertyDescriptorImpl =
|
||||||
JvmPropertyDescriptorImpl(
|
JvmPropertyDescriptorImpl(
|
||||||
containingDeclaration, null, annotations, modality, visibility, extraFlags, false, name,
|
containingDeclaration, null, annotations, modality, visibility, extraFlags, false, name,
|
||||||
CallableMemberDescriptor.Kind.SYNTHESIZED, source, false, false
|
CallableMemberDescriptor.Kind.SYNTHESIZED, source, false, false, false, false
|
||||||
).initialize(type)
|
).initialize(type)
|
||||||
|
|
||||||
fun createFinalField(
|
fun createFinalField(
|
||||||
@@ -85,7 +85,7 @@ class JvmPropertyDescriptorImpl(
|
|||||||
): PropertyDescriptorImpl =
|
): PropertyDescriptorImpl =
|
||||||
JvmPropertyDescriptorImpl(
|
JvmPropertyDescriptorImpl(
|
||||||
classDescriptor, null, annotations, Modality.FINAL, visibility, extraFlags, false, name,
|
classDescriptor, null, annotations, Modality.FINAL, visibility, extraFlags, false, name,
|
||||||
CallableMemberDescriptor.Kind.SYNTHESIZED, source, false, false
|
CallableMemberDescriptor.Kind.SYNTHESIZED, source, false, false, false, false
|
||||||
).initialize(type, dispatchReceiverParameter = classDescriptor.thisAsReceiverParameter)
|
).initialize(type, dispatchReceiverParameter = classDescriptor.thisAsReceiverParameter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,4 +108,4 @@ class JvmFunctionDescriptorImpl(
|
|||||||
SourceElement.NO_SOURCE, extraFlags
|
SourceElement.NO_SOURCE, extraFlags
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -59,7 +59,7 @@ class JvmSharedVariablesManager(val builtIns: KotlinBuiltIns) : SharedVariablesM
|
|||||||
PropertyDescriptorImpl.create(
|
PropertyDescriptorImpl.create(
|
||||||
refClass, Annotations.EMPTY, Modality.FINAL, Visibilities.PUBLIC, true,
|
refClass, Annotations.EMPTY, Modality.FINAL, Visibilities.PUBLIC, true,
|
||||||
Name.identifier("element"), CallableMemberDescriptor.Kind.DECLARATION, SourceElement.NO_SOURCE,
|
Name.identifier("element"), CallableMemberDescriptor.Kind.DECLARATION, SourceElement.NO_SOURCE,
|
||||||
false, false
|
false, false, false, false
|
||||||
).initialize(type, dispatchReceiverParameter = refClass.thisAsReceiverParameter)
|
).initialize(type, dispatchReceiverParameter = refClass.thisAsReceiverParameter)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ class JvmSharedVariablesManager(val builtIns: KotlinBuiltIns) : SharedVariablesM
|
|||||||
PropertyDescriptorImpl.create(
|
PropertyDescriptorImpl.create(
|
||||||
genericRefClass, Annotations.EMPTY, Modality.FINAL, Visibilities.PUBLIC, true,
|
genericRefClass, Annotations.EMPTY, Modality.FINAL, Visibilities.PUBLIC, true,
|
||||||
Name.identifier("element"), CallableMemberDescriptor.Kind.DECLARATION, SourceElement.NO_SOURCE,
|
Name.identifier("element"), CallableMemberDescriptor.Kind.DECLARATION, SourceElement.NO_SOURCE,
|
||||||
false, false
|
false, false, false, false
|
||||||
).initialize(
|
).initialize(
|
||||||
type = builtIns.anyType,
|
type = builtIns.anyType,
|
||||||
dispatchReceiverParameter = genericRefClass.thisAsReceiverParameter
|
dispatchReceiverParameter = genericRefClass.thisAsReceiverParameter
|
||||||
|
|||||||
+1
-1
@@ -128,7 +128,7 @@ class SpecialDescriptorsFactory(
|
|||||||
objectDescriptor,
|
objectDescriptor,
|
||||||
Annotations.EMPTY, Modality.FINAL, Visibilities.PUBLIC, false,
|
Annotations.EMPTY, Modality.FINAL, Visibilities.PUBLIC, false,
|
||||||
Name.identifier("INSTANCE"),
|
Name.identifier("INSTANCE"),
|
||||||
CallableMemberDescriptor.Kind.SYNTHESIZED, SourceElement.NO_SOURCE, false, false
|
CallableMemberDescriptor.Kind.SYNTHESIZED, SourceElement.NO_SOURCE, false, false, false, false
|
||||||
).initialize(objectDescriptor.defaultType)
|
).initialize(objectDescriptor.defaultType)
|
||||||
|
|
||||||
return instanceFieldDescriptor
|
return instanceFieldDescriptor
|
||||||
|
|||||||
@@ -50,16 +50,18 @@ abstract class IrDelegateDescriptorBase(
|
|||||||
delegateType: KotlinType
|
delegateType: KotlinType
|
||||||
) : PropertyDescriptorImpl(
|
) : PropertyDescriptorImpl(
|
||||||
containingDeclaration,
|
containingDeclaration,
|
||||||
null, // original
|
/* original = */ null,
|
||||||
Annotations.EMPTY,
|
Annotations.EMPTY,
|
||||||
Modality.FINAL,
|
Modality.FINAL,
|
||||||
Visibilities.PRIVATE,
|
Visibilities.PRIVATE,
|
||||||
false, // isVar
|
/* isVar = */ false,
|
||||||
name,
|
name,
|
||||||
CallableMemberDescriptor.Kind.SYNTHESIZED,
|
CallableMemberDescriptor.Kind.SYNTHESIZED,
|
||||||
SourceElement.NO_SOURCE,
|
SourceElement.NO_SOURCE,
|
||||||
false, // lateInit
|
/* lateInit = */ false,
|
||||||
false // isConst
|
/* isConst = */ false,
|
||||||
|
/* isPlatform = */ false,
|
||||||
|
/* isImpl = */ false
|
||||||
) {
|
) {
|
||||||
init {
|
init {
|
||||||
setOutType(delegateType)
|
setOutType(delegateType)
|
||||||
|
|||||||
Vendored
+40
@@ -0,0 +1,40 @@
|
|||||||
|
// !LANGUAGE: +MultiPlatformProjects
|
||||||
|
// MODULE: m1-common
|
||||||
|
// FILE: common.kt
|
||||||
|
|
||||||
|
platform val justVal: String
|
||||||
|
platform var justVar: String
|
||||||
|
|
||||||
|
platform val String.extensionVal: Unit
|
||||||
|
platform var <T> T.genericExtensionVar: T
|
||||||
|
|
||||||
|
platform val valWithGet: String
|
||||||
|
get
|
||||||
|
platform var varWithGetSet: String
|
||||||
|
get set
|
||||||
|
|
||||||
|
platform var varWithPlatformGetSet: String
|
||||||
|
<!WRONG_MODIFIER_TARGET!>platform<!> get
|
||||||
|
<!WRONG_MODIFIER_TARGET!>platform<!> set
|
||||||
|
|
||||||
|
platform val backingFieldVal: String = <!PLATFORM_PROPERTY_INITIALIZER!>"no"<!>
|
||||||
|
platform var backingFieldVar: String = <!PLATFORM_PROPERTY_INITIALIZER!>"no"<!>
|
||||||
|
|
||||||
|
platform val customAccessorVal: String
|
||||||
|
<!PLATFORM_DECLARATION_WITH_BODY!>get()<!> = "no"
|
||||||
|
platform var customAccessorVar: String
|
||||||
|
<!PLATFORM_DECLARATION_WITH_BODY!>get()<!> = "no"
|
||||||
|
<!PLATFORM_DECLARATION_WITH_BODY!>set(value)<!> {}
|
||||||
|
|
||||||
|
platform <!CONST_VAL_WITHOUT_INITIALIZER!>const<!> val constVal: Int
|
||||||
|
|
||||||
|
platform <!WRONG_MODIFIER_TARGET!>lateinit<!> var lateinitVar: String
|
||||||
|
|
||||||
|
<!WRONG_MODIFIER_TARGET!>platform<!> val delegated: String by Delegate
|
||||||
|
object Delegate { operator fun getValue(x: Any?, y: Any?): String = "" }
|
||||||
|
|
||||||
|
fun test(): String {
|
||||||
|
<!WRONG_MODIFIER_TARGET!>platform<!> val localVariable: String
|
||||||
|
localVariable = "no"
|
||||||
|
return localVariable
|
||||||
|
}
|
||||||
Vendored
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public val backingFieldVal: kotlin.String = "no"
|
||||||
|
public var backingFieldVar: kotlin.String
|
||||||
|
public const val constVal: kotlin.Int
|
||||||
|
public val customAccessorVal: kotlin.String
|
||||||
|
public var customAccessorVar: kotlin.String
|
||||||
|
public val delegated: kotlin.String
|
||||||
|
public val justVal: kotlin.String
|
||||||
|
public var justVar: kotlin.String
|
||||||
|
public lateinit var lateinitVar: kotlin.String
|
||||||
|
public val valWithGet: kotlin.String
|
||||||
|
public var varWithGetSet: kotlin.String
|
||||||
|
public var varWithPlatformGetSet: kotlin.String
|
||||||
|
public val kotlin.String.extensionVal: kotlin.Unit
|
||||||
|
public var </*0*/ T> T.genericExtensionVar: T
|
||||||
|
public fun test(): kotlin.String
|
||||||
|
|
||||||
|
public object Delegate {
|
||||||
|
private constructor Delegate()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public final operator fun getValue(/*0*/ x: kotlin.Any?, /*1*/ y: kotlin.Any?): kotlin.String
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
// !LANGUAGE: +MultiPlatformProjects
|
||||||
|
// MODULE: m1-common
|
||||||
|
// FILE: common.kt
|
||||||
|
platform var foo: String
|
||||||
|
|
||||||
|
// MODULE: m2-jvm(m1-common)
|
||||||
|
// FILE: jvm.kt
|
||||||
|
impl var foo: String = "JVM"
|
||||||
|
|
||||||
|
// MODULE: m3-js(m1-common)
|
||||||
|
// FILE: js.kt
|
||||||
|
impl var foo: String = "JS"
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
// -- Module: <m1-common> --
|
||||||
|
package
|
||||||
|
|
||||||
|
public var foo: kotlin.String
|
||||||
|
|
||||||
|
|
||||||
|
// -- Module: <m2-jvm> --
|
||||||
|
package
|
||||||
|
|
||||||
|
public var foo: kotlin.String
|
||||||
|
|
||||||
|
|
||||||
|
// -- Module: <m3-js> --
|
||||||
|
package
|
||||||
|
|
||||||
|
public var foo: kotlin.String
|
||||||
@@ -12630,6 +12630,27 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/testData/diagnostics/tests/multiplatform/topLevelProperty")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class TopLevelProperty extends AbstractDiagnosticsTest {
|
||||||
|
public void testAllFilesPresentInTopLevelProperty() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform/topLevelProperty"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("differentKindsOfProperties.kt")
|
||||||
|
public void testDifferentKindsOfProperties() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/differentKindsOfProperties.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("simplePlatformVar.kt")
|
||||||
|
public void testSimplePlatformVar() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/simplePlatformVar.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/diagnostics/tests/namedArguments")
|
@TestMetadata("compiler/testData/diagnostics/tests/namedArguments")
|
||||||
|
|||||||
+1
-1
@@ -46,7 +46,7 @@ public class JavaPropertyDescriptor extends PropertyDescriptorImpl implements Ja
|
|||||||
boolean isStaticFinal
|
boolean isStaticFinal
|
||||||
) {
|
) {
|
||||||
super(containingDeclaration, original, annotations, modality, visibility, isVar, name, kind, source,
|
super(containingDeclaration, original, annotations, modality, visibility, isVar, name, kind, source,
|
||||||
/* lateInit = */ false, /* isConst = */ false);
|
/* lateInit = */ false, /* isConst = */ false, /* isPlatform = */ false, /* isImpl = */ false);
|
||||||
|
|
||||||
this.isStaticFinal = isStaticFinal;
|
this.isStaticFinal = isStaticFinal;
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-8
@@ -44,6 +44,8 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
|
|||||||
private final Kind kind;
|
private final Kind kind;
|
||||||
private final boolean lateInit;
|
private final boolean lateInit;
|
||||||
private final boolean isConst;
|
private final boolean isConst;
|
||||||
|
private final boolean isPlatform;
|
||||||
|
private final boolean isImpl;
|
||||||
|
|
||||||
private ReceiverParameterDescriptor dispatchReceiverParameter;
|
private ReceiverParameterDescriptor dispatchReceiverParameter;
|
||||||
private ReceiverParameterDescriptor extensionReceiverParameter;
|
private ReceiverParameterDescriptor extensionReceiverParameter;
|
||||||
@@ -63,7 +65,9 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
|
|||||||
@NotNull Kind kind,
|
@NotNull Kind kind,
|
||||||
@NotNull SourceElement source,
|
@NotNull SourceElement source,
|
||||||
boolean lateInit,
|
boolean lateInit,
|
||||||
boolean isConst
|
boolean isConst,
|
||||||
|
boolean isPlatform,
|
||||||
|
boolean isImpl
|
||||||
) {
|
) {
|
||||||
super(containingDeclaration, annotations, name, null, isVar, source);
|
super(containingDeclaration, annotations, name, null, isVar, source);
|
||||||
this.modality = modality;
|
this.modality = modality;
|
||||||
@@ -72,6 +76,8 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
|
|||||||
this.kind = kind;
|
this.kind = kind;
|
||||||
this.lateInit = lateInit;
|
this.lateInit = lateInit;
|
||||||
this.isConst = isConst;
|
this.isConst = isConst;
|
||||||
|
this.isPlatform = isPlatform;
|
||||||
|
this.isImpl = isImpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -85,10 +91,12 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
|
|||||||
@NotNull Kind kind,
|
@NotNull Kind kind,
|
||||||
@NotNull SourceElement source,
|
@NotNull SourceElement source,
|
||||||
boolean lateInit,
|
boolean lateInit,
|
||||||
boolean isConst
|
boolean isConst,
|
||||||
|
boolean isPlatform,
|
||||||
|
boolean isImpl
|
||||||
) {
|
) {
|
||||||
return new PropertyDescriptorImpl(containingDeclaration, null, annotations,
|
return new PropertyDescriptorImpl(containingDeclaration, null, annotations,
|
||||||
modality, visibility, isVar, name, kind, source, lateInit, isConst);
|
modality, visibility, isVar, name, kind, source, lateInit, isConst, isPlatform, isImpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(
|
public void setType(
|
||||||
@@ -334,7 +342,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
|
|||||||
) {
|
) {
|
||||||
return new PropertyDescriptorImpl(
|
return new PropertyDescriptorImpl(
|
||||||
newOwner, original, getAnnotations(), newModality, newVisibility, isVar(), getName(), kind, SourceElement.NO_SOURCE,
|
newOwner, original, getAnnotations(), newModality, newVisibility, isVar(), getName(), kind, SourceElement.NO_SOURCE,
|
||||||
isLateInit(), isConst()
|
isLateInit(), isConst(), isPlatform(), isImpl()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -357,14 +365,12 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPlatform() {
|
public boolean isPlatform() {
|
||||||
// TODO
|
return isPlatform;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isImpl() {
|
public boolean isImpl() {
|
||||||
// TODO
|
return isImpl;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -365,7 +365,9 @@ public class ErrorUtils {
|
|||||||
CallableMemberDescriptor.Kind.DECLARATION,
|
CallableMemberDescriptor.Kind.DECLARATION,
|
||||||
SourceElement.NO_SOURCE,
|
SourceElement.NO_SOURCE,
|
||||||
/* lateInit = */ false,
|
/* lateInit = */ false,
|
||||||
/* isConst = */ false
|
/* isConst = */ false,
|
||||||
|
/* isPlatform = */ false,
|
||||||
|
/* isImpl = */ false
|
||||||
);
|
);
|
||||||
descriptor.setType(ERROR_PROPERTY_TYPE,
|
descriptor.setType(ERROR_PROPERTY_TYPE,
|
||||||
Collections.<TypeParameterDescriptor>emptyList(),
|
Collections.<TypeParameterDescriptor>emptyList(),
|
||||||
|
|||||||
+5
-2
@@ -24,7 +24,10 @@ import org.jetbrains.kotlin.protobuf.MessageLite
|
|||||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
|
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.SimpleType
|
||||||
|
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||||
|
import org.jetbrains.kotlin.types.Variance
|
||||||
|
import org.jetbrains.kotlin.types.asSimpleType
|
||||||
|
|
||||||
interface DeserializedMemberDescriptor : MemberDescriptor {
|
interface DeserializedMemberDescriptor : MemberDescriptor {
|
||||||
val proto: MessageLite
|
val proto: MessageLite
|
||||||
@@ -87,7 +90,7 @@ class DeserializedPropertyDescriptor(
|
|||||||
override val containerSource: SourceElement?
|
override val containerSource: SourceElement?
|
||||||
) : DeserializedCallableMemberDescriptor,
|
) : DeserializedCallableMemberDescriptor,
|
||||||
PropertyDescriptorImpl(containingDeclaration, original, annotations,
|
PropertyDescriptorImpl(containingDeclaration, original, annotations,
|
||||||
modality, visibility, isVar, name, kind, SourceElement.NO_SOURCE, isLateInit, isConst) {
|
modality, visibility, isVar, name, kind, SourceElement.NO_SOURCE, isLateInit, isConst, false, false) {
|
||||||
|
|
||||||
override fun createSubstitutedCopy(
|
override fun createSubstitutedCopy(
|
||||||
newOwner: DeclarationDescriptor,
|
newOwner: DeclarationDescriptor,
|
||||||
|
|||||||
+2
-2
@@ -101,8 +101,8 @@ private fun genProperty(
|
|||||||
Name.identifier(id.name),
|
Name.identifier(id.name),
|
||||||
CallableMemberDescriptor.Kind.SYNTHESIZED,
|
CallableMemberDescriptor.Kind.SYNTHESIZED,
|
||||||
sourceElement,
|
sourceElement,
|
||||||
false,
|
false, false, false, false
|
||||||
false) {
|
) {
|
||||||
override val errorType = errorType
|
override val errorType = errorType
|
||||||
override val cacheView = cacheView
|
override val cacheView = cacheView
|
||||||
override val resourceId = id
|
override val resourceId = id
|
||||||
|
|||||||
Reference in New Issue
Block a user