From e50b102e89f2e1720cd17af022fe2b44d338dce0 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 14 Dec 2016 19:46:20 +0300 Subject: [PATCH] Treat absence of version in SinceKotlinInfo as infinite version This may be needed in the future to make some declarations erroneous for all versions of compilers --- .../jetbrains/kotlin/diagnostics/Errors.java | 5 +++-- .../rendering/DefaultErrorMessages.java | 19 ++++++++++++++++--- .../kotlin/resolve/deprecationUtil.kt | 4 ++-- .../descriptors/SinceKotlinInfo.kt | 14 +++++++++----- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index e00a0a8d86a..5dbb470f082 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -38,6 +38,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall; import org.jetbrains.kotlin.resolve.calls.tower.WrongResolutionToClassifier; import org.jetbrains.kotlin.resolve.checkers.HeaderImplDeclarationChecker; import org.jetbrains.kotlin.serialization.deserialization.IncompatibleVersionErrorData; +import org.jetbrains.kotlin.serialization.deserialization.descriptors.SinceKotlinInfo; import org.jetbrains.kotlin.types.KotlinType; import java.lang.reflect.Field; @@ -81,8 +82,8 @@ public interface Errors { DiagnosticFactory2 DEPRECATION = DiagnosticFactory2.create(WARNING); DiagnosticFactory2 DEPRECATION_ERROR = DiagnosticFactory2.create(ERROR); - DiagnosticFactory3> SINCE_KOTLIN_INFO_DEPRECATION = DiagnosticFactory3.create(WARNING); - DiagnosticFactory3> SINCE_KOTLIN_INFO_DEPRECATION_ERROR = DiagnosticFactory3.create(ERROR); + DiagnosticFactory3> SINCE_KOTLIN_INFO_DEPRECATION = DiagnosticFactory3.create(WARNING); + DiagnosticFactory3> SINCE_KOTLIN_INFO_DEPRECATION_ERROR = DiagnosticFactory3.create(ERROR); DiagnosticFactory2 API_NOT_AVAILABLE = DiagnosticFactory2.create(ERROR); 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 b1adc8127c0..91c5e7129fa 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -34,6 +34,7 @@ import org.jetbrains.kotlin.psi.KtSimpleNameExpression; import org.jetbrains.kotlin.psi.KtTypeConstraint; import org.jetbrains.kotlin.resolve.VarianceConflictDiagnosticData; import org.jetbrains.kotlin.serialization.deserialization.IncompatibleVersionErrorData; +import org.jetbrains.kotlin.serialization.deserialization.descriptors.SinceKotlinInfo; import org.jetbrains.kotlin.types.KotlinType; import org.jetbrains.kotlin.util.MappedExtensionProvider; import org.jetbrains.kotlin.util.OperatorNameConventions; @@ -321,7 +322,7 @@ public class DefaultErrorMessages { MAP.put(DEPRECATION, "''{0}'' is deprecated. {1}", DEPRECATION_RENDERER, STRING); MAP.put(DEPRECATION_ERROR, "Using ''{0}'' is an error. {1}", DEPRECATION_RENDERER, STRING); - DiagnosticParameterRenderer> sinceKotlinInfoRenderer = new DiagnosticParameterRenderer>() { + DiagnosticParameterRenderer> sinceKotlinInfoMessage = new DiagnosticParameterRenderer>() { @NotNull @Override public String render(@NotNull Pair pair, @NotNull RenderingContext renderingContext) { @@ -329,8 +330,20 @@ public class DefaultErrorMessages { return pair.getFirst().getVersionString() + (message != null ? ". " + message : ""); } }; - MAP.put(SINCE_KOTLIN_INFO_DEPRECATION, "''{0}'' is only supported since Kotlin {1} and should not be used in Kotlin {2}", DEPRECATION_RENDERER, STRING, sinceKotlinInfoRenderer); - MAP.put(SINCE_KOTLIN_INFO_DEPRECATION_ERROR, "''{0}'' is only available since Kotlin {1} and cannot be used in Kotlin {2}", DEPRECATION_RENDERER, STRING, sinceKotlinInfoRenderer); + MAP.put(SINCE_KOTLIN_INFO_DEPRECATION, "''{0}''{1} should not be used in Kotlin {2}", DEPRECATION_RENDERER, new DiagnosticParameterRenderer() { + @NotNull + @Override + public String render(@NotNull SinceKotlinInfo.Version obj, @NotNull RenderingContext renderingContext) { + return obj.equals(SinceKotlinInfo.Version.INFINITY) ? "" : " is only supported since Kotlin " + obj.asString() + " and"; + } + }, sinceKotlinInfoMessage); + MAP.put(SINCE_KOTLIN_INFO_DEPRECATION_ERROR, "''{0}''{1} cannot be used in Kotlin {2}", DEPRECATION_RENDERER, new DiagnosticParameterRenderer() { + @NotNull + @Override + public String render(@NotNull SinceKotlinInfo.Version obj, @NotNull RenderingContext renderingContext) { + return obj.equals(SinceKotlinInfo.Version.INFINITY) ? "" : " is only available since Kotlin " + obj.asString() + " and"; + } + }, sinceKotlinInfoMessage); MAP.put(API_NOT_AVAILABLE, "This declaration is only available since Kotlin {0} and cannot be used with the specified API version {1}", STRING, STRING); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecationUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecationUtil.kt index 877d0a44678..b688c05fa12 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecationUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecationUtil.kt @@ -123,8 +123,8 @@ private data class DeprecatedBySinceKotlinInfo( } } - val sinceKotlinVersion: String - get() = sinceKotlinInfo.version.asString() + val sinceKotlinVersion: SinceKotlinInfo.Version + get() = sinceKotlinInfo.version } fun DeclarationDescriptor.getDeprecations(languageVersionSettings: LanguageVersionSettings): List { diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/SinceKotlinInfo.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/SinceKotlinInfo.kt index 93b8c4435d7..d5e56bef54c 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/SinceKotlinInfo.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/SinceKotlinInfo.kt @@ -44,11 +44,14 @@ class SinceKotlinInfo( fun encode( writeVersion: (Int) -> Unit, writeVersionFull: (Int) -> Unit - ) { - if (major > MAJOR_MASK || minor > MINOR_MASK || patch > PATCH_MASK) { + ) = when { + this == INFINITY -> { + // Do nothing: absence of version means INFINITY + } + major > MAJOR_MASK || minor > MINOR_MASK || patch > PATCH_MASK -> { writeVersionFull(major or (minor shl 8) or (patch shl 16)) } - else if (this != DEFAULT) { + else -> { writeVersion(major or (minor shl MAJOR_BITS) or (patch shl (MAJOR_BITS + MINOR_BITS))) } } @@ -56,7 +59,8 @@ class SinceKotlinInfo( override fun toString(): String = asString() companion object { - val DEFAULT = Version(1, 0, 0) + @JvmField + val INFINITY = Version(256, 256, 256) // Number of bits used for major, minor and patch components in "version" field private const val MAJOR_BITS = 3 @@ -77,7 +81,7 @@ class SinceKotlinInfo( minor = (version shr MAJOR_BITS) and MINOR_MASK, patch = (version shr (MAJOR_BITS + MINOR_BITS)) and PATCH_MASK ) - else -> Version.DEFAULT + else -> Version.INFINITY } } }