From 1f30d076de5a9c7840ade24de7cf083d6dc07cc5 Mon Sep 17 00:00:00 2001 From: Roman Efremov Date: Thu, 8 Feb 2024 15:59:43 +0100 Subject: [PATCH] [CLI] Introduce compiler argument to suppress error about API version ...greater than language version. ^KT-63712 --- .../CommonCompilerArgumentsCopyGenerated.kt | 1 + .../arguments/CommonCompilerArguments.kt | 24 +++++++++++++++---- compiler/testData/cli/js/jsExtraHelp.out | 3 +++ ...apiVersionGreaterThanLanguageSuppress.args | 8 +++++++ .../apiVersionGreaterThanLanguageSuppress.kt | 6 +++++ .../apiVersionGreaterThanLanguageSuppress.out | 1 + ...ionGreaterThanLanguageSuppressUseless.args | 8 +++++++ ...sionGreaterThanLanguageSuppressUseless.out | 2 ++ compiler/testData/cli/jvm/extraHelp.out | 3 +++ .../kotlin/cli/CliTestGenerated.java | 10 ++++++++ 10 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppress.args create mode 100644 compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppress.kt create mode 100644 compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppress.out create mode 100644 compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppressUseless.args create mode 100644 compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppressUseless.out diff --git a/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArgumentsCopyGenerated.kt b/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArgumentsCopyGenerated.kt index 8bcf85ec583..c2aee1ecf81 100644 --- a/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArgumentsCopyGenerated.kt +++ b/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArgumentsCopyGenerated.kt @@ -70,6 +70,7 @@ fun copyCommonCompilerArguments(from: CommonCompilerArguments, to: CommonCompile to.selfUpperBoundInference = from.selfUpperBoundInference to.skipMetadataVersionCheck = from.skipMetadataVersionCheck to.skipPrereleaseCheck = from.skipPrereleaseCheck + to.suppressApiVersionGreaterThanLanguageVersionError = from.suppressApiVersionGreaterThanLanguageVersionError to.suppressVersionWarnings = from.suppressVersionWarnings to.unrestrictedBuilderInference = from.unrestrictedBuilderInference to.useExperimental = from.useExperimental?.copyOf() diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt index dfc4eceebba..224940e537e 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt @@ -562,6 +562,18 @@ Use the 'warning' level to issue warnings instead of errors.""" field = value } + // TODO(KT-56076): remove this argument after stdlib started to be built with 2.0 + @Argument( + value = "-Xsuppress-api-version-greater-than-language-version-error", + description = "Suppress error about API version greater than language version.\n" + + "Warning: This is temporary solution (see KT-63712) intended to be used only for stdlib build." + ) + var suppressApiVersionGreaterThanLanguageVersionError: Boolean = false + set(value) { + checkFrozen() + field = value + } + @Argument( value = "-Xextended-compiler-checks", description = """Enable additional compiler checks that might provide verbose diagnostic information for certain errors. @@ -911,10 +923,14 @@ The corresponding calls' declarations may not be marked with @BuilderInference." collector: MessageCollector ) { if (apiVersion > ApiVersion.createByLanguageVersion(languageVersion)) { - collector.report( - CompilerMessageSeverity.ERROR, - "-api-version (${apiVersion.versionString}) cannot be greater than -language-version (${languageVersion.versionString})" - ) + if (!suppressApiVersionGreaterThanLanguageVersionError) { + collector.report( + CompilerMessageSeverity.ERROR, + "-api-version (${apiVersion.versionString}) cannot be greater than -language-version (${languageVersion.versionString})" + ) + } + } else if (suppressApiVersionGreaterThanLanguageVersionError) { + collector.report(WARNING, "Useless suppress -Xsuppress-api-version-greater-than-language-version-error") } } diff --git a/compiler/testData/cli/js/jsExtraHelp.out b/compiler/testData/cli/js/jsExtraHelp.out index cd4b764662c..ad912c952b2 100644 --- a/compiler/testData/cli/js/jsExtraHelp.out +++ b/compiler/testData/cli/js/jsExtraHelp.out @@ -132,6 +132,9 @@ where advanced options include: -Xself-upper-bound-inference Support inferring type arguments from the self-type upper bounds of the corresponding type parameters. -Xskip-metadata-version-check Allow loading classes with bad metadata versions and pre-release classes. -Xskip-prerelease-check Allow loading pre-release classes. + -Xsuppress-api-version-greater-than-language-version-error + Suppress error about API version greater than language version. + Warning: This is temporary solution (see KT-63712) intended to be used only for stdlib build. -Xsuppress-version-warnings Suppress warnings about outdated, inconsistent, or experimental language or API versions. -Xunrestricted-builder-inference Eliminate builder inference restrictions, for example by allowing type variables to be returned from builder inference calls. diff --git a/compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppress.args b/compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppress.args new file mode 100644 index 00000000000..9ba9490b746 --- /dev/null +++ b/compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppress.args @@ -0,0 +1,8 @@ +$TESTDATA_DIR$/apiVersionGreaterThanLanguageSuppress.kt +-d +$TEMP_DIR$ +-api-version +2.0 +-language-version +1.9 +-Xsuppress-api-version-greater-than-language-version-error \ No newline at end of file diff --git a/compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppress.kt b/compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppress.kt new file mode 100644 index 00000000000..f5510562faa --- /dev/null +++ b/compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppress.kt @@ -0,0 +1,6 @@ +@SinceKotlin("2.0") +fun new() {} + +fun useNew() { + new() +} \ No newline at end of file diff --git a/compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppress.out b/compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppress.out new file mode 100644 index 00000000000..d86bac9de59 --- /dev/null +++ b/compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppress.out @@ -0,0 +1 @@ +OK diff --git a/compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppressUseless.args b/compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppressUseless.args new file mode 100644 index 00000000000..9e9ef66282e --- /dev/null +++ b/compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppressUseless.args @@ -0,0 +1,8 @@ +$TESTDATA_DIR$/apiVersionGreaterThanLanguageSuppress.kt +-d +$TEMP_DIR$ +-api-version +2.0 +-language-version +2.0 +-Xsuppress-api-version-greater-than-language-version-error \ No newline at end of file diff --git a/compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppressUseless.out b/compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppressUseless.out new file mode 100644 index 00000000000..99c64a54ded --- /dev/null +++ b/compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppressUseless.out @@ -0,0 +1,2 @@ +warning: useless suppress -Xsuppress-api-version-greater-than-language-version-error +OK diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index 54cc6bfb1aa..1245a849a10 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -219,6 +219,9 @@ where advanced options include: -Xself-upper-bound-inference Support inferring type arguments from the self-type upper bounds of the corresponding type parameters. -Xskip-metadata-version-check Allow loading classes with bad metadata versions and pre-release classes. -Xskip-prerelease-check Allow loading pre-release classes. + -Xsuppress-api-version-greater-than-language-version-error + Suppress error about API version greater than language version. + Warning: This is temporary solution (see KT-63712) intended to be used only for stdlib build. -Xsuppress-version-warnings Suppress warnings about outdated, inconsistent, or experimental language or API versions. -Xunrestricted-builder-inference Eliminate builder inference restrictions, for example by allowing type variables to be returned from builder inference calls. diff --git a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java index 6f13708b088..994f46d5a6f 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -215,6 +215,16 @@ public class CliTestGenerated extends AbstractCliTest { runTest("compiler/testData/cli/jvm/apiVersionGreaterThanLanguage.args"); } + @TestMetadata("apiVersionGreaterThanLanguageSuppress.args") + public void testApiVersionGreaterThanLanguageSuppress() throws Exception { + runTest("compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppress.args"); + } + + @TestMetadata("apiVersionGreaterThanLanguageSuppressUseless.args") + public void testApiVersionGreaterThanLanguageSuppressUseless() throws Exception { + runTest("compiler/testData/cli/jvm/apiVersionGreaterThanLanguageSuppressUseless.args"); + } + @TestMetadata("apiVersionInvalid.args") public void testApiVersionInvalid() throws Exception { runTest("compiler/testData/cli/jvm/apiVersionInvalid.args");