diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt index fda5872a290..b3332977bae 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt @@ -505,6 +505,12 @@ default: `indy-with-constants` for JVM target 9 or greater, `inline` otherwise"" ) var validateBytecode: Boolean by FreezableVar(false) + @Argument( + value = "-Xenhance-type-parameter-types-to-def-not-null", + description = "Enhance not null annotated type parameter's types to definitely not null types (@NotNull T => T & Any)" + ) + var enhanceTypeParameterTypesToDefNotNull: Boolean by FreezableVar(false) + override fun configureAnalysisFlags(collector: MessageCollector, languageVersion: LanguageVersion): MutableMap, Any> { val result = super.configureAnalysisFlags(collector, languageVersion) result[JvmAnalysisFlags.strictMetadataVersionSemantics] = strictMetadataVersionSemantics @@ -533,6 +539,10 @@ default: `indy-with-constants` for JVM target 9 or greater, `inline` otherwise"" if (typeEnhancementImprovementsInStrictMode) { result[LanguageFeature.TypeEnhancementImprovementsInStrictMode] = LanguageFeature.State.ENABLED } + if (enhanceTypeParameterTypesToDefNotNull) { + result[LanguageFeature.ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated] = LanguageFeature.State.ENABLED + } + return result } diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index 23393ecad17..06b78e98bf5 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -27,6 +27,8 @@ where advanced options include: -Xemit-jvm-type-annotations Emit JVM type annotations in bytecode -Xjvm-enable-preview Allow using features from Java language that are in preview phase. Works as `--enable-preview` in Java. All class files are marked as preview-generated thus it won't be possible to use them in release environment + -Xenhance-type-parameter-types-to-def-not-null + Enhance not null annotated type parameter's types to definitely not null types (@NotNull T => T & Any) -Xfriend-paths= Paths to output directories for friend modules (whose internals should be visible) -Xmultifile-parts-inherit Compile multifile classes as a hierarchy of parts and facade -Xmodule-path= Paths where to find Java 9+ modules diff --git a/compiler/testData/cli/jvm/kt49209.args b/compiler/testData/cli/jvm/kt49209.args new file mode 100644 index 00000000000..7f6c6180daf --- /dev/null +++ b/compiler/testData/cli/jvm/kt49209.args @@ -0,0 +1,6 @@ +-Xenhance-type-parameter-types-to-def-not-null +$TESTDATA_DIR$/kt49209.kt +$TESTDATA_DIR$/kt49209 +$FOREIGN_JAVA8_ANNOTATIONS_DIR$ +-d +$TEMP_DIR$ diff --git a/compiler/testData/cli/jvm/kt49209.kt b/compiler/testData/cli/jvm/kt49209.kt new file mode 100644 index 00000000000..29c237fe5db --- /dev/null +++ b/compiler/testData/cli/jvm/kt49209.kt @@ -0,0 +1,2 @@ +fun usingMethod(java : Java) : String = java.getFoo() +fun usingProperty(java : Java) : String = java.foo diff --git a/compiler/testData/cli/jvm/kt49209.out b/compiler/testData/cli/jvm/kt49209.out new file mode 100644 index 00000000000..d86bac9de59 --- /dev/null +++ b/compiler/testData/cli/jvm/kt49209.out @@ -0,0 +1 @@ +OK diff --git a/compiler/testData/cli/jvm/kt49209/Java.java b/compiler/testData/cli/jvm/kt49209/Java.java new file mode 100644 index 00000000000..2b72934a028 --- /dev/null +++ b/compiler/testData/cli/jvm/kt49209/Java.java @@ -0,0 +1,6 @@ +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; + +public interface Java { + @NonNull T getFoo(); +} diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/cli/AbstractCliTest.java b/compiler/tests-common/tests/org/jetbrains/kotlin/cli/AbstractCliTest.java index b2090266a91..4c211c4417b 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/cli/AbstractCliTest.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/cli/AbstractCliTest.java @@ -263,6 +263,10 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir { .replace( "$FOREIGN_ANNOTATIONS_DIR$", new File(ThirdPartyAnnotationPathsKt.FOREIGN_ANNOTATIONS_SOURCES_PATH).getPath() + ) + .replace( + "$FOREIGN_JAVA8_ANNOTATIONS_DIR$", + new File(ThirdPartyAnnotationPathsKt.FOREIGN_JDK8_ANNOTATIONS_SOURCES_PATH).getPath() ).replace( "$JDK_17$", KtTestUtil.getJdk17Home().getPath() diff --git a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java index 841932cbf06..662809831dc 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -631,6 +631,11 @@ public class CliTestGenerated extends AbstractCliTest { runTest("compiler/testData/cli/jvm/kt22304.args"); } + @TestMetadata("kt49209.args") + public void testKt49209() throws Exception { + runTest("compiler/testData/cli/jvm/kt49209.args"); + } + @TestMetadata("languageVersion.args") public void testLanguageVersion() throws Exception { runTest("compiler/testData/cli/jvm/languageVersion.args");