Skip to content

Commit 7daa9c2

Browse files
ALikhachevSpace Team
authored andcommitted
[BTA] Report unknown enum argument values
1 parent 7ae56a5 commit 7daa9c2

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

compiler/build-tools/kotlin-build-tools-compat/gen/org/jetbrains/kotlin/buildtools/internal/compat/arguments/CommonCompilerArgumentsImpl.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ import org.jetbrains.kotlin.buildtools.`internal`.compat.arguments.CommonCompile
102102
import org.jetbrains.kotlin.buildtools.`internal`.compat.arguments.CommonCompilerArgumentsImpl.Companion.X_VERIFY_IR_VISIBILITY
103103
import org.jetbrains.kotlin.buildtools.`internal`.compat.arguments.CommonCompilerArgumentsImpl.Companion.X_WARNING_LEVEL
104104
import org.jetbrains.kotlin.buildtools.`internal`.compat.arguments.CommonCompilerArgumentsImpl.Companion.X_WHEN_GUARDS
105+
import org.jetbrains.kotlin.buildtools.api.CompilerArgumentsParseException
105106
import org.jetbrains.kotlin.buildtools.api.KotlinReleaseVersion
106107
import org.jetbrains.kotlin.buildtools.api.arguments.ExperimentalCompilerArgument
107108
import org.jetbrains.kotlin.buildtools.api.arguments.enums.ExplicitApiMode
@@ -240,7 +241,7 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
240241
try { this[XX_LANGUAGE] = arguments.manuallyConfiguredFeatures } catch (_: NoSuchMethodError) { }
241242
try { this[XX_DEBUG_LEVEL_COMPILER_CHECKS] = arguments.debugLevelCompilerChecks } catch (_: NoSuchMethodError) { }
242243
try { this[XX_DUMP_MODEL] = arguments.dumpArgumentsDir } catch (_: NoSuchMethodError) { }
243-
try { this[XX_EXPLICIT_RETURN_TYPES] = arguments.explicitReturnTypes.let { ExplicitApiMode.entries.first { entry -> entry.stringValue == it } } } catch (_: NoSuchMethodError) { }
244+
try { this[XX_EXPLICIT_RETURN_TYPES] = arguments.explicitReturnTypes.let { ExplicitApiMode.entries.firstOrNull { entry -> entry.stringValue == it } ?: throw CompilerArgumentsParseException("Unknown -XXexplicit-return-types value: $it") } } catch (_: NoSuchMethodError) { }
244245
try { this[XX_LENIENT_MODE] = arguments.lenientMode } catch (_: NoSuchMethodError) { }
245246
try { this[X_ALLOW_ANY_SCRIPTS_IN_SOURCE_ROOTS] = arguments.allowAnyScriptsInSourceRoots } catch (_: NoSuchMethodError) { }
246247
try { this[X_ALLOW_CONDITION_IMPLIES_RETURNS_CONTRACTS] = arguments.allowConditionImpliesReturnsContracts } catch (_: NoSuchMethodError) { }
@@ -267,7 +268,7 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
267268
try { this[X_DUMP_PERF] = arguments.dumpPerf } catch (_: NoSuchMethodError) { }
268269
try { this[X_ENABLE_INCREMENTAL_COMPILATION] = arguments.incrementalCompilation } catch (_: NoSuchMethodError) { }
269270
try { this[X_EXPECT_ACTUAL_CLASSES] = arguments.expectActualClasses } catch (_: NoSuchMethodError) { }
270-
try { this[X_EXPLICIT_API] = arguments.explicitApi.let { ExplicitApiMode.entries.first { entry -> entry.stringValue == it } } } catch (_: NoSuchMethodError) { }
271+
try { this[X_EXPLICIT_API] = arguments.explicitApi.let { ExplicitApiMode.entries.firstOrNull { entry -> entry.stringValue == it } ?: throw CompilerArgumentsParseException("Unknown -Xexplicit-api value: $it") } } catch (_: NoSuchMethodError) { }
271272
try { this[X_FRAGMENT_DEPENDENCY] = arguments.fragmentDependencies } catch (_: NoSuchMethodError) { }
272273
try { this[X_FRAGMENT_REFINES] = arguments.fragmentRefines } catch (_: NoSuchMethodError) { }
273274
try { this[X_FRAGMENT_SOURCES] = arguments.fragmentSources } catch (_: NoSuchMethodError) { }
@@ -298,7 +299,7 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
298299
try { this[X_REPORT_ALL_WARNINGS] = arguments.reportAllWarnings } catch (_: NoSuchMethodError) { }
299300
try { this[X_REPORT_OUTPUT_FILES] = arguments.reportOutputFiles } catch (_: NoSuchMethodError) { }
300301
try { this[X_REPORT_PERF] = arguments.reportPerf } catch (_: NoSuchMethodError) { }
301-
try { this[X_RETURN_VALUE_CHECKER] = arguments.returnValueChecker.let { ReturnValueCheckerMode.entries.first { entry -> entry.stringValue == it } } } catch (_: NoSuchMethodError) { }
302+
try { this[X_RETURN_VALUE_CHECKER] = arguments.returnValueChecker.let { ReturnValueCheckerMode.entries.firstOrNull { entry -> entry.stringValue == it } ?: throw CompilerArgumentsParseException("Unknown -Xreturn-value-checker value: $it") } } catch (_: NoSuchMethodError) { }
302303
try { this[X_SEPARATE_KMP_COMPILATION] = arguments.separateKmpCompilationScheme } catch (_: NoSuchMethodError) { }
303304
try { this[X_SKIP_METADATA_VERSION_CHECK] = arguments.skipMetadataVersionCheck } catch (_: NoSuchMethodError) { }
304305
try { this[X_SKIP_PRERELEASE_CHECK] = arguments.skipPrereleaseCheck } catch (_: NoSuchMethodError) { }
@@ -316,9 +317,9 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
316317
try { this[X_VERIFY_IR_VISIBILITY] = arguments.verifyIrVisibility } catch (_: NoSuchMethodError) { }
317318
try { this[X_WARNING_LEVEL] = arguments.warningLevels } catch (_: NoSuchMethodError) { }
318319
try { this[X_WHEN_GUARDS] = arguments.whenGuards } catch (_: NoSuchMethodError) { }
319-
try { this[API_VERSION] = arguments.apiVersion?.let { KotlinVersion.entries.first { entry -> entry.stringValue == it } } } catch (_: NoSuchMethodError) { }
320+
try { this[API_VERSION] = arguments.apiVersion?.let { KotlinVersion.entries.firstOrNull { entry -> entry.stringValue == it } ?: throw CompilerArgumentsParseException("Unknown -api-version value: $it") } } catch (_: NoSuchMethodError) { }
320321
try { this[KOTLIN_HOME] = arguments.kotlinHome } catch (_: NoSuchMethodError) { }
321-
try { this[LANGUAGE_VERSION] = arguments.languageVersion?.let { KotlinVersion.entries.first { entry -> entry.stringValue == it } } } catch (_: NoSuchMethodError) { }
322+
try { this[LANGUAGE_VERSION] = arguments.languageVersion?.let { KotlinVersion.entries.firstOrNull { entry -> entry.stringValue == it } ?: throw CompilerArgumentsParseException("Unknown -language-version value: $it") } } catch (_: NoSuchMethodError) { }
322323
try { this[OPT_IN] = arguments.optIn } catch (_: NoSuchMethodError) { }
323324
try { this[PROGRESSIVE] = arguments.progressiveMode } catch (_: NoSuchMethodError) { }
324325
try { this[SCRIPT] = arguments.script } catch (_: NoSuchMethodError) { }

