FE: use proper version in version requirement error message
#KT-48690 Fixed
This commit is contained in:
@@ -99,9 +99,9 @@ public interface Errors {
|
||||
DiagnosticFactory2<PsiElement, DeclarationDescriptor, String> DEPRECATION_ERROR = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory3<PsiElement, TypeAliasDescriptor, DeclarationDescriptor, String> TYPEALIAS_EXPANSION_DEPRECATION = DiagnosticFactory3.create(WARNING);
|
||||
DiagnosticFactory3<PsiElement, TypeAliasDescriptor, DeclarationDescriptor, String> TYPEALIAS_EXPANSION_DEPRECATION_ERROR = DiagnosticFactory3.create(ERROR);
|
||||
DiagnosticFactory3<PsiElement, DeclarationDescriptor, VersionRequirement.Version, Pair<LanguageVersion, String>>
|
||||
DiagnosticFactory3<PsiElement, DeclarationDescriptor, VersionRequirement.Version, Pair<String, String>>
|
||||
VERSION_REQUIREMENT_DEPRECATION = DiagnosticFactory3.create(WARNING);
|
||||
DiagnosticFactory3<PsiElement, DeclarationDescriptor, VersionRequirement.Version, Pair<LanguageVersion, String>>
|
||||
DiagnosticFactory3<PsiElement, DeclarationDescriptor, VersionRequirement.Version, Pair<String, String>>
|
||||
VERSION_REQUIREMENT_DEPRECATION_ERROR = DiagnosticFactory3.create(ERROR);
|
||||
// descriptor and deprecation infos are needed only for IDE quickfix for this warning
|
||||
DiagnosticFactory3<KtNamedDeclaration, String, CallableMemberDescriptor, List<DescriptorBasedDeprecationInfo>> OVERRIDE_DEPRECATION = DiagnosticFactory3.create(WARNING, DECLARATION_NAME);
|
||||
|
||||
+2
-2
@@ -385,9 +385,9 @@ public class DefaultErrorMessages {
|
||||
MAP.put(TYPEALIAS_EXPANSION_DEPRECATION, "''{0}'' uses ''{1}'', which is deprecated. {2}", DEPRECATION_RENDERER, DEPRECATION_RENDERER, STRING);
|
||||
MAP.put(TYPEALIAS_EXPANSION_DEPRECATION_ERROR, "''{0}'' uses ''{1}'', which is an error. {2}", DEPRECATION_RENDERER, DEPRECATION_RENDERER, STRING);
|
||||
|
||||
DiagnosticParameterRenderer<Pair<LanguageVersion, String>> versionRequirementMessage = (pair, renderingContext) -> {
|
||||
DiagnosticParameterRenderer<Pair<String, String>> versionRequirementMessage = (pair, renderingContext) -> {
|
||||
String message = pair.getSecond();
|
||||
return pair.getFirst().getVersionString() + (message != null ? ". " + message : "");
|
||||
return pair.getFirst() + (message != null ? ". " + message : "");
|
||||
};
|
||||
MAP.put(VERSION_REQUIREMENT_DEPRECATION, "''{0}''{1} should not be used in Kotlin {2}", DEPRECATION_RENDERER,
|
||||
(obj, renderingContext) -> obj.equals(VersionRequirement.Version.INFINITY) ? "" : " is only supported since Kotlin " + obj.asString() + " and",
|
||||
|
||||
@@ -7,11 +7,13 @@ package org.jetbrains.kotlin.resolve.deprecation
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.config.ApiVersion
|
||||
import org.jetbrains.kotlin.config.KotlinCompilerVersion
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.container.DefaultImplementation
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.resolve.annotations.argumentValue
|
||||
import org.jetbrains.kotlin.resolve.constants.StringValue
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue.*
|
||||
@@ -48,9 +50,14 @@ internal fun createDeprecationDiagnostic(
|
||||
WARNING -> Errors.VERSION_REQUIREMENT_DEPRECATION
|
||||
ERROR, HIDDEN -> Errors.VERSION_REQUIREMENT_DEPRECATION_ERROR
|
||||
}
|
||||
val currentVersionString = when (deprecation.versionRequirement.kind) {
|
||||
ProtoBuf.VersionRequirement.VersionKind.COMPILER_VERSION -> KotlinCompilerVersion.VERSION
|
||||
ProtoBuf.VersionRequirement.VersionKind.LANGUAGE_VERSION -> languageVersionSettings.languageVersion.versionString
|
||||
ProtoBuf.VersionRequirement.VersionKind.API_VERSION -> languageVersionSettings.apiVersion.versionString
|
||||
}
|
||||
factory.on(
|
||||
element, targetOriginal, deprecation.versionRequirement.version,
|
||||
languageVersionSettings.languageVersion to deprecation.message
|
||||
currentVersionString to deprecation.message
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
$TESTDATA_DIR$/requireKotlinCompilerVersion.kt
|
||||
-classpath
|
||||
$TESTDATA_DIR$/requireKotlinCompilerVersion
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
@@ -0,0 +1,16 @@
|
||||
// Library part (build separately)
|
||||
|
||||
//@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
|
||||
//package test.access
|
||||
//
|
||||
//import kotlin.internal.RequireKotlin
|
||||
//import kotlin.internal.RequireKotlinVersionKind
|
||||
//
|
||||
//@RequireKotlin("9.9.90", versionKind = RequireKotlinVersionKind.COMPILER_VERSION)
|
||||
//class Foo
|
||||
|
||||
import test.access.Foo
|
||||
|
||||
fun main() {
|
||||
Foo()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
compiler/testData/cli/jvm/requireKotlinCompilerVersion.kt:12:20: error: 'Foo' is only available since Kotlin 9.9.90 and cannot be used in Kotlin $VERSION$
|
||||
import test.access.Foo
|
||||
^
|
||||
compiler/testData/cli/jvm/requireKotlinCompilerVersion.kt:15:5: error: 'Foo' is only available since Kotlin 9.9.90 and cannot be used in Kotlin $VERSION$
|
||||
Foo()
|
||||
^
|
||||
COMPILATION_ERROR
|
||||
Binary file not shown.
@@ -766,6 +766,11 @@ public class CliTestGenerated extends AbstractCliTest {
|
||||
runTest("compiler/testData/cli/jvm/recordAsSingleFileRoot.args");
|
||||
}
|
||||
|
||||
@TestMetadata("requireKotlinCompilerVersion.args")
|
||||
public void testRequireKotlinCompilerVersion() throws Exception {
|
||||
runTest("compiler/testData/cli/jvm/requireKotlinCompilerVersion.args");
|
||||
}
|
||||
|
||||
@TestMetadata("resultInReturnTypeSupportedByDefault15.args")
|
||||
public void testResultInReturnTypeSupportedByDefault15() throws Exception {
|
||||
runTest("compiler/testData/cli/jvm/resultInReturnTypeSupportedByDefault15.args");
|
||||
|
||||
Reference in New Issue
Block a user