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 cce917df61a..96d8525148f 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 @@ -365,6 +365,12 @@ abstract class CommonCompilerArguments : CommonToolArguments() { ) var extendedCompilerChecks: Boolean by FreezableVar(false) + @Argument( + value = "-Xunrestricted-builder-inference", + description = "Eliminate builder inference restrictions like allowance of returning type variables of a builder inference call" + ) + var unrestrictedBuilderInference: Boolean by FreezableVar(false) + open fun configureAnalysisFlags(collector: MessageCollector, languageVersion: LanguageVersion): MutableMap, Any> { return HashMap, Any>().apply { put(AnalysisFlags.skipMetadataVersionCheck, skipMetadataVersionCheck) @@ -394,6 +400,10 @@ abstract class CommonCompilerArguments : CommonToolArguments() { put(LanguageFeature.MultiPlatformProjects, LanguageFeature.State.ENABLED) } + if (unrestrictedBuilderInference) { + put(LanguageFeature.UnrestrictedBuilderInference, LanguageFeature.State.ENABLED) + } + if (newInference) { put(LanguageFeature.NewInference, LanguageFeature.State.ENABLED) put(LanguageFeature.SamConversionPerArgument, LanguageFeature.State.ENABLED) diff --git a/compiler/testData/cli/js/jsExtraHelp.out b/compiler/testData/cli/js/jsExtraHelp.out index e8fee8f4628..02e0f0f0109 100644 --- a/compiler/testData/cli/js/jsExtraHelp.out +++ b/compiler/testData/cli/js/jsExtraHelp.out @@ -84,6 +84,8 @@ where advanced options include: -Xskip-metadata-version-check Allow to load classes with bad metadata version and pre-release classes -Xskip-prerelease-check Allow to load pre-release classes -Xsuppress-version-warnings Suppress warnings about outdated, inconsistent or experimental language or API versions + -Xunrestricted-builder-inference + Eliminate builder inference restrictions like allowance of returning type variables of a builder inference call -Xuse-experimental= Enable, but don't propagate usages of experimental API for marker annotation with the given fully qualified name -Xuse-fir Compile using Front-end IR. Warning: this feature is far from being production-ready -Xuse-fir-extended-checkers Use extended analysis mode based on Front-end IR. Warning: this feature is far from being production-ready diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index 0032ef30011..163f5a686a5 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -194,6 +194,8 @@ where advanced options include: -Xskip-metadata-version-check Allow to load classes with bad metadata version and pre-release classes -Xskip-prerelease-check Allow to load pre-release classes -Xsuppress-version-warnings Suppress warnings about outdated, inconsistent or experimental language or API versions + -Xunrestricted-builder-inference + Eliminate builder inference restrictions like allowance of returning type variables of a builder inference call -Xuse-experimental= Enable, but don't propagate usages of experimental API for marker annotation with the given fully qualified name -Xuse-fir Compile using Front-end IR. Warning: this feature is far from being production-ready -Xuse-fir-extended-checkers Use extended analysis mode based on Front-end IR. Warning: this feature is far from being production-ready diff --git a/compiler/testData/cli/jvm/unrestrictedBuilderInference.args b/compiler/testData/cli/jvm/unrestrictedBuilderInference.args new file mode 100644 index 00000000000..4bea4537a9d --- /dev/null +++ b/compiler/testData/cli/jvm/unrestrictedBuilderInference.args @@ -0,0 +1,5 @@ +$TESTDATA_DIR$/unrestrictedBuilderInference.kt +-d +$TEMP_DIR$ +-Xunrestricted-builder-inference +-Xopt-in=kotlin.RequiresOptIn diff --git a/compiler/testData/cli/jvm/unrestrictedBuilderInference.kt b/compiler/testData/cli/jvm/unrestrictedBuilderInference.kt new file mode 100644 index 00000000000..500c59b7632 --- /dev/null +++ b/compiler/testData/cli/jvm/unrestrictedBuilderInference.kt @@ -0,0 +1,6 @@ +@OptIn(ExperimentalStdlibApi::class) +fun main() { + val x = buildMap { + val y = put(1, "") + } +} diff --git a/compiler/testData/cli/jvm/unrestrictedBuilderInference.out b/compiler/testData/cli/jvm/unrestrictedBuilderInference.out new file mode 100644 index 00000000000..a2803e584f6 --- /dev/null +++ b/compiler/testData/cli/jvm/unrestrictedBuilderInference.out @@ -0,0 +1,7 @@ +compiler/testData/cli/jvm/unrestrictedBuilderInference.kt:3:9: warning: variable 'x' is never used + val x = buildMap { + ^ +compiler/testData/cli/jvm/unrestrictedBuilderInference.kt:4:13: warning: variable 'y' is never used + val y = put(1, "") + ^ +OK diff --git a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java index a131e170b5c..6c68783c18d 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -836,6 +836,11 @@ public class CliTestGenerated extends AbstractCliTest { runTest("compiler/testData/cli/jvm/unknownExtraFlags.args"); } + @TestMetadata("unrestrictedBuilderInference.args") + public void testUnrestrictedBuilderInference() throws Exception { + runTest("compiler/testData/cli/jvm/unrestrictedBuilderInference.args"); + } + @TestMetadata("useDeclarationThatWasExperimentalWithoutExplicitImport.args") public void testUseDeclarationThatWasExperimentalWithoutExplicitImport() throws Exception { runTest("compiler/testData/cli/jvm/useDeclarationThatWasExperimentalWithoutExplicitImport.args");