compiler/build-tools/kotlin-build-tools-compat/gen/org/jetbrains/kotlin/buildtools/internal/compat/arguments/JvmCompilerArgumentsImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ internal class JvmCompilerArgumentsImpl : CommonCompilerArgumentsImpl(), JvmComp
295295
try { this[JAVA_PARAMETERS] = arguments.javaParameters } catch (_: NoSuchMethodError) { }
296296
try { this[JDK_HOME] = arguments.jdkHome } catch (_: NoSuchMethodError) { }
297297
try { this[JVM_DEFAULT] = arguments.jvmDefaultStable } catch (_: NoSuchMethodError) { }
298-
try { this[JVM_TARGET] = arguments.jvmTarget?.let { JvmTarget.entries.first { entry -> entry.stringValue == it } } } catch (_: NoSuchMethodError) { }
298+
try { this[JVM_TARGET] = arguments.jvmTarget?.let { JvmTarget.entries.firstOrNull { entry -> entry.stringValue == it } ?: throw CompilerArgumentsParseException("Unknown -jvm-target value: $it") } } catch (_: NoSuchMethodError) { }
299299
try { this[MODULE_NAME] = arguments.moduleName } catch (_: NoSuchMethodError) { }
300300
try { this[NO_JDK] = arguments.noJdk } catch (_: NoSuchMethodError) { }
301301
try { this[NO_REFLECT] = arguments.noReflect } catch (_: NoSuchMethodError) { }

