FIR: Support enhanced types when checking if Java type is primitive
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@ FILE: test.kt
|
||||
private final val DERIVED_FACTORY: R|DiagnosticFactory0<ft<DerivedElement, DerivedElement?>>| = R|/DiagnosticFactory0.DiagnosticFactory0|<R|ft<DerivedElement, DerivedElement?>|>()
|
||||
private get(): R|DiagnosticFactory0<ft<DerivedElement, DerivedElement?>>|
|
||||
public final fun createViaFactory(d: R|EmptyDiagnostic|): R|kotlin/Unit| {
|
||||
lval casted: R|Diagnostic<ft<DerivedElement, DerivedElement?>>| = R|/DERIVED_FACTORY|.R|SubstitutionOverride</DiagnosticFactory0.cast: R|Diagnostic<ft<DerivedElement, DerivedElement?>>|>|(R|<local>/d|)
|
||||
lval casted: R|Diagnostic<ft<DerivedElement, DerivedElement?>>| = R|/DERIVED_FACTORY|.R|SubstitutionOverride</DiagnosticFactory0.cast: R|@EnhancedNullability Diagnostic<ft<DerivedElement, DerivedElement?>>|>|(R|<local>/d|)
|
||||
lval element: R|DerivedElement| = R|<local>/casted|.R|/Diagnostic.element|
|
||||
R|/Fix.Fix|(R|<local>/element|)
|
||||
}
|
||||
|
||||
+6
@@ -16855,6 +16855,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/innerNestedClassFromJava.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("integerNotNullable.kt")
|
||||
public void testIntegerNotNullable() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/integerNotNullable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("invisiblePackagePrivateInheritedMember.kt")
|
||||
public void testInvisiblePackagePrivateInheritedMember() throws Exception {
|
||||
|
||||
+6
@@ -16855,6 +16855,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/innerNestedClassFromJava.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("integerNotNullable.kt")
|
||||
public void testIntegerNotNullable() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/integerNotNullable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("invisiblePackagePrivateInheritedMember.kt")
|
||||
public void testInvisiblePackagePrivateInheritedMember() throws Exception {
|
||||
|
||||
@@ -212,11 +212,10 @@ data class ConeCapturedType(
|
||||
|
||||
data class ConeTypeVariableType(
|
||||
override val nullability: ConeNullability,
|
||||
override val lookupTag: ConeClassifierLookupTag
|
||||
override val lookupTag: ConeClassifierLookupTag,
|
||||
override val attributes: ConeAttributes = ConeAttributes.Empty,
|
||||
) : ConeLookupTagBasedType() {
|
||||
override val typeArguments: Array<out ConeTypeProjection> get() = emptyArray()
|
||||
|
||||
override val attributes: ConeAttributes get() = ConeAttributes.Empty
|
||||
}
|
||||
|
||||
data class ConeDefinitelyNotNullType(val original: ConeKotlinType) : ConeSimpleKotlinType(), DefinitelyNotNullTypeMarker {
|
||||
@@ -227,7 +226,7 @@ data class ConeDefinitelyNotNullType(val original: ConeKotlinType) : ConeSimpleK
|
||||
get() = ConeNullability.NOT_NULL
|
||||
|
||||
override val attributes: ConeAttributes
|
||||
get() = ConeAttributes.Empty
|
||||
get() = original.attributes
|
||||
|
||||
companion object
|
||||
}
|
||||
|
||||
@@ -80,8 +80,7 @@ class JavaOverrideChecker internal constructor(
|
||||
}
|
||||
|
||||
private fun ConeKotlinType.isPrimitiveInJava(): Boolean = with(context) {
|
||||
// TODO: Support enhanced type like `@NotNull Integer` that are not nullable, but still aren't primitive
|
||||
!isNullableType() && isPrimitiveOrNullablePrimitive
|
||||
!isNullableType() && CompilerConeAttributes.EnhancedNullability !in attributes && isPrimitiveOrNullablePrimitive
|
||||
}
|
||||
|
||||
private fun isEqualArrayElementTypeProjections(
|
||||
|
||||
+4
-1
@@ -84,7 +84,10 @@ abstract class AbstractConeSubstitutor(private val typeContext: ConeTypeContext)
|
||||
}
|
||||
|
||||
private fun ConeDefinitelyNotNullType.substituteOriginal(): ConeKotlinType? {
|
||||
val substituted = substituteOrNull(original)?.withNullability(ConeNullability.NOT_NULL, typeContext) ?: return null
|
||||
val substituted = substituteOrNull(original)
|
||||
?.withNullability(ConeNullability.NOT_NULL, typeContext)
|
||||
?.withAttributes(original.attributes, typeContext)
|
||||
?: return null
|
||||
return ConeDefinitelyNotNullType.create(substituted, typeContext) ?: substituted
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLookupTagWithFixedSymbol
|
||||
import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||
@@ -110,6 +110,13 @@ fun <T : ConeKotlinType> T.withAttributes(attributes: ConeAttributes, typeSystem
|
||||
lowerBound.withAttributes(attributes, typeSystemContext),
|
||||
upperBound.withAttributes(attributes, typeSystemContext)
|
||||
)
|
||||
is ConeTypeVariableType -> ConeTypeVariableType(nullability, lookupTag, attributes)
|
||||
is ConeCapturedType -> ConeCapturedType(
|
||||
captureStatus, lowerType, nullability, constructor, attributes, isProjectionNotNull,
|
||||
)
|
||||
// TODO: Consider correct application of attributes to ConeIntersectionType
|
||||
// Currently, ConeAttributes.union works a bit strange, because it lefts only `other` parts
|
||||
is ConeIntersectionType -> this
|
||||
else -> error("Not supported: $this: ${this.render()}")
|
||||
} as T
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// FIR_IDENTICAL
|
||||
// FILE: Box.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Box<T> {
|
||||
public void put(@NotNull T t) {}
|
||||
}
|
||||
|
||||
// FILE: IntBox.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class IntBox extends Box<Integer> {
|
||||
public int result = 0;
|
||||
@Override
|
||||
public void put(@NotNull Integer t) {
|
||||
result = t;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main() {
|
||||
IntBox().put(1)
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package
|
||||
|
||||
public fun main(): kotlin.Unit
|
||||
|
||||
public open class Box</*0*/ T : kotlin.Any!> {
|
||||
public constructor Box</*0*/ T : kotlin.Any!>()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open fun put(/*0*/ @org.jetbrains.annotations.NotNull t: T!!): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public open class IntBox : Box<kotlin.Int!> {
|
||||
public constructor IntBox()
|
||||
public final var result: kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
@java.lang.Override public open override /*1*/ fun put(/*0*/ @org.jetbrains.annotations.NotNull t: kotlin.Int): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
// FILE: A.java
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
public class A {
|
||||
public void foo(int x) {}
|
||||
public void bar(@NotNull Double x) {}
|
||||
}
|
||||
|
||||
// FILE: B.java
|
||||
import org.jetbrains.annotations.*;
|
||||
public class B extends A {
|
||||
public void foo(@NotNull Integer x) {}
|
||||
public void bar(double x) {}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
fun foo(b: B) {
|
||||
// See KT-9182
|
||||
b.<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>(1)
|
||||
b.bar(2.0)
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// FILE: A.java
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
|
||||
+16
-2
@@ -17,7 +17,7 @@ FILE fqName:<root> fileName:/kt43217.kt
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:<no name provided> modality:FINAL visibility:local superTypes:[<root>.DoubleExpression]'
|
||||
FUN name:get visibility:public modality:FINAL <> ($this:<root>.A.b.<no name provided>) returnType:kotlin.Double [operator]
|
||||
overridden:
|
||||
public abstract fun get (): kotlin.Double [fake_override,operator] declared in <root>.DoubleExpression
|
||||
public abstract fun get (): @[EnhancedNullability] kotlin.Double [fake_override,operator] declared in <root>.DoubleExpression
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.A.b.<no name provided>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun get (): kotlin.Double [operator] declared in <root>.A.b.<no name provided>'
|
||||
@@ -30,6 +30,13 @@ FILE fqName:<root> fileName:/kt43217.kt
|
||||
public open fun isEqualTo (value: kotlin.Double): @[EnhancedNullability] @[Override] kotlin.Any declared in <root>.DoubleExpression
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.DoubleExpression
|
||||
VALUE_PARAMETER name:value index:0 type:kotlin.Double
|
||||
FUN FAKE_OVERRIDE name:isEqualTo visibility:public modality:OPEN <> ($this:<root>.ObservableValue<T of <root>.ObservableValue>, value:@[EnhancedNullability] kotlin.Double) returnType:@[EnhancedNullability] kotlin.Any [fake_override]
|
||||
annotations:
|
||||
NotNull(value = <null>)
|
||||
overridden:
|
||||
public open fun isEqualTo (value: @[EnhancedNullability] kotlin.Double): @[EnhancedNullability] kotlin.Any [fake_override] declared in <root>.DoubleExpression
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.ObservableValue<T of <root>.ObservableValue>
|
||||
VALUE_PARAMETER name:value index:0 type:@[EnhancedNullability] kotlin.Double
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
overridden:
|
||||
public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in <root>.DoubleExpression
|
||||
@@ -72,7 +79,7 @@ FILE fqName:<root> fileName:/kt43217.kt
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[<root>.DoubleExpression]'
|
||||
FUN name:get visibility:public modality:FINAL <> ($this:<root>.C) returnType:kotlin.Double [operator]
|
||||
overridden:
|
||||
public abstract fun get (): kotlin.Double [fake_override,operator] declared in <root>.DoubleExpression
|
||||
public abstract fun get (): @[EnhancedNullability] kotlin.Double [fake_override,operator] declared in <root>.DoubleExpression
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.C
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun get (): kotlin.Double [operator] declared in <root>.C'
|
||||
@@ -85,6 +92,13 @@ FILE fqName:<root> fileName:/kt43217.kt
|
||||
public open fun isEqualTo (value: kotlin.Double): @[EnhancedNullability] @[Override] kotlin.Any declared in <root>.DoubleExpression
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.DoubleExpression
|
||||
VALUE_PARAMETER name:value index:0 type:kotlin.Double
|
||||
FUN FAKE_OVERRIDE name:isEqualTo visibility:public modality:OPEN <> ($this:<root>.ObservableValue<T of <root>.ObservableValue>, value:@[EnhancedNullability] kotlin.Double) returnType:@[EnhancedNullability] kotlin.Any [fake_override]
|
||||
annotations:
|
||||
NotNull(value = <null>)
|
||||
overridden:
|
||||
public open fun isEqualTo (value: @[EnhancedNullability] kotlin.Double): @[EnhancedNullability] kotlin.Any [fake_override] declared in <root>.DoubleExpression
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.ObservableValue<T of <root>.ObservableValue>
|
||||
VALUE_PARAMETER name:value index:0 type:@[EnhancedNullability] kotlin.Double
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
overridden:
|
||||
public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in <root>.DoubleExpression
|
||||
|
||||
@@ -75,12 +75,12 @@ FILE fqName:<root> fileName:/AbstractMutableMap.kt
|
||||
public open fun replaceAll (p0: @[EnhancedNullability] java.util.function.BiFunction<in @[FlexibleNullability] K of kotlin.collections.AbstractMutableMap?, in @[FlexibleNullability] V of kotlin.collections.AbstractMutableMap?, out @[FlexibleNullability] V of kotlin.collections.AbstractMutableMap?>): kotlin.Unit [fake_override] declared in kotlin.collections.AbstractMutableMap
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.collections.MutableMap<K of kotlin.collections.MutableMap, V of kotlin.collections.MutableMap>
|
||||
VALUE_PARAMETER name:p0 index:0 type:@[EnhancedNullability] java.util.function.BiFunction<in @[FlexibleNullability] K of <root>.MyMap?, in @[FlexibleNullability] V of <root>.MyMap?, out @[FlexibleNullability] V of <root>.MyMap?>
|
||||
FUN FAKE_OVERRIDE name:merge visibility:public modality:OPEN <> ($this:kotlin.collections.MutableMap<K of kotlin.collections.MutableMap, V of kotlin.collections.MutableMap>, p0:K of <root>.MyMap, p1:V of <root>.MyMap, p2:@[EnhancedNullability] java.util.function.BiFunction<in @[FlexibleNullability] V of <root>.MyMap?, in @[FlexibleNullability] V of <root>.MyMap?, out @[FlexibleNullability] V of <root>.MyMap?>) returnType:V of <root>.MyMap? [fake_override]
|
||||
FUN FAKE_OVERRIDE name:merge visibility:public modality:OPEN <> ($this:kotlin.collections.MutableMap<K of kotlin.collections.MutableMap, V of kotlin.collections.MutableMap>, p0:K of <root>.MyMap, p1:@[EnhancedNullability] V of <root>.MyMap, p2:@[EnhancedNullability] java.util.function.BiFunction<in @[FlexibleNullability] V of <root>.MyMap?, in @[FlexibleNullability] V of <root>.MyMap?, out @[FlexibleNullability] V of <root>.MyMap?>) returnType:V of <root>.MyMap? [fake_override]
|
||||
overridden:
|
||||
public open fun merge (p0: K of kotlin.collections.AbstractMutableMap, p1: V of kotlin.collections.AbstractMutableMap, p2: @[EnhancedNullability] java.util.function.BiFunction<in @[FlexibleNullability] V of kotlin.collections.AbstractMutableMap?, in @[FlexibleNullability] V of kotlin.collections.AbstractMutableMap?, out @[FlexibleNullability] V of kotlin.collections.AbstractMutableMap?>): V of kotlin.collections.AbstractMutableMap? [fake_override] declared in kotlin.collections.AbstractMutableMap
|
||||
public open fun merge (p0: K of kotlin.collections.AbstractMutableMap, p1: @[EnhancedNullability] V of kotlin.collections.AbstractMutableMap, p2: @[EnhancedNullability] java.util.function.BiFunction<in @[FlexibleNullability] V of kotlin.collections.AbstractMutableMap?, in @[FlexibleNullability] V of kotlin.collections.AbstractMutableMap?, out @[FlexibleNullability] V of kotlin.collections.AbstractMutableMap?>): V of kotlin.collections.AbstractMutableMap? [fake_override] declared in kotlin.collections.AbstractMutableMap
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.collections.MutableMap<K of kotlin.collections.MutableMap, V of kotlin.collections.MutableMap>
|
||||
VALUE_PARAMETER name:p0 index:0 type:K of <root>.MyMap
|
||||
VALUE_PARAMETER name:p1 index:1 type:V of <root>.MyMap
|
||||
VALUE_PARAMETER name:p1 index:1 type:@[EnhancedNullability] V of <root>.MyMap
|
||||
VALUE_PARAMETER name:p2 index:2 type:@[EnhancedNullability] java.util.function.BiFunction<in @[FlexibleNullability] V of <root>.MyMap?, in @[FlexibleNullability] V of <root>.MyMap?, out @[FlexibleNullability] V of <root>.MyMap?>
|
||||
FUN FAKE_OVERRIDE name:computeIfPresent visibility:public modality:OPEN <> ($this:kotlin.collections.MutableMap<K of kotlin.collections.MutableMap, V of kotlin.collections.MutableMap>, p0:K of <root>.MyMap, p1:@[EnhancedNullability] java.util.function.BiFunction<in @[FlexibleNullability] K of <root>.MyMap?, in @[FlexibleNullability] V of <root>.MyMap?, out @[FlexibleNullability] V of <root>.MyMap?>) returnType:V of <root>.MyMap? [fake_override]
|
||||
overridden:
|
||||
|
||||
Generated
+6
@@ -16861,6 +16861,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/innerNestedClassFromJava.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("integerNotNullable.kt")
|
||||
public void testIntegerNotNullable() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/integerNotNullable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("invisiblePackagePrivateInheritedMember.kt")
|
||||
public void testInvisiblePackagePrivateInheritedMember() throws Exception {
|
||||
|
||||
+6
@@ -16855,6 +16855,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/innerNestedClassFromJava.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("integerNotNullable.kt")
|
||||
public void testIntegerNotNullable() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/integerNotNullable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("invisiblePackagePrivateInheritedMember.kt")
|
||||
public void testInvisiblePackagePrivateInheritedMember() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user