diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AccessorForPropertyDescriptor.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AccessorForPropertyDescriptor.java index b0b216e160f..ba2d01ffd8c 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AccessorForPropertyDescriptor.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AccessorForPropertyDescriptor.java @@ -77,7 +77,8 @@ public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implem ) { super(containingDeclaration, null, Annotations.Companion.getEMPTY(), Modality.FINAL, Visibilities.LOCAL, 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.superCallTarget = superCallTarget; diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt index 9ecfee402a4..c252140f3ff 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt @@ -278,9 +278,10 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l name: Name, kind: CallableMemberDescriptor.Kind, source: SourceElement - ) : SyntheticJavaPropertyDescriptor, PropertyDescriptorImpl(containingDeclaration, original, annotations, - modality, visibility, isVar, name, kind, source, - /* lateInit = */ false, /* isConst = */ false) { + ) : SyntheticJavaPropertyDescriptor, PropertyDescriptorImpl( + containingDeclaration, original, annotations, modality, visibility, isVar, name, kind, source, + /* lateInit = */ false, /* isConst = */ false, /* isPlatform = */ false, /* isImpl = */ false + ) { override var getMethod: FunctionDescriptor by Delegates.notNull() private set diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index f2daef45815..bf107b0f57c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -494,6 +494,8 @@ public interface Errors { DiagnosticFactory0 PLATFORM_DECLARATION_WITH_BODY = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE); DiagnosticFactory0 PLATFORM_DECLARATION_WITH_DEFAULT_PARAMETER = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 PLATFORM_PROPERTY_INITIALIZER = DiagnosticFactory0.create(ERROR); + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Errors/warnings inside code blocks diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 3c2a408f60e..c73adb0e99f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -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_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(SUPERTYPE_NOT_INITIALIZED, "This type has a constructor, and thus must be initialized here"); MAP.put(NOTHING_TO_OVERRIDE, "''{0}'' overrides nothing", NAME); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt index 939a3cdf67e..29e21234da7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.resolve import com.google.common.collect.ImmutableSet -import com.google.common.collect.Sets import com.intellij.psi.PsiElement import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.config.LanguageVersionSettings @@ -650,17 +649,19 @@ class DeclarationsChecker( val initializer = property.initializer val delegate = property.delegate + val isPlatform = propertyDescriptor.isPlatform if (initializer != null) { if (inTrait) { trace.report(PROPERTY_INITIALIZER_IN_INTERFACE.on(initializer)) } - else { - if (!backingFieldRequired) { - trace.report(PROPERTY_INITIALIZER_NO_BACKING_FIELD.on(initializer)) - } - else if (property.receiverTypeReference != null) { - trace.report(EXTENSION_PROPERTY_WITH_BACKING_FIELD.on(initializer)) - } + else if (isPlatform) { + trace.report(PLATFORM_PROPERTY_INITIALIZER.on(initializer)) + } + else if (!backingFieldRequired) { + trace.report(PROPERTY_INITIALIZER_NO_BACKING_FIELD.on(initializer)) + } + else if (property.receiverTypeReference != null) { + trace.report(EXTENSION_PROPERTY_WITH_BACKING_FIELD.on(initializer)) } } else if (delegate != null) { @@ -670,7 +671,7 @@ class DeclarationsChecker( } else { 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) { trace.report(MUST_BE_INITIALIZED.on(property)) } @@ -681,11 +682,9 @@ class DeclarationsChecker( else if (noExplicitTypeOrGetterType(property)) { trace.report(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER.on(property)) } - if (backingFieldRequired && !inTrait && propertyDescriptor.isLateInit && !isUninitialized) { - if (trace[MUST_BE_LATEINIT, propertyDescriptor] ?: false) {} - else { - trace.report(UNNECESSARY_LATEINIT.on(property)) - } + if (backingFieldRequired && !inTrait && propertyDescriptor.isLateInit && !isUninitialized && + trace[MUST_BE_LATEINIT, propertyDescriptor] != true) { + trace.report(UNNECESSARY_LATEINIT.on(property)) } } } @@ -800,11 +799,18 @@ class DeclarationsChecker( private fun checkAccessor( propertyDescriptor: PropertyDescriptor, accessor: KtPropertyAccessor?, - accessorDescriptor: PropertyAccessorDescriptor?) { + accessorDescriptor: PropertyAccessorDescriptor? + ) { 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 tokens = modifiersChecker.getTokensCorrespondingToModifiers(accessorModifierList, - Sets.newHashSet(KtTokens.PUBLIC_KEYWORD, KtTokens.PROTECTED_KEYWORD, KtTokens.PRIVATE_KEYWORD, KtTokens.INTERNAL_KEYWORD)) + val tokens = modifiersChecker.getTokensCorrespondingToModifiers( + accessorModifierList, + setOf(KtTokens.PUBLIC_KEYWORD, KtTokens.PROTECTED_KEYWORD, KtTokens.PRIVATE_KEYWORD, KtTokens.INTERNAL_KEYWORD) + ) if (accessor.isGetter) { if (accessorDescriptor.visibility != propertyDescriptor.visibility) { reportVisibilityModifierDiagnostics(tokens.values, Errors.GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java index 53b383ea98b..c1f1418643b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java @@ -808,7 +808,10 @@ public class DescriptorResolver { CallableMemberDescriptor.Kind.DECLARATION, KotlinSourceElementKt.toSourceElement(property), 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); @@ -1123,7 +1126,9 @@ public class DescriptorResolver { CallableMemberDescriptor.Kind.DECLARATION, KotlinSourceElementKt.toSourceElement(parameter), /* lateInit = */ false, - /* isConst = */ false + /* isConst = */ false, + /* isPlatform = */ false, + /* isImpl = */ false ); propertyWrapper.setDescriptor(propertyDescriptor); propertyDescriptor.setType(type, Collections.emptyList(), diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/LocalVariableResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/LocalVariableResolver.kt index e96cfd4e117..df710d28600 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/LocalVariableResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/LocalVariableResolver.kt @@ -85,14 +85,14 @@ class LocalVariableResolver( propertyDescriptor, delegateExpression, typingContext.scope, - typingContext.trace); + typingContext.trace) } } val initializer = property.initializer var typeInfo: KotlinTypeInfo if (initializer != null) { - val outType = propertyDescriptor.getType() + val outType = propertyDescriptor.type typeInfo = facade.getTypeInfo(initializer, context.replaceExpectedType(outType)) val dataFlowInfo = typeInfo.dataFlowInfo val type = typeInfo.type @@ -146,7 +146,9 @@ class LocalVariableResolver( CallableMemberDescriptor.Kind.DECLARATION, variable.toSourceElement(), /* lateInit = */ false, - /* isConst = */ false + /* isConst = */ false, + /* isPlatform = */ false, + /* isImpl = */ false ) // For a local variable the type must not be deferred type = variableTypeAndInitializerResolver.resolveType(propertyDescriptor, scope, variable, dataFlowInfo, trace, local = true) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt index 9e06e05cfd4..c86c87ec45a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt @@ -90,8 +90,8 @@ object ModifierCheckerCore { CONST_KEYWORD to EnumSet.of(MEMBER_PROPERTY, TOP_LEVEL_PROPERTY), OPERATOR_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 - IMPL_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, TOP_LEVEL_PROPERTY_WITHOUT_FIELD_OR_DELEGATE, CLASS_ONLY, OBJECT, INTERFACE, INNER_CLASS, ENUM_CLASS, ANNOTATION_CLASS) // TODO ) val featureDependencies = mapOf( diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/dynamicCalls.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/dynamicCalls.kt index 9a4af897bca..8ce403423bc 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/dynamicCalls.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/dynamicCalls.kt @@ -97,7 +97,9 @@ class DynamicCallableDescriptors(storageManager: StorageManager, builtIns: Kotli CallableMemberDescriptor.Kind.DECLARATION, SourceElement.NO_SOURCE, /* lateInit = */ false, - /* isConst = */ false + /* isConst = */ false, + /* isPlatform = */ false, + /* isImpl = */ false ) propertyDescriptor.setType( dynamicType, diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/JvmDescriptorWithExtraFlags.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/JvmDescriptorWithExtraFlags.kt index 57b45692986..4527ec0af6e 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/JvmDescriptorWithExtraFlags.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/JvmDescriptorWithExtraFlags.kt @@ -20,10 +20,8 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl -import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.org.objectweb.asm.commons.Method interface JvmDescriptorWithExtraFlags { val extraFlags: Int @@ -41,10 +39,12 @@ class JvmPropertyDescriptorImpl( kind: CallableMemberDescriptor.Kind, source: SourceElement, isLateInit: Boolean, - isConst: Boolean + isConst: Boolean, + isPlatform: Boolean, + isImpl: Boolean ) : JvmDescriptorWithExtraFlags, PropertyDescriptorImpl( containingDeclaration, original, annotations, modality, visibility, isVar, - name, kind, source, isLateInit, isConst + name, kind, source, isLateInit, isConst, isPlatform, isImpl ) { override fun createSubstitutedCopy( newOwner: DeclarationDescriptor, @@ -55,7 +55,7 @@ class JvmPropertyDescriptorImpl( ): PropertyDescriptorImpl = JvmPropertyDescriptorImpl( newOwner, original, annotations, newModality, newVisibility, extraFlags, isVar, name, kind, - SourceElement.NO_SOURCE, isLateInit, isConst + SourceElement.NO_SOURCE, isLateInit, isConst, isPlatform, isImpl ) companion object { @@ -71,7 +71,7 @@ class JvmPropertyDescriptorImpl( ): PropertyDescriptorImpl = JvmPropertyDescriptorImpl( containingDeclaration, null, annotations, modality, visibility, extraFlags, false, name, - CallableMemberDescriptor.Kind.SYNTHESIZED, source, false, false + CallableMemberDescriptor.Kind.SYNTHESIZED, source, false, false, false, false ).initialize(type) fun createFinalField( @@ -85,7 +85,7 @@ class JvmPropertyDescriptorImpl( ): PropertyDescriptorImpl = JvmPropertyDescriptorImpl( 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) } } @@ -108,4 +108,4 @@ class JvmFunctionDescriptorImpl( SourceElement.NO_SOURCE, extraFlags ) } -} \ No newline at end of file +} diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/SharedVariablesManager.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/SharedVariablesManager.kt index 318025a34d6..5ea59789264 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/SharedVariablesManager.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/SharedVariablesManager.kt @@ -59,7 +59,7 @@ class JvmSharedVariablesManager(val builtIns: KotlinBuiltIns) : SharedVariablesM PropertyDescriptorImpl.create( refClass, Annotations.EMPTY, Modality.FINAL, Visibilities.PUBLIC, true, Name.identifier("element"), CallableMemberDescriptor.Kind.DECLARATION, SourceElement.NO_SOURCE, - false, false + false, false, false, false ).initialize(type, dispatchReceiverParameter = refClass.thisAsReceiverParameter) } @@ -99,7 +99,7 @@ class JvmSharedVariablesManager(val builtIns: KotlinBuiltIns) : SharedVariablesM PropertyDescriptorImpl.create( genericRefClass, Annotations.EMPTY, Modality.FINAL, Visibilities.PUBLIC, true, Name.identifier("element"), CallableMemberDescriptor.Kind.DECLARATION, SourceElement.NO_SOURCE, - false, false + false, false, false, false ).initialize( type = builtIns.anyType, dispatchReceiverParameter = genericRefClass.thisAsReceiverParameter diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/SpecialDescriptorsFactory.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/SpecialDescriptorsFactory.kt index f98272e2519..5f3c9a8101e 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/SpecialDescriptorsFactory.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/SpecialDescriptorsFactory.kt @@ -128,7 +128,7 @@ class SpecialDescriptorsFactory( objectDescriptor, Annotations.EMPTY, Modality.FINAL, Visibilities.PUBLIC, false, Name.identifier("INSTANCE"), - CallableMemberDescriptor.Kind.SYNTHESIZED, SourceElement.NO_SOURCE, false, false + CallableMemberDescriptor.Kind.SYNTHESIZED, SourceElement.NO_SOURCE, false, false, false, false ).initialize(objectDescriptor.defaultType) return instanceFieldDescriptor diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrDelegateDescriptor.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrDelegateDescriptor.kt index f053512c6cc..2c20d9008b2 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrDelegateDescriptor.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrDelegateDescriptor.kt @@ -50,16 +50,18 @@ abstract class IrDelegateDescriptorBase( delegateType: KotlinType ) : PropertyDescriptorImpl( containingDeclaration, - null, // original + /* original = */ null, Annotations.EMPTY, Modality.FINAL, Visibilities.PRIVATE, - false, // isVar + /* isVar = */ false, name, CallableMemberDescriptor.Kind.SYNTHESIZED, SourceElement.NO_SOURCE, - false, // lateInit - false // isConst + /* lateInit = */ false, + /* isConst = */ false, + /* isPlatform = */ false, + /* isImpl = */ false ) { init { setOutType(delegateType) diff --git a/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/differentKindsOfProperties.kt b/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/differentKindsOfProperties.kt new file mode 100644 index 00000000000..f77e0857c70 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/differentKindsOfProperties.kt @@ -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.genericExtensionVar: T + +platform val valWithGet: String + get +platform var varWithGetSet: String + get set + +platform var varWithPlatformGetSet: String + platform get + platform set + +platform val backingFieldVal: String = "no" +platform var backingFieldVar: String = "no" + +platform val customAccessorVal: String + get() = "no" +platform var customAccessorVar: String + get() = "no" + set(value) {} + +platform const val constVal: Int + +platform lateinit var lateinitVar: String + +platform val delegated: String by Delegate +object Delegate { operator fun getValue(x: Any?, y: Any?): String = "" } + +fun test(): String { + platform val localVariable: String + localVariable = "no" + return localVariable +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/differentKindsOfProperties.txt b/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/differentKindsOfProperties.txt new file mode 100644 index 00000000000..5bf85aff46c --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/differentKindsOfProperties.txt @@ -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 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 +} diff --git a/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/simplePlatformVar.kt b/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/simplePlatformVar.kt new file mode 100644 index 00000000000..4200bc90c8a --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/simplePlatformVar.kt @@ -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" diff --git a/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/simplePlatformVar.txt b/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/simplePlatformVar.txt new file mode 100644 index 00000000000..af6c3cb5e79 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/simplePlatformVar.txt @@ -0,0 +1,16 @@ +// -- Module: -- +package + +public var foo: kotlin.String + + +// -- Module: -- +package + +public var foo: kotlin.String + + +// -- Module: -- +package + +public var foo: kotlin.String diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 20dd56fe326..ac0d7a749b4 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -12630,6 +12630,27 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { 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") diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaPropertyDescriptor.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaPropertyDescriptor.java index d659b3f8356..d19934e305b 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaPropertyDescriptor.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaPropertyDescriptor.java @@ -46,7 +46,7 @@ public class JavaPropertyDescriptor extends PropertyDescriptorImpl implements Ja boolean isStaticFinal ) { 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; } diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java index 9f0478622ed..42e32a150c9 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java @@ -44,6 +44,8 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp private final Kind kind; private final boolean lateInit; private final boolean isConst; + private final boolean isPlatform; + private final boolean isImpl; private ReceiverParameterDescriptor dispatchReceiverParameter; private ReceiverParameterDescriptor extensionReceiverParameter; @@ -63,7 +65,9 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp @NotNull Kind kind, @NotNull SourceElement source, boolean lateInit, - boolean isConst + boolean isConst, + boolean isPlatform, + boolean isImpl ) { super(containingDeclaration, annotations, name, null, isVar, source); this.modality = modality; @@ -72,6 +76,8 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp this.kind = kind; this.lateInit = lateInit; this.isConst = isConst; + this.isPlatform = isPlatform; + this.isImpl = isImpl; } @NotNull @@ -85,10 +91,12 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp @NotNull Kind kind, @NotNull SourceElement source, boolean lateInit, - boolean isConst + boolean isConst, + boolean isPlatform, + boolean isImpl ) { 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( @@ -334,7 +342,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp ) { return new PropertyDescriptorImpl( 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 public boolean isPlatform() { - // TODO - return false; + return isPlatform; } @Override public boolean isImpl() { - // TODO - return false; + return isImpl; } @Override diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java index 107869eeeaf..d518386dfde 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/ErrorUtils.java @@ -365,7 +365,9 @@ public class ErrorUtils { CallableMemberDescriptor.Kind.DECLARATION, SourceElement.NO_SOURCE, /* lateInit = */ false, - /* isConst = */ false + /* isConst = */ false, + /* isPlatform = */ false, + /* isImpl = */ false ); descriptor.setType(ERROR_PROPERTY_TYPE, Collections.emptyList(), diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedMemberDescriptor.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedMemberDescriptor.kt index 99aa970ff7b..e03b798e50a 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedMemberDescriptor.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedMemberDescriptor.kt @@ -24,7 +24,10 @@ import org.jetbrains.kotlin.protobuf.MessageLite import org.jetbrains.kotlin.serialization.ProtoBuf import org.jetbrains.kotlin.serialization.deserialization.NameResolver 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 { val proto: MessageLite @@ -87,7 +90,7 @@ class DeserializedPropertyDescriptor( override val containerSource: SourceElement? ) : DeserializedCallableMemberDescriptor, 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( newOwner: DeclarationDescriptor, diff --git a/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/synthetic/res/syntheticDescriptorGeneration.kt b/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/synthetic/res/syntheticDescriptorGeneration.kt index 841b80d0ec6..60461267c9e 100644 --- a/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/synthetic/res/syntheticDescriptorGeneration.kt +++ b/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/synthetic/res/syntheticDescriptorGeneration.kt @@ -101,8 +101,8 @@ private fun genProperty( Name.identifier(id.name), CallableMemberDescriptor.Kind.SYNTHESIZED, sourceElement, - false, - false) { + false, false, false, false + ) { override val errorType = errorType override val cacheView = cacheView override val resourceId = id