compiler/build-tools/kotlin-build-tools-impl/gen/org/jetbrains/kotlin/buildtools/internal/arguments/CommonCompilerArgumentsImpl.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgume
108108
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_VERIFY_IR_VISIBILITY
109109
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_WARNING_LEVEL
110110
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_WHEN_GUARDS
111+
import org.jetbrains.kotlin.buildtools.api.CompilerArgumentsParseException
111112
import org.jetbrains.kotlin.buildtools.api.KotlinReleaseVersion
112113
import org.jetbrains.kotlin.buildtools.api.arguments.ExperimentalCompilerArgument
113114
import org.jetbrains.kotlin.buildtools.api.arguments.enums.ExplicitApiMode
@@ -253,7 +254,7 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
253254
try { this[XX_LANGUAGE] = arguments.manuallyConfiguredFeatures } catch (_: NoSuchMethodError) { }
254255
try { this[XX_DEBUG_LEVEL_COMPILER_CHECKS] = arguments.debugLevelCompilerChecks } catch (_: NoSuchMethodError) { }
255256
try { this[XX_DUMP_MODEL] = arguments.dumpArgumentsDir } catch (_: NoSuchMethodError) { }
256-
try { this[XX_EXPLICIT_RETURN_TYPES] = arguments.explicitReturnTypes.let { ExplicitApiMode.entries.first { entry -> entry.stringValue == it } } } catch (_: NoSuchMethodError) { }
257+
try { this[XX_EXPLICIT_RETURN_TYPES] = arguments.explicitReturnTypes.let { ExplicitApiMode.entries.firstOrNull { entry -> entry.stringValue == it } ?: throw CompilerArgumentsParseException("Unknown -XXexplicit-return-types value: $it") } } catch (_: NoSuchMethodError) { }
257258
try { this[XX_LENIENT_MODE] = arguments.lenientMode } catch (_: NoSuchMethodError) { }
258259
try { this[X_ALLOW_ANY_SCRIPTS_IN_SOURCE_ROOTS] = arguments.allowAnyScriptsInSourceRoots } catch (_: NoSuchMethodError) { }
259260
try { this[X_ALLOW_CONDITION_IMPLIES_RETURNS_CONTRACTS] = arguments.allowConditionImpliesReturnsContracts } catch (_: NoSuchMethodError) { }
@@ -282,7 +283,7 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
282283
try { this[X_DUMP_PERF] = arguments.dumpPerf } catch (_: NoSuchMethodError) { }
283284
try { this[X_ENABLE_INCREMENTAL_COMPILATION] = arguments.incrementalCompilation } catch (_: NoSuchMethodError) { }
284285
try { this[X_EXPECT_ACTUAL_CLASSES] = arguments.expectActualClasses } catch (_: NoSuchMethodError) { }
285-
try { this[X_EXPLICIT_API] = arguments.explicitApi.let { ExplicitApiMode.entries.first { entry -> entry.stringValue == it } } } catch (_: NoSuchMethodError) { }
286+
try { this[X_EXPLICIT_API] = arguments.explicitApi.let { ExplicitApiMode.entries.firstOrNull { entry -> entry.stringValue == it } ?: throw CompilerArgumentsParseException("Unknown -Xexplicit-api value: $it") } } catch (_: NoSuchMethodError) { }
286287
try { this[X_EXPLICIT_BACKING_FIELDS] = arguments.explicitBackingFields } catch (_: NoSuchMethodError) { }
287288
try { this[X_FRAGMENT_DEPENDENCY] = arguments.fragmentDependencies } catch (_: NoSuchMethodError) { }
288289
try { this[X_FRAGMENT_FRIEND_DEPENDENCY] = arguments.fragmentFriendDependencies } catch (_: NoSuchMethodError) { }
@@ -316,7 +317,7 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
316317
try { this[X_REPORT_ALL_WARNINGS] = arguments.reportAllWarnings } catch (_: NoSuchMethodError) { }
317318
try { this[X_REPORT_OUTPUT_FILES] = arguments.reportOutputFiles } catch (_: NoSuchMethodError) { }
318319
try { this[X_REPORT_PERF] = arguments.reportPerf } catch (_: NoSuchMethodError) { }
319-
try { this[X_RETURN_VALUE_CHECKER] = arguments.returnValueChecker.let { ReturnValueCheckerMode.entries.first { entry -> entry.stringValue == it } } } catch (_: NoSuchMethodError) { }
320+
try { this[X_RETURN_VALUE_CHECKER] = arguments.returnValueChecker.let { ReturnValueCheckerMode.entries.firstOrNull { entry -> entry.stringValue == it } ?: throw CompilerArgumentsParseException("Unknown -Xreturn-value-checker value: $it") } } catch (_: NoSuchMethodError) { }
320321
try { this[X_SEPARATE_KMP_COMPILATION] = arguments.separateKmpCompilationScheme } catch (_: NoSuchMethodError) { }
321322
try { this[X_SKIP_METADATA_VERSION_CHECK] = arguments.skipMetadataVersionCheck } catch (_: NoSuchMethodError) { }
322323
try { this[X_SKIP_PRERELEASE_CHECK] = arguments.skipPrereleaseCheck } catch (_: NoSuchMethodError) { }
@@ -334,9 +335,9 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
334335
try { this[X_VERIFY_IR_VISIBILITY] = arguments.verifyIrVisibility } catch (_: NoSuchMethodError) { }
335336
try { this[X_WARNING_LEVEL] = arguments.warningLevels } catch (_: NoSuchMethodError) { }
336337
try { this[X_WHEN_GUARDS] = arguments.whenGuards } catch (_: NoSuchMethodError) { }
337-
try { this[API_VERSION] = arguments.apiVersion?.let { KotlinVersion.entries.first { entry -> entry.stringValue == it } } } catch (_: NoSuchMethodError) { }
338+
try { this[API_VERSION] = arguments.apiVersion?.let { KotlinVersion.entries.firstOrNull { entry -> entry.stringValue == it } ?: throw CompilerArgumentsParseException("Unknown -api-version value: $it") } } catch (_: NoSuchMethodError) { }
338339
try { this[KOTLIN_HOME] = arguments.kotlinHome } catch (_: NoSuchMethodError) { }
339-
try { this[LANGUAGE_VERSION] = arguments.languageVersion?.let { KotlinVersion.entries.first { entry -> entry.stringValue == it } } } catch (_: NoSuchMethodError) { }
340+
try { this[LANGUAGE_VERSION] = arguments.languageVersion?.let { KotlinVersion.entries.firstOrNull { entry -> entry.stringValue == it } ?: throw CompilerArgumentsParseException("Unknown -language-version value: $it") } } catch (_: NoSuchMethodError) { }
340341
try { this[OPT_IN] = arguments.optIn } catch (_: NoSuchMethodError) { }
341342
try { this[PROGRESSIVE] = arguments.progressiveMode } catch (_: NoSuchMethodError) { }
342343
try { this[SCRIPT] = arguments.script } catch (_: NoSuchMethodError) { }

