From 6776930881e74bf0e12aa253445b9e29df41e0f7 Mon Sep 17 00:00:00 2001 From: Nikolay Lunyak Date: Tue, 17 Aug 2021 18:11:27 +0300 Subject: [PATCH] [FIR] Forbid explicit backing fields for FE 1.0 --- .../src/org/jetbrains/kotlin/diagnostics/Errors.java | 2 ++ .../kotlin/diagnostics/rendering/DefaultErrorMessages.java | 2 ++ .../org/jetbrains/kotlin/resolve/DeclarationsChecker.kt | 7 +++++++ 3 files changed, 11 insertions(+) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index c24265d768d..33696758ccc 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -71,6 +71,8 @@ public interface Errors { DiagnosticFactory1> EXPERIMENTAL_FEATURE_WARNING = DiagnosticFactory1.create(WARNING); DiagnosticFactory1> EXPERIMENTAL_FEATURE_ERROR = DiagnosticFactory1.create(ERROR); + DiagnosticFactory0 EXPLICIT_BACKING_FIELDS_UNSUPPORTED = DiagnosticFactory0.create(ERROR); + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Generic errors/warnings: applicable in many contexts 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 8af252ce3d3..c39764f14c2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -712,6 +712,8 @@ public class DefaultErrorMessages { MAP.put(EXPERIMENTAL_FEATURE_WARNING, "{0}", new LanguageFeatureMessageRenderer(LanguageFeatureMessageRenderer.Type.WARNING)); MAP.put(EXPERIMENTAL_FEATURE_ERROR, "{0}", new LanguageFeatureMessageRenderer(LanguageFeatureMessageRenderer.Type.ERROR)); + MAP.put(EXPLICIT_BACKING_FIELDS_UNSUPPORTED, "Explicit backing field declarations are not supported in FE 1.0"); + MAP.put(EXCEPTION_FROM_ANALYZER, "Internal Error occurred while analyzing this expression:\n{0}", THROWABLE); MAP.put(MISSING_STDLIB, "{0}. Ensure you have the standard Kotlin library in dependencies", STRING); MAP.put(UNNECESSARY_SAFE_CALL, "Unnecessary safe call on a non-null receiver of type {0}. This expression will have nullable type in future releases", RENDER_TYPE); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt index c9586d17109..1c9927433c6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt @@ -591,6 +591,12 @@ class DeclarationsChecker( } } + private fun checkBackingField(property: KtProperty) { + property.fieldDeclaration?.let { + trace.report(EXPLICIT_BACKING_FIELDS_UNSUPPORTED.on(it)) + } + } + private fun checkProperty(property: KtProperty, propertyDescriptor: PropertyDescriptor) { val containingDeclaration = propertyDescriptor.containingDeclaration if (containingDeclaration is ClassDescriptor) { @@ -605,6 +611,7 @@ class DeclarationsChecker( checkPropertyTypeParametersAreUsedInReceiverType(propertyDescriptor) checkImplicitCallableType(property, propertyDescriptor) checkPrivateExpectedDeclaration(property, propertyDescriptor) + checkBackingField(property) } private fun checkPrivateExpectedDeclaration(declaration: KtDeclaration, descriptor: MemberDescriptor) {