Add fallback flag for legacy var smart casts after try #KT-21377 Fixed
This commit is contained in:
+6
@@ -112,6 +112,12 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
|
||||
)
|
||||
var newInference: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(
|
||||
value = "-Xlegacy-smart-cast-after-try",
|
||||
description = "Allow var smart casts despite assignment in try block"
|
||||
)
|
||||
var legacySmartCastAfterTry by FreezableVar(false)
|
||||
|
||||
open fun configureAnalysisFlags(collector: MessageCollector): MutableMap<AnalysisFlag<*>, Any> {
|
||||
return HashMap<AnalysisFlag<*>, Any>().apply {
|
||||
put(AnalysisFlag.skipMetadataVersionCheck, skipMetadataVersionCheck)
|
||||
|
||||
@@ -208,6 +208,10 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> extends CLI
|
||||
extraLanguageFeatures.put(LanguageFeature.NewInference, LanguageFeature.State.ENABLED);
|
||||
}
|
||||
|
||||
if (arguments.getLegacySmartCastAfterTry()) {
|
||||
extraLanguageFeatures.put(LanguageFeature.SoundSmartCastsAfterTry, LanguageFeature.State.DISABLED);
|
||||
}
|
||||
|
||||
setupPlatformSpecificLanguageFeatureSettings(extraLanguageFeatures, arguments);
|
||||
|
||||
CommonConfigurationKeysKt.setLanguageVersionSettings(configuration, new LanguageVersionSettingsImpl(
|
||||
|
||||
+1
@@ -7,6 +7,7 @@ where advanced options include:
|
||||
-Xcoroutines={enable|warn|error}
|
||||
Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier
|
||||
-Xintellij-plugin-root=<path> Path to the kotlin-compiler.jar or directory where IntelliJ configuration files can be found
|
||||
-Xlegacy-smart-cast-after-try Allow var smart casts despite assignment in try block
|
||||
-Xmulti-platform Enable experimental language support for multi-platform projects
|
||||
-Xnew-inference Enable new experimental generic type inference algorithm
|
||||
-Xno-check-actual Do not check presence of 'actual' modifier in multi-platform projects
|
||||
|
||||
+1
@@ -34,6 +34,7 @@ where advanced options include:
|
||||
-Xcoroutines={enable|warn|error}
|
||||
Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier
|
||||
-Xintellij-plugin-root=<path> Path to the kotlin-compiler.jar or directory where IntelliJ configuration files can be found
|
||||
-Xlegacy-smart-cast-after-try Allow var smart casts despite assignment in try block
|
||||
-Xmulti-platform Enable experimental language support for multi-platform projects
|
||||
-Xnew-inference Enable new experimental generic type inference algorithm
|
||||
-Xno-check-actual Do not check presence of 'actual' modifier in multi-platform projects
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
$TESTDATA_DIR$/legacySmartCastsAfterTry.kt
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
-Xlegacy-smart-cast-after-try
|
||||
@@ -0,0 +1,9 @@
|
||||
fun foo() {
|
||||
var some: String? = null
|
||||
some = "alpha"
|
||||
try {
|
||||
some = "omega"
|
||||
}
|
||||
catch (e: Exception) {}
|
||||
some.length
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
compiler/testData/cli/jvm/legacySmartCastsAfterTry.kt:2:25: warning: variable 'some' initializer is redundant
|
||||
var some: String? = null
|
||||
^
|
||||
OK
|
||||
@@ -338,6 +338,12 @@ public class CliTestGenerated extends AbstractCliTest {
|
||||
doJvmTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("legacySmartCastsAfterTry.args")
|
||||
public void testLegacySmartCastsAfterTry() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/legacySmartCastsAfterTry.args");
|
||||
doJvmTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("multipleTextRangesInDiagnosticsOrder.args")
|
||||
public void testMultipleTextRangesInDiagnosticsOrder() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/multipleTextRangesInDiagnosticsOrder.args");
|
||||
|
||||
Reference in New Issue
Block a user