compiler/build-tools/kotlin-build-tools-impl/gen/org/jetbrains/kotlin/buildtools/internal/arguments/JvmCompilerArgumentsImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ internal class JvmCompilerArgumentsImpl : CommonCompilerArgumentsImpl(), JvmComp
298298
try { this[JAVA_PARAMETERS] = arguments.javaParameters } catch (_: NoSuchMethodError) { }
299299
try { this[JDK_HOME] = arguments.jdkHome } catch (_: NoSuchMethodError) { }
300300
try { this[JVM_DEFAULT] = arguments.jvmDefaultStable } catch (_: NoSuchMethodError) { }
301-
try { this[JVM_TARGET] = arguments.jvmTarget?.let { JvmTarget.entries.first { entry -> entry.stringValue == it } } } catch (_: NoSuchMethodError) { }
301+
try { this[JVM_TARGET] = arguments.jvmTarget?.let { JvmTarget.entries.firstOrNull { entry -> entry.stringValue == it } ?: throw CompilerArgumentsParseException("Unknown -jvm-target value: $it") } } catch (_: NoSuchMethodError) { }
302302
try { this[MODULE_NAME] = arguments.moduleName } catch (_: NoSuchMethodError) { }
303303
try { this[NO_JDK] = arguments.noJdk } catch (_: NoSuchMethodError) { }
304304
try { this[NO_REFLECT] = arguments.noReflect } catch (_: NoSuchMethodError) { }

compiler/build-tools/kotlin-build-tools-options-generator/src/org/jetbrains/kotlin/buildtools/options/generator/BtaImplGenerator.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,11 @@ internal class BtaImplGenerator(
205205
when {
206206
type.classifier in enumNameAccessors -> {
207207
add(maybeGetNullabilitySign(argument))
208-
add(".let { %T.entries.first { entry -> entry.stringValue == it } }", argumentTypeParameter.copy(nullable = false))
208+
add(
209+
$$".let { %T.entries.firstOrNull { entry -> entry.stringValue == it } ?: throw %M(\"Unknown -$${argument.name} value: $it\") }",
210+
argumentTypeParameter.copy(nullable = false),
211+
MemberName("org.jetbrains.kotlin.buildtools.api", "CompilerArgumentsParseException"),
212+
)
209213
}
210214
argument.valueType is IntType -> {
211215
add(maybeGetNullabilitySign(argument))

0 commit comments

Comments
 (0)