diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonToolArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonToolArguments.kt index ddf21dde214..740dab7b539 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonToolArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonToolArguments.kt @@ -27,7 +27,7 @@ abstract class CommonToolArguments : Freezable(), Serializable { var freeArgs: List by FreezableVar(emptyList()) @Transient - var errors: ArgumentParseErrors = ArgumentParseErrors() + var errors: ArgumentParseErrors? = null @Argument(value = "-help", shortName = "-h", description = "Print a synopsis of standard options") var help: Boolean by FreezableVar(false) diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/parseCommandLineArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/parseCommandLineArguments.kt index 7a2d40d83c5..e38bdb3be52 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/parseCommandLineArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/parseCommandLineArguments.kt @@ -38,12 +38,12 @@ private const val ADVANCED_ARGUMENT_PREFIX = "-X" private const val FREE_ARGS_DELIMITER = "--" data class ArgumentParseErrors( - val unknownArgs: MutableList = SmartList(), + val unknownArgs: MutableList = SmartList(), - val unknownExtraFlags: MutableList = SmartList(), + val unknownExtraFlags: MutableList = SmartList(), // Names of extra (-X...) arguments which have been passed in an obsolete form ("-Xaaa bbb", instead of "-Xaaa=bbb") - val extraArgumentsPassedInObsoleteForm: MutableList = SmartList(), + val extraArgumentsPassedInObsoleteForm: MutableList = SmartList(), // Non-boolean arguments which have been passed multiple times, possibly with different values. // The key in the map is the name of the argument, the value is the last passed value. @@ -62,11 +62,12 @@ data class ArgumentParseErrors( // Parses arguments into the passed [result] object. Errors related to the parsing will be collected into [CommonToolArguments.errors]. fun parseCommandLineArguments(args: List, result: A) { - val preprocessed = preprocessCommandLineArguments(args, result.errors) - parsePreprocessedCommandLineArguments(preprocessed, result) + val errors = result.errors ?: ArgumentParseErrors().also { result.errors = it } + val preprocessed = preprocessCommandLineArguments(args, errors) + parsePreprocessedCommandLineArguments(preprocessed, result, errors) } -private fun parsePreprocessedCommandLineArguments(args: List, result: A) { +private fun parsePreprocessedCommandLineArguments(args: List, result: A, errors: ArgumentParseErrors) { data class ArgumentField(val property: KMutableProperty1, val argument: Argument) @Suppress("UNCHECKED_CAST") @@ -76,7 +77,6 @@ private fun parsePreprocessedCommandLineArguments(args ArgumentField(property as KMutableProperty1, argument) } - val errors = result.errors val visitedArgs = mutableSetOf() var freeArgsStarted = false @@ -198,7 +198,8 @@ private fun updateField(property: KMutableProperty1 { } private fun reportArgumentParseProblems(collector: MessageCollector, arguments: A) { - val errors = arguments.errors + reportUnsafeInternalArgumentsIfAny(arguments, collector) + + val errors = arguments.errors ?: return + for (flag in errors.unknownExtraFlags) { collector.report(STRONG_WARNING, "Flag is not supported by this version of the compiler: $flag") } @@ -139,7 +142,6 @@ abstract class CLITool { collector.report(STRONG_WARNING, argfileError) } - reportUnsafeInternalArgumentsIfAny(arguments, collector) for (internalArgumentsError in errors.internalArgumentsParsingProblems) { collector.report(STRONG_WARNING, internalArgumentsError) }