K2: introduce JavaTypeParameterDefaultRepresentationWithDNN exp. feature

#KT-66447 Fixed
This commit is contained in:
Mikhail Glukhikh
2024-03-11 18:09:43 +01:00
committed by Space Team
parent 4464385fa9
commit cd20f31810
35 changed files with 627 additions and 6 deletions
@@ -21828,12 +21828,24 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/j+k/flexibleTypeVariablePosition.kt");
}
@Test
@TestMetadata("flexibleTypeVariablePositionDnnRepresentation.kt")
public void testFlexibleTypeVariablePositionDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/j+k/flexibleTypeVariablePositionDnnRepresentation.kt");
}
@Test
@TestMetadata("futureGet.kt")
public void testFutureGet() {
runTest("compiler/testData/diagnostics/tests/j+k/futureGet.kt");
}
@Test
@TestMetadata("futureGetDnnRepresentation.kt")
public void testFutureGetDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/j+k/futureGetDnnRepresentation.kt");
}
@Test
@TestMetadata("genericConstructorWithMultipleBounds.kt")
public void testGenericConstructorWithMultipleBounds() {
@@ -22110,6 +22122,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/j+k/nullableLinkedListToQueue.kt");
}
@Test
@TestMetadata("nullableLinkedListToQueueDnnRepresentation.kt")
public void testNullableLinkedListToQueueDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/j+k/nullableLinkedListToQueueDnnRepresentation.kt");
}
@Test
@TestMetadata("nullableRawTypeWithFlexibleArguments.kt")
public void testNullableRawTypeWithFlexibleArguments() {
@@ -23163,6 +23181,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullable.kt");
}
@Test
@TestMetadata("notNullTypeParameterWithKotlinNullableDnnRepresentation.kt")
public void testNotNullTypeParameterWithKotlinNullableDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullableDnnRepresentation.kt");
}
@Test
@TestMetadata("notNullTypeParameterWithKotlinNullableWarnings.kt")
public void testNotNullTypeParameterWithKotlinNullableWarnings() {
@@ -28692,6 +28716,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/override/dnnOverridesFlexible.kt");
}
@Test
@TestMetadata("dnnOverridesFlexibleDnnRepresentation.kt")
public void testDnnOverridesFlexibleDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/override/dnnOverridesFlexibleDnnRepresentation.kt");
}
@Test
@TestMetadata("DuplicateMethod.kt")
public void testDuplicateMethod() {
@@ -29304,6 +29334,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/platformTypes/comparingWithWrongNullability.kt");
}
@Test
@TestMetadata("comparingWithWrongNullabilityDnnRepresentation.kt")
public void testComparingWithWrongNullabilityDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/platformTypes/comparingWithWrongNullabilityDnnRepresentation.kt");
}
@Test
@TestMetadata("delegateByComplexInheritance.kt")
public void testDelegateByComplexInheritance() {
@@ -29693,6 +29729,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/platformTypes/methodCall/singleton.kt");
}
@Test
@TestMetadata("singletonDnnRepresentation.kt")
public void testSingletonDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/platformTypes/methodCall/singletonDnnRepresentation.kt");
}
@Test
@TestMetadata("string.kt")
public void testString() {
@@ -33204,6 +33246,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/samConversions/sameCandidatesFromKotlinAndJavaInOneScope.kt");
}
@Test
@TestMetadata("sameConversionToGenericWrongNullabilityDnnRepresentation.kt")
public void testSameConversionToGenericWrongNullabilityDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/samConversions/sameConversionToGenericWrongNullabilityDnnRepresentation.kt");
}
@Test
@TestMetadata("SimpleCorrect.kt")
public void testSimpleCorrect() {
@@ -21828,12 +21828,24 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/j+k/flexibleTypeVariablePosition.kt");
}
@Test
@TestMetadata("flexibleTypeVariablePositionDnnRepresentation.kt")
public void testFlexibleTypeVariablePositionDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/j+k/flexibleTypeVariablePositionDnnRepresentation.kt");
}
@Test
@TestMetadata("futureGet.kt")
public void testFutureGet() {
runTest("compiler/testData/diagnostics/tests/j+k/futureGet.kt");
}
@Test
@TestMetadata("futureGetDnnRepresentation.kt")
public void testFutureGetDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/j+k/futureGetDnnRepresentation.kt");
}
@Test
@TestMetadata("genericConstructorWithMultipleBounds.kt")
public void testGenericConstructorWithMultipleBounds() {
@@ -22110,6 +22122,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/j+k/nullableLinkedListToQueue.kt");
}
@Test
@TestMetadata("nullableLinkedListToQueueDnnRepresentation.kt")
public void testNullableLinkedListToQueueDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/j+k/nullableLinkedListToQueueDnnRepresentation.kt");
}
@Test
@TestMetadata("nullableRawTypeWithFlexibleArguments.kt")
public void testNullableRawTypeWithFlexibleArguments() {
@@ -23163,6 +23181,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullable.kt");
}
@Test
@TestMetadata("notNullTypeParameterWithKotlinNullableDnnRepresentation.kt")
public void testNotNullTypeParameterWithKotlinNullableDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullableDnnRepresentation.kt");
}
@Test
@TestMetadata("notNullTypeParameterWithKotlinNullableWarnings.kt")
public void testNotNullTypeParameterWithKotlinNullableWarnings() {
@@ -28692,6 +28716,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/override/dnnOverridesFlexible.kt");
}
@Test
@TestMetadata("dnnOverridesFlexibleDnnRepresentation.kt")
public void testDnnOverridesFlexibleDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/override/dnnOverridesFlexibleDnnRepresentation.kt");
}
@Test
@TestMetadata("DuplicateMethod.kt")
public void testDuplicateMethod() {
@@ -29304,6 +29334,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/platformTypes/comparingWithWrongNullability.kt");
}
@Test
@TestMetadata("comparingWithWrongNullabilityDnnRepresentation.kt")
public void testComparingWithWrongNullabilityDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/platformTypes/comparingWithWrongNullabilityDnnRepresentation.kt");
}
@Test
@TestMetadata("delegateByComplexInheritance.kt")
public void testDelegateByComplexInheritance() {
@@ -29693,6 +29729,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/platformTypes/methodCall/singleton.kt");
}
@Test
@TestMetadata("singletonDnnRepresentation.kt")
public void testSingletonDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/platformTypes/methodCall/singletonDnnRepresentation.kt");
}
@Test
@TestMetadata("string.kt")
public void testString() {
@@ -33204,6 +33246,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/samConversions/sameCandidatesFromKotlinAndJavaInOneScope.kt");
}
@Test
@TestMetadata("sameConversionToGenericWrongNullabilityDnnRepresentation.kt")
public void testSameConversionToGenericWrongNullabilityDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/samConversions/sameConversionToGenericWrongNullabilityDnnRepresentation.kt");
}
@Test
@TestMetadata("SimpleCorrect.kt")
public void testSimpleCorrect() {
@@ -21822,12 +21822,24 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
runTest("compiler/testData/diagnostics/tests/j+k/flexibleTypeVariablePosition.kt");
}
@Test
@TestMetadata("flexibleTypeVariablePositionDnnRepresentation.kt")
public void testFlexibleTypeVariablePositionDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/j+k/flexibleTypeVariablePositionDnnRepresentation.kt");
}
@Test
@TestMetadata("futureGet.kt")
public void testFutureGet() {
runTest("compiler/testData/diagnostics/tests/j+k/futureGet.kt");
}
@Test
@TestMetadata("futureGetDnnRepresentation.kt")
public void testFutureGetDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/j+k/futureGetDnnRepresentation.kt");
}
@Test
@TestMetadata("genericConstructorWithMultipleBounds.kt")
public void testGenericConstructorWithMultipleBounds() {
@@ -22104,6 +22116,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
runTest("compiler/testData/diagnostics/tests/j+k/nullableLinkedListToQueue.kt");
}
@Test
@TestMetadata("nullableLinkedListToQueueDnnRepresentation.kt")
public void testNullableLinkedListToQueueDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/j+k/nullableLinkedListToQueueDnnRepresentation.kt");
}
@Test
@TestMetadata("nullableRawTypeWithFlexibleArguments.kt")
public void testNullableRawTypeWithFlexibleArguments() {
@@ -23157,6 +23175,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
runTest("compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullable.kt");
}
@Test
@TestMetadata("notNullTypeParameterWithKotlinNullableDnnRepresentation.kt")
public void testNotNullTypeParameterWithKotlinNullableDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullableDnnRepresentation.kt");
}
@Test
@TestMetadata("notNullTypeParameterWithKotlinNullableWarnings.kt")
public void testNotNullTypeParameterWithKotlinNullableWarnings() {
@@ -26390,6 +26414,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
runTest("compiler/testData/diagnostics/tests/override/dnnOverridesFlexible.kt");
}
@Test
@TestMetadata("dnnOverridesFlexibleDnnRepresentation.kt")
public void testDnnOverridesFlexibleDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/override/dnnOverridesFlexibleDnnRepresentation.kt");
}
@Test
@TestMetadata("DuplicateMethod.kt")
public void testDuplicateMethod() {
@@ -27002,6 +27032,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
runTest("compiler/testData/diagnostics/tests/platformTypes/comparingWithWrongNullability.kt");
}
@Test
@TestMetadata("comparingWithWrongNullabilityDnnRepresentation.kt")
public void testComparingWithWrongNullabilityDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/platformTypes/comparingWithWrongNullabilityDnnRepresentation.kt");
}
@Test
@TestMetadata("delegateByComplexInheritance.kt")
public void testDelegateByComplexInheritance() {
@@ -27391,6 +27427,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
runTest("compiler/testData/diagnostics/tests/platformTypes/methodCall/singleton.kt");
}
@Test
@TestMetadata("singletonDnnRepresentation.kt")
public void testSingletonDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/platformTypes/methodCall/singletonDnnRepresentation.kt");
}
@Test
@TestMetadata("string.kt")
public void testString() {
@@ -30896,6 +30938,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
runTest("compiler/testData/diagnostics/tests/samConversions/sameCandidatesFromKotlinAndJavaInOneScope.kt");
}
@Test
@TestMetadata("sameConversionToGenericWrongNullabilityDnnRepresentation.kt")
public void testSameConversionToGenericWrongNullabilityDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/samConversions/sameConversionToGenericWrongNullabilityDnnRepresentation.kt");
}
@Test
@TestMetadata("SimpleCorrect.kt")
public void testSimpleCorrect() {
@@ -21828,12 +21828,24 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
runTest("compiler/testData/diagnostics/tests/j+k/flexibleTypeVariablePosition.kt");
}
@Test
@TestMetadata("flexibleTypeVariablePositionDnnRepresentation.kt")
public void testFlexibleTypeVariablePositionDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/j+k/flexibleTypeVariablePositionDnnRepresentation.kt");
}
@Test
@TestMetadata("futureGet.kt")
public void testFutureGet() {
runTest("compiler/testData/diagnostics/tests/j+k/futureGet.kt");
}
@Test
@TestMetadata("futureGetDnnRepresentation.kt")
public void testFutureGetDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/j+k/futureGetDnnRepresentation.kt");
}
@Test
@TestMetadata("genericConstructorWithMultipleBounds.kt")
public void testGenericConstructorWithMultipleBounds() {
@@ -22110,6 +22122,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
runTest("compiler/testData/diagnostics/tests/j+k/nullableLinkedListToQueue.kt");
}
@Test
@TestMetadata("nullableLinkedListToQueueDnnRepresentation.kt")
public void testNullableLinkedListToQueueDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/j+k/nullableLinkedListToQueueDnnRepresentation.kt");
}
@Test
@TestMetadata("nullableRawTypeWithFlexibleArguments.kt")
public void testNullableRawTypeWithFlexibleArguments() {
@@ -23163,6 +23181,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
runTest("compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullable.kt");
}
@Test
@TestMetadata("notNullTypeParameterWithKotlinNullableDnnRepresentation.kt")
public void testNotNullTypeParameterWithKotlinNullableDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullableDnnRepresentation.kt");
}
@Test
@TestMetadata("notNullTypeParameterWithKotlinNullableWarnings.kt")
public void testNotNullTypeParameterWithKotlinNullableWarnings() {
@@ -26396,6 +26420,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
runTest("compiler/testData/diagnostics/tests/override/dnnOverridesFlexible.kt");
}
@Test
@TestMetadata("dnnOverridesFlexibleDnnRepresentation.kt")
public void testDnnOverridesFlexibleDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/override/dnnOverridesFlexibleDnnRepresentation.kt");
}
@Test
@TestMetadata("DuplicateMethod.kt")
public void testDuplicateMethod() {
@@ -27008,6 +27038,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
runTest("compiler/testData/diagnostics/tests/platformTypes/comparingWithWrongNullability.kt");
}
@Test
@TestMetadata("comparingWithWrongNullabilityDnnRepresentation.kt")
public void testComparingWithWrongNullabilityDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/platformTypes/comparingWithWrongNullabilityDnnRepresentation.kt");
}
@Test
@TestMetadata("delegateByComplexInheritance.kt")
public void testDelegateByComplexInheritance() {
@@ -27397,6 +27433,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
runTest("compiler/testData/diagnostics/tests/platformTypes/methodCall/singleton.kt");
}
@Test
@TestMetadata("singletonDnnRepresentation.kt")
public void testSingletonDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/platformTypes/methodCall/singletonDnnRepresentation.kt");
}
@Test
@TestMetadata("string.kt")
public void testString() {
@@ -30908,6 +30950,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
runTest("compiler/testData/diagnostics/tests/samConversions/sameCandidatesFromKotlinAndJavaInOneScope.kt");
}
@Test
@TestMetadata("sameConversionToGenericWrongNullabilityDnnRepresentation.kt")
public void testSameConversionToGenericWrongNullabilityDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/samConversions/sameConversionToGenericWrongNullabilityDnnRepresentation.kt");
}
@Test
@TestMetadata("SimpleCorrect.kt")
public void testSimpleCorrect() {
@@ -6,10 +6,12 @@
package org.jetbrains.kotlin.fir.java
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
import org.jetbrains.kotlin.fir.java.enhancement.readOnlyToMutable
import org.jetbrains.kotlin.fir.languageVersionSettings
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedNameError
import org.jetbrains.kotlin.fir.resolve.toFirRegularClassSymbol
import org.jetbrains.kotlin.fir.types.*
@@ -111,7 +113,21 @@ private fun JavaType?.toConeTypeProjection(
}
val upperBound = toConeKotlinTypeForFlexibleBound(session, javaTypeParameterStack, mode, attributes, lowerBound)
if (isRaw) ConeRawType.create(lowerBound, upperBound) else ConeFlexibleType(lowerBound, upperBound)
val finalLowerBound = when {
!session.languageVersionSettings.supportsFeature(LanguageFeature.JavaTypeParameterDefaultRepresentationWithDNN) ->
lowerBound
lowerBound is ConeTypeParameterType ->
ConeDefinitelyNotNullType.create(
lowerBound, session.typeContext,
// Upper bounds might be not initialized properly yet, so we force creating DefinitelyNotNullType
// It should not affect semantics, since it would be still a valid type anyway
avoidComprehensiveCheck = true,
) ?: lowerBound
else -> lowerBound
}
if (isRaw) ConeRawType.create(finalLowerBound, upperBound) else ConeFlexibleType(finalLowerBound, upperBound)
}
is JavaArrayType -> {
@@ -6,10 +6,13 @@
package org.jetbrains.kotlin.fir.types
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.fir.declarations.utils.modality
import org.jetbrains.kotlin.fir.diagnostics.ConeIntermediateDiagnostic
import org.jetbrains.kotlin.fir.isPrimitiveNumberOrUnsignedNumberType
import org.jetbrains.kotlin.fir.languageVersionSettings
import org.jetbrains.kotlin.fir.resolve.createSubstitutionForSupertype
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider
@@ -587,7 +590,9 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
return intersectionType.withAlternative(secondCandidate)
}
override fun useRefinedBoundsForTypeVariableInFlexiblePosition(): Boolean = false
override fun useRefinedBoundsForTypeVariableInFlexiblePosition(): Boolean = session.languageVersionSettings.supportsFeature(
LanguageFeature.JavaTypeParameterDefaultRepresentationWithDNN
)
override fun KotlinTypeMarker.convertToNonRaw(): KotlinTypeMarker {
require(this is ConeKotlinType)
@@ -5,8 +5,10 @@
package org.jetbrains.kotlin.fir.resolve.calls
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.languageVersionSettings
import org.jetbrains.kotlin.fir.renderWithType
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import org.jetbrains.kotlin.fir.resolve.inference.ConeTypeParameterBasedTypeVariable
@@ -166,6 +168,9 @@ internal object CreateFreshTypeVariableSubstitutorStage : ResolutionStage() {
}
private fun FirTypeParameterRef.shouldBeFlexible(context: ConeTypeContext): Boolean {
if (context.session.languageVersionSettings.supportsFeature(LanguageFeature.JavaTypeParameterDefaultRepresentationWithDNN)) {
return false
}
return symbol.resolvedBounds.any {
val type = it.coneType
type is ConeFlexibleType || with(context) {
@@ -1,4 +1,5 @@
// FIR_IDENTICAL
// !LANGUAGE: -JavaTypeParameterDefaultRepresentationWithDNN
// ISSUE: KT-59138
// SKIP_TXT
// FILE: JavaClass.java
@@ -15,8 +16,8 @@ fun takeN(n: Number?): Int = 1
fun bar(n: Number?) {
fun takeN(n: Number): String = ""
// in K1, it was resolved to nullable takeN
// in K2, it would be resolved to not-nullable and may fail with NPE
// in K1 & K2, it is resolved to nullable takeN
// in K2 with DNN representation ON, it would be resolved to not-nullable and may fail with NPE
takeN(JavaClass.simpleId(n)).div(1)
takeN(JavaClass.simpleId(n)).<!UNRESOLVED_REFERENCE!>length<!>
}
@@ -0,0 +1,22 @@
// !LANGUAGE: +JavaTypeParameterDefaultRepresentationWithDNN
// ISSUE: KT-59138
// SKIP_TXT
// FILE: JavaClass.java
public class JavaClass {
public static <K> K simpleId(K k) { // fun <K> simpleId(k: K & Any..K?): K & Any..K? =
return k;
}
}
// FILE: main.kt
fun takeN(n: Number?): Int = 1
fun bar(n: Number?) {
fun takeN(n: Number): String = ""
// in K1 & K2, it is resolved to nullable takeN
// in K2 with DNN representation ON, it would be resolved to not-nullable and may fail with NPE
takeN(JavaClass.simpleId(n)).<!UNRESOLVED_REFERENCE!>div<!>(1)
takeN(JavaClass.simpleId(n)).length
}
@@ -0,0 +1,22 @@
// !LANGUAGE: +JavaTypeParameterDefaultRepresentationWithDNN
// ISSUE: KT-59138
// SKIP_TXT
// FILE: JavaClass.java
public class JavaClass {
public static <K> K simpleId(K k) { // fun <K> simpleId(k: K & Any..K?): K & Any..K? =
return k;
}
}
// FILE: main.kt
fun takeN(n: Number?): Int = 1
fun bar(n: Number?) {
fun takeN(n: Number): String = ""
// in K1 & K2, it is resolved to nullable takeN
// in K2 with DNN representation ON, it would be resolved to not-nullable and may fail with NPE
takeN(JavaClass.simpleId(n)).div(1)
takeN(JavaClass.simpleId(n)).<!UNRESOLVED_REFERENCE!>length<!>
}
+1
View File
@@ -1,5 +1,6 @@
// FIR_IDENTICAL
// FULL_JDK
// LANGUAGE: -JavaTypeParameterDefaultRepresentationWithDNN
// JVM_TARGET: 1.8
import java.util.concurrent.Future
@@ -0,0 +1,18 @@
// FULL_JDK
// LANGUAGE: +JavaTypeParameterDefaultRepresentationWithDNN
// JVM_TARGET: 1.8
import java.util.concurrent.Future
import java.util.concurrent.atomic.AtomicReference
fun foo(future: Future<String?>) {
future.get().length
}
fun bar(threadLocal: ThreadLocal<String?>) {
threadLocal.get().length
}
fun baz(ref: AtomicReference<String?>) {
ref.get().length
}
@@ -0,0 +1,18 @@
// FULL_JDK
// LANGUAGE: +JavaTypeParameterDefaultRepresentationWithDNN
// JVM_TARGET: 1.8
import java.util.concurrent.Future
import java.util.concurrent.atomic.AtomicReference
fun foo(future: Future<String?>) {
future.get()<!UNSAFE_CALL!>.<!>length
}
fun bar(threadLocal: ThreadLocal<String?>) {
threadLocal.get()<!UNSAFE_CALL!>.<!>length
}
fun baz(ref: AtomicReference<String?>) {
ref.get()<!UNSAFE_CALL!>.<!>length
}
@@ -1,4 +1,5 @@
// FULL_JDK
// LANGUAGE: -JavaTypeParameterDefaultRepresentationWithDNN
// ISSUE: KT-65184
// FILE: A.java
@@ -1,4 +1,5 @@
// FULL_JDK
// LANGUAGE: -JavaTypeParameterDefaultRepresentationWithDNN
// ISSUE: KT-65184
// FILE: A.java
@@ -0,0 +1,46 @@
// FULL_JDK
// LANGUAGE: +JavaTypeParameterDefaultRepresentationWithDNN
// ISSUE: KT-65184
// FILE: A.java
public class A<T> {
}
// FILE: B.java
public class B<T> extends A<T> {
}
// FILE: box.kt
import java.util.LinkedList
import java.util.Queue
fun bar(b: A<String>) {}
fun func(p: A<B<String>>) {
}
class X {
fun bar(b: Queue<String>) {}
}
fun test(x : X) {
x.bar(LinkedList<String?>())
bar(B<String?>())
func(A<B<String>>())
func(<!ARGUMENT_TYPE_MISMATCH!>A<B<String?>>()<!>)
func(<!ARGUMENT_TYPE_MISMATCH!>A<B<String?>?>()<!>)
func(<!ARGUMENT_TYPE_MISMATCH!>A<B<String>?>()<!>)
}
class C {
fun bar(b: Queue<String>) {}
}
fun test(c: C, jj: LinkedList<String?>) {
c.bar(jj)
}
@@ -0,0 +1,46 @@
// FULL_JDK
// LANGUAGE: +JavaTypeParameterDefaultRepresentationWithDNN
// ISSUE: KT-65184
// FILE: A.java
public class A<T> {
}
// FILE: B.java
public class B<T> extends A<T> {
}
// FILE: box.kt
import java.util.LinkedList
import java.util.Queue
fun bar(b: A<String>) {}
fun func(p: A<B<String>>) {
}
class X {
fun bar(b: Queue<String>) {}
}
fun test(x : X) {
x.bar(<!TYPE_MISMATCH!>LinkedList<String?>()<!>)
bar(<!TYPE_MISMATCH!>B<String?>()<!>)
func(A<B<String>>())
func(<!TYPE_MISMATCH!>A<B<String?>>()<!>)
func(<!TYPE_MISMATCH!>A<B<String?>?>()<!>)
func(<!TYPE_MISMATCH!>A<B<String>?>()<!>)
}
class C {
fun bar(b: Queue<String>) {}
}
fun test(c: C, jj: LinkedList<String?>) {
c.bar(<!TYPE_MISMATCH!>jj<!>)
}
@@ -1,5 +1,5 @@
// !SKIP_JAVAC
// !LANGUAGE: +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated
// !LANGUAGE: +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated -JavaTypeParameterDefaultRepresentationWithDNN
// FILE: SLRUMap.java
import org.jetbrains.annotations.NotNull;
@@ -1,5 +1,5 @@
// !SKIP_JAVAC
// !LANGUAGE: +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated
// !LANGUAGE: +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated -JavaTypeParameterDefaultRepresentationWithDNN
// FILE: SLRUMap.java
import org.jetbrains.annotations.NotNull;
@@ -0,0 +1,42 @@
// !SKIP_JAVAC
// !LANGUAGE: +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated +JavaTypeParameterDefaultRepresentationWithDNN
// FILE: SLRUMap.java
import org.jetbrains.annotations.NotNull;
import java.util.List;
public interface SLRUMap<V> {
void takeV(@NotNull V value);
<E> void takeE(@NotNull E value);
void takeVList(@NotNull List<@NotNull V> value);
<E> void takeEList(@NotNull List<@NotNull E> value);
public <K> K id(K value) { return null; }
}
// FILE: main.kt
fun <V> SLRUMap<V>.getOrPut(value: V, l: List<V>) {
takeV(<!ARGUMENT_TYPE_MISMATCH!>value<!>)
takeVList(<!ARGUMENT_TYPE_MISMATCH!>l<!>)
takeE(<!ARGUMENT_TYPE_MISMATCH!>value<!>)
takeEList(<!ARGUMENT_TYPE_MISMATCH!>l<!>)
takeE(id(value))
if (value != null) {
takeV(value)
takeE(value)
takeE(id(value))
}
}
fun <V : Any> SLRUMap<V>.getOrPutNN(value: V, l: List<V>) {
takeV(value)
takeVList(l)
takeE(value)
takeEList(l)
takeE(id(value))
}
@@ -0,0 +1,42 @@
// !SKIP_JAVAC
// !LANGUAGE: +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated +JavaTypeParameterDefaultRepresentationWithDNN
// FILE: SLRUMap.java
import org.jetbrains.annotations.NotNull;
import java.util.List;
public interface SLRUMap<V> {
void takeV(@NotNull V value);
<E> void takeE(@NotNull E value);
void takeVList(@NotNull List<@NotNull V> value);
<E> void takeEList(@NotNull List<@NotNull E> value);
public <K> K id(K value) { return null; }
}
// FILE: main.kt
fun <V> SLRUMap<V>.getOrPut(value: V, l: List<V>) {
takeV(<!TYPE_MISMATCH!>value<!>)
takeVList(<!TYPE_MISMATCH!>l<!>)
takeE(<!TYPE_MISMATCH!>value<!>)
takeEList(<!TYPE_MISMATCH!>l<!>)
takeE(<!TYPE_MISMATCH!>id(value)<!>)
if (value != null) {
takeV(<!DEBUG_INFO_SMARTCAST!>value<!>)
takeE(<!DEBUG_INFO_SMARTCAST!>value<!>)
takeE(id(value))
}
}
fun <V : Any> SLRUMap<V>.getOrPutNN(value: V, l: List<V>) {
takeV(value)
takeVList(l)
takeE(value)
takeEList(l)
takeE(id(value))
}
@@ -1,4 +1,5 @@
// FIR_IDENTICAL
// LANGUAGE: -JavaTypeParameterDefaultRepresentationWithDNN
// ISSUE: KT-58933
// FILE: J.java
public interface J<T> {
@@ -0,0 +1,15 @@
// LANGUAGE: +JavaTypeParameterDefaultRepresentationWithDNN
// ISSUE: KT-58933
// FILE: J.java
public interface J<T> {
void simple(T t);
void box(Box<T> box);
}
// FILE: test.kt
class Box<T>
class K<T> : J<T> {
override fun simple(t: T & Any) {}
override fun box(box: Box<T & Any>) {}
}
@@ -0,0 +1,15 @@
// LANGUAGE: +JavaTypeParameterDefaultRepresentationWithDNN
// ISSUE: KT-58933
// FILE: J.java
public interface J<T> {
void simple(T t);
void box(Box<T> box);
}
// FILE: test.kt
class Box<T>
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class K<!><T> : J<T> {
<!NOTHING_TO_OVERRIDE!>override<!> fun simple(t: T & Any) {}
<!NOTHING_TO_OVERRIDE!>override<!> fun box(box: Box<T & Any>) {}
}
@@ -1,5 +1,6 @@
// FIR_IDENTICAL
// FULL_JDK
// LANGUAGE: -JavaTypeParameterDefaultRepresentationWithDNN
import java.util.Comparator;
@@ -0,0 +1,11 @@
// FIR_IDENTICAL
// FULL_JDK
// LANGUAGE: +JavaTypeParameterDefaultRepresentationWithDNN
import java.util.Comparator;
fun foo() {
Comparator.comparing<String?, Boolean?> {
it != ""
}
}
@@ -1,4 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
// LANGUAGE: -JavaTypeParameterDefaultRepresentationWithDNN
interface Foo
@@ -1,4 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
// LANGUAGE: -JavaTypeParameterDefaultRepresentationWithDNN
interface Foo
@@ -0,0 +1,10 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
// LANGUAGE: +JavaTypeParameterDefaultRepresentationWithDNN
interface Foo
fun test() {
var nullable: Foo? = null
val foo: Collection<Foo> = java.util.Collections.singleton(nullable)
val foo1: Collection<Foo> = java.util.Collections.singleton(nullable!!)
}
@@ -0,0 +1,10 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
// LANGUAGE: +JavaTypeParameterDefaultRepresentationWithDNN
interface Foo
fun test() {
var nullable: Foo? = null
val foo: Collection<Foo> = <!TYPE_MISMATCH!>java.util.Collections.singleton(nullable)<!>
val foo1: Collection<Foo> = java.util.Collections.singleton(nullable!!)
}
@@ -1,4 +1,5 @@
// FIR_IDENTICAL
// LANGUAGE: -JavaTypeParameterDefaultRepresentationWithDNN
// ISSUE: KT-57014
// FULL_JDK
// JVM_TARGET: 1.8
@@ -0,0 +1,14 @@
// LANGUAGE: +JavaTypeParameterDefaultRepresentationWithDNN
// ISSUE: KT-57014
// FULL_JDK
// JVM_TARGET: 1.8
import java.util.function.Supplier
fun main() {
val sam = Supplier<String> {
<!ARGUMENT_TYPE_MISMATCH!>foo()<!>
}
}
fun foo(): String? = null
@@ -0,0 +1,14 @@
// LANGUAGE: +JavaTypeParameterDefaultRepresentationWithDNN
// ISSUE: KT-57014
// FULL_JDK
// JVM_TARGET: 1.8
import java.util.function.Supplier
fun main() {
val sam = Supplier<String> {
foo()
}
}
fun foo(): String? = null
@@ -21828,12 +21828,24 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/j+k/flexibleTypeVariablePosition.kt");
}
@Test
@TestMetadata("flexibleTypeVariablePositionDnnRepresentation.kt")
public void testFlexibleTypeVariablePositionDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/j+k/flexibleTypeVariablePositionDnnRepresentation.kt");
}
@Test
@TestMetadata("futureGet.kt")
public void testFutureGet() {
runTest("compiler/testData/diagnostics/tests/j+k/futureGet.kt");
}
@Test
@TestMetadata("futureGetDnnRepresentation.kt")
public void testFutureGetDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/j+k/futureGetDnnRepresentation.kt");
}
@Test
@TestMetadata("genericConstructorWithMultipleBounds.kt")
public void testGenericConstructorWithMultipleBounds() {
@@ -22110,6 +22122,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/j+k/nullableLinkedListToQueue.kt");
}
@Test
@TestMetadata("nullableLinkedListToQueueDnnRepresentation.kt")
public void testNullableLinkedListToQueueDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/j+k/nullableLinkedListToQueueDnnRepresentation.kt");
}
@Test
@TestMetadata("nullableRawTypeWithFlexibleArguments.kt")
public void testNullableRawTypeWithFlexibleArguments() {
@@ -23163,6 +23181,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullable.kt");
}
@Test
@TestMetadata("notNullTypeParameterWithKotlinNullableDnnRepresentation.kt")
public void testNotNullTypeParameterWithKotlinNullableDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/j+k/types/notNullTypeParameterWithKotlinNullableDnnRepresentation.kt");
}
@Test
@TestMetadata("notNullTypeParameterWithKotlinNullableWarnings.kt")
public void testNotNullTypeParameterWithKotlinNullableWarnings() {
@@ -28692,6 +28716,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/override/dnnOverridesFlexible.kt");
}
@Test
@TestMetadata("dnnOverridesFlexibleDnnRepresentation.kt")
public void testDnnOverridesFlexibleDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/override/dnnOverridesFlexibleDnnRepresentation.kt");
}
@Test
@TestMetadata("DuplicateMethod.kt")
public void testDuplicateMethod() {
@@ -29304,6 +29334,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/platformTypes/comparingWithWrongNullability.kt");
}
@Test
@TestMetadata("comparingWithWrongNullabilityDnnRepresentation.kt")
public void testComparingWithWrongNullabilityDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/platformTypes/comparingWithWrongNullabilityDnnRepresentation.kt");
}
@Test
@TestMetadata("delegateByComplexInheritance.kt")
public void testDelegateByComplexInheritance() {
@@ -29693,6 +29729,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/platformTypes/methodCall/singleton.kt");
}
@Test
@TestMetadata("singletonDnnRepresentation.kt")
public void testSingletonDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/platformTypes/methodCall/singletonDnnRepresentation.kt");
}
@Test
@TestMetadata("string.kt")
public void testString() {
@@ -33204,6 +33246,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/samConversions/sameCandidatesFromKotlinAndJavaInOneScope.kt");
}
@Test
@TestMetadata("sameConversionToGenericWrongNullabilityDnnRepresentation.kt")
public void testSameConversionToGenericWrongNullabilityDnnRepresentation() {
runTest("compiler/testData/diagnostics/tests/samConversions/sameConversionToGenericWrongNullabilityDnnRepresentation.kt");
}
@Test
@TestMetadata("SimpleCorrect.kt")
public void testSimpleCorrect() {
@@ -384,6 +384,7 @@ enum class LanguageFeature(
DisableCheckingChangedProgressionsResolve(sinceVersion = null, kind = OTHER), // KT-49276
ContextSensitiveEnumResolutionInWhen(sinceVersion = null, kind = UNSTABLE_FEATURE), // KT-52774
ForbidSyntheticPropertiesWithoutBaseJavaGetter(sinceVersion = null, kind = OTHER), // KT-64358
JavaTypeParameterDefaultRepresentationWithDNN(sinceVersion = null, kind = OTHER), // KT-59138
;
init {