diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java index fb62f7d3b06..d9be7d8ea50 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java @@ -1606,6 +1606,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/ir/irText/types"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.kt") + public void testExplicitEqualsAndCompareToCallsOnPlatformTypeReceiver() throws Exception { + runTest("compiler/testData/ir/irText/types/explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.kt"); + } + @TestMetadata("intersectionType1_NI.kt") public void testIntersectionType1_NI() throws Exception { runTest("compiler/testData/ir/irText/types/intersectionType1_NI.kt"); @@ -1640,5 +1645,10 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { public void testLocalVariableOfIntersectionType_NI() throws Exception { runTest("compiler/testData/ir/irText/types/localVariableOfIntersectionType_NI.kt"); } + + @TestMetadata("nullabilityAssertionOnExtensionReceiver.kt") + public void testNullabilityAssertionOnExtensionReceiver() throws Exception { + runTest("compiler/testData/ir/irText/types/nullabilityAssertionOnExtensionReceiver.kt"); + } } } diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/transformations/InsertImplicitCasts.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/transformations/InsertImplicitCasts.kt index 898d5d4f2f7..df1f6d67991 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/transformations/InsertImplicitCasts.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/transformations/InsertImplicitCasts.kt @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrTypeOperatorCallImpl import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol import org.jetbrains.kotlin.ir.types.* +import org.jetbrains.kotlin.ir.types.impl.makeTypeIntersection import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection import org.jetbrains.kotlin.ir.types.impl.originalKotlinType import org.jetbrains.kotlin.ir.util.TypeTranslator @@ -37,7 +38,6 @@ import org.jetbrains.kotlin.psi2ir.generators.GeneratorExtensions import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.isDynamic import org.jetbrains.kotlin.types.isNullabilityFlexible -import org.jetbrains.kotlin.types.typeUtil.makeNotNullable fun insertImplicitCasts(element: IrElement, context: GeneratorContext) { element.transformChildren( @@ -111,10 +111,12 @@ open class InsertImplicitCasts( val dTypeParameters = getDeclarationSideTypeParameters(declaration) val cTypeParameters = getTypeSideTypeParameters(declaration) val typeArguments = getTypeArguments(expression, dTypeParameters) - val dispatchReceiver = declaration.dispatchReceiverParameter - val extensionReceiver = declaration.extensionReceiverParameter - this.dispatchReceiver = this.dispatchReceiver?.cast(dispatchReceiver?.type?.substitute(dTypeParameters + cTypeParameters, typeArguments)) - this.extensionReceiver = this.extensionReceiver?.cast(extensionReceiver?.type?.substitute(dTypeParameters + cTypeParameters, typeArguments)) + dispatchReceiver = dispatchReceiver?.cast( + declaration.dispatchReceiverParameter?.type?.substitute(dTypeParameters + cTypeParameters, typeArguments) + ) + extensionReceiver = extensionReceiver?.cast( + declaration.extensionReceiverParameter?.type?.substitute(dTypeParameters + cTypeParameters, typeArguments) + ) } } @@ -123,8 +125,12 @@ open class InsertImplicitCasts( val dTypeParameters = getDeclarationSideTypeParameters(declaration) val cTypeParameters = getTypeSideTypeParameters(declaration) val typeArguments = getTypeArguments(this, dTypeParameters) - dispatchReceiver = dispatchReceiver?.cast(declaration.dispatchReceiverParameter?.type?.substitute(dTypeParameters + cTypeParameters, typeArguments)) - extensionReceiver = extensionReceiver?.cast(declaration.extensionReceiverParameter?.type?.substitute(dTypeParameters + cTypeParameters, typeArguments)) + dispatchReceiver = dispatchReceiver?.cast( + declaration.dispatchReceiverParameter?.type?.substitute(dTypeParameters + cTypeParameters, typeArguments) + ) + extensionReceiver = extensionReceiver?.cast( + declaration.extensionReceiverParameter?.type?.substitute(dTypeParameters + cTypeParameters, typeArguments) + ) } override fun visitMemberAccess(expression: IrMemberAccessExpression): IrExpression = @@ -314,7 +320,7 @@ open class InsertImplicitCasts( } private fun IrExpression.implicitNonNull(valueType: IrType, expectedType: IrType): IrExpression { - val notNullValueType = valueType.makeNotNull() + val notNullValueType = valueType.getRepresentableUpperBound().makeNotNull() return implicitCast(notNullValueType, IrTypeOperator.IMPLICIT_NOTNULL).cast(expectedType) } @@ -352,9 +358,13 @@ open class InsertImplicitCasts( private fun IrType.isBuiltInIntegerType(): Boolean = isByte() || isShort() || isInt() || isLong() || - isUByte() || - isUShort() || - isUInt() || - isULong() + isUByte() || isUShort() || isUInt() || isULong() + + private fun IrType.getRepresentableUpperBound(): IrType { + if (this !is IrSimpleType) return this + val classifier = this.classifier as? IrTypeParameterSymbol ?: return this + val superTypes = classifier.owner.superTypes + return makeTypeIntersection(superTypes) + } } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/TypeTranslator.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/TypeTranslator.kt index c8aab108e97..69170b29932 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/TypeTranslator.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/TypeTranslator.kt @@ -57,11 +57,11 @@ class TypeTranslator( typeParametersResolver.resolveScopedTypeParameter(typeParameterDescriptor) ?: symbolTable.referenceTypeParameter(typeParameterDescriptor) - fun translateType(ktType: KotlinType): IrType = - translateType(ktType, Variance.INVARIANT).type + fun translateType(kotlinType: KotlinType): IrType = + translateType(kotlinType, kotlinType, Variance.INVARIANT).type - private fun translateType(ktType: KotlinType, variance: Variance): IrTypeProjection { - val approximatedType = LegacyTypeApproximation().approximate(ktType) + private fun translateType(originalKotlinType: KotlinType, kotlinType: KotlinType, variance: Variance): IrTypeProjection { + val approximatedType = LegacyTypeApproximation().approximate(kotlinType) when { approximatedType.isError -> @@ -69,7 +69,7 @@ class TypeTranslator( approximatedType.isDynamic() -> return IrDynamicTypeImpl(approximatedType, translateTypeAnnotations(approximatedType.annotations), variance) approximatedType.isFlexible() -> - return translateType(approximatedType.upperIfFlexible(), variance) + return translateType(originalKotlinType, approximatedType.upperIfFlexible(), variance) } val ktTypeConstructor = approximatedType.constructor @@ -77,7 +77,7 @@ class TypeTranslator( ?: throw AssertionError("No descriptor for type $approximatedType") return IrSimpleTypeBuilder().apply { - kotlinType = approximatedType + this.kotlinType = originalKotlinType hasQuestionMark = approximatedType.isMarkedNullable this.variance = variance when (ktTypeDescriptor) { @@ -140,6 +140,6 @@ class TypeTranslator( if (it.isStarProjection) IrStarProjectionImpl else - translateType(it.type, it.projectionKind) + translateType(it.type, it.type, it.projectionKind) } } diff --git a/compiler/testData/ir/irText/expressions/coercionToUnit.txt b/compiler/testData/ir/irText/expressions/coercionToUnit.txt index d01d2818e25..fc69eeb210b 100644 --- a/compiler/testData/ir/irText/expressions/coercionToUnit.txt +++ b/compiler/testData/ir/irText/expressions/coercionToUnit.txt @@ -36,7 +36,8 @@ FILE fqName: fileName:/coercionToUnit.kt BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: CALL 'public open fun println (x: kotlin.String?): kotlin.Unit declared in java.io.PrintStream' type=kotlin.Unit origin=null - $this: GET_VAR 'val tmp0_safe_receiver: java.io.PrintStream? [val] declared in .test3' type=java.io.PrintStream? origin=null + $this: TYPE_OP type=java.io.PrintStream origin=IMPLICIT_NOTNULL typeOperand=java.io.PrintStream + GET_VAR 'val tmp0_safe_receiver: java.io.PrintStream? [val] declared in .test3' type=java.io.PrintStream? origin=null x: CONST String type=kotlin.String value="Hello," TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit BLOCK type=kotlin.Unit? origin=SAFE_CALL @@ -51,5 +52,6 @@ FILE fqName: fileName:/coercionToUnit.kt BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: CALL 'public open fun println (x: kotlin.String?): kotlin.Unit declared in java.io.PrintStream' type=kotlin.Unit origin=null - $this: GET_VAR 'val tmp1_safe_receiver: java.io.PrintStream? [val] declared in .test3' type=java.io.PrintStream? origin=null + $this: TYPE_OP type=java.io.PrintStream origin=IMPLICIT_NOTNULL typeOperand=java.io.PrintStream + GET_VAR 'val tmp1_safe_receiver: java.io.PrintStream? [val] declared in .test3' type=java.io.PrintStream? origin=null x: CONST String type=kotlin.String value="world!" diff --git a/compiler/testData/ir/irText/expressions/implicitCastOnPlatformType.txt b/compiler/testData/ir/irText/expressions/implicitCastOnPlatformType.txt index c61dd192848..e77a3e499d3 100644 --- a/compiler/testData/ir/irText/expressions/implicitCastOnPlatformType.txt +++ b/compiler/testData/ir/irText/expressions/implicitCastOnPlatformType.txt @@ -2,5 +2,6 @@ FILE fqName: fileName:/implicitCastOnPlatformType.kt FUN name:test visibility:public modality:FINAL <> () returnType:kotlin.String BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun test (): kotlin.String declared in ' - CALL 'public open fun getProperty (key: kotlin.String?): kotlin.String? declared in java.lang.System' type=kotlin.String? origin=null - key: CONST String type=kotlin.String value="test" + TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String + CALL 'public open fun getProperty (key: kotlin.String?): kotlin.String? declared in java.lang.System' type=kotlin.String? origin=null + key: CONST String type=kotlin.String value="test" diff --git a/compiler/testData/ir/irText/expressions/jvmStaticFieldReference.txt b/compiler/testData/ir/irText/expressions/jvmStaticFieldReference.txt index 2b8d63aeb0b..9d1e7256ca0 100644 --- a/compiler/testData/ir/irText/expressions/jvmStaticFieldReference.txt +++ b/compiler/testData/ir/irText/expressions/jvmStaticFieldReference.txt @@ -2,14 +2,16 @@ FILE fqName: fileName:/jvmStaticFieldReference.kt FUN name:testFun visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY CALL 'public open fun println (x: kotlin.String?): kotlin.Unit declared in java.io.PrintStream' type=kotlin.Unit origin=null - $this: GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:out type:java.io.PrintStream? visibility:public [final,static] ' type=java.io.PrintStream? origin=GET_PROPERTY + $this: TYPE_OP type=java.io.PrintStream origin=IMPLICIT_NOTNULL typeOperand=java.io.PrintStream + GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:out type:java.io.PrintStream? visibility:public [final,static] ' type=java.io.PrintStream? origin=GET_PROPERTY x: CONST String type=kotlin.String value="testFun" PROPERTY name:testProp visibility:public modality:FINAL [var] FUN name: visibility:public modality:FINAL <> () returnType:kotlin.Any correspondingProperty: PROPERTY name:testProp visibility:public modality:FINAL [var] BLOCK_BODY CALL 'public open fun println (x: kotlin.String?): kotlin.Unit declared in java.io.PrintStream' type=kotlin.Unit origin=null - $this: GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:out type:java.io.PrintStream? visibility:public [final,static] ' type=java.io.PrintStream? origin=GET_PROPERTY + $this: TYPE_OP type=java.io.PrintStream origin=IMPLICIT_NOTNULL typeOperand=java.io.PrintStream + GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:out type:java.io.PrintStream? visibility:public [final,static] ' type=java.io.PrintStream? origin=GET_PROPERTY x: CONST String type=kotlin.String value="testProp/get" RETURN type=kotlin.Nothing from='public final fun (): kotlin.Any declared in ' CONST Int type=kotlin.Int value=42 @@ -18,7 +20,8 @@ FILE fqName: fileName:/jvmStaticFieldReference.kt VALUE_PARAMETER name:value index:0 type:kotlin.Any BLOCK_BODY CALL 'public open fun println (x: kotlin.String?): kotlin.Unit declared in java.io.PrintStream' type=kotlin.Unit origin=null - $this: GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:out type:java.io.PrintStream? visibility:public [final,static] ' type=java.io.PrintStream? origin=GET_PROPERTY + $this: TYPE_OP type=java.io.PrintStream origin=IMPLICIT_NOTNULL typeOperand=java.io.PrintStream + GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:out type:java.io.PrintStream? visibility:public [final,static] ' type=java.io.PrintStream? origin=GET_PROPERTY x: CONST String type=kotlin.String value="testProp/set" CLASS CLASS name:TestClass modality:FINAL visibility:public superTypes:[kotlin.Any] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.TestClass @@ -34,7 +37,8 @@ FILE fqName: fileName:/jvmStaticFieldReference.kt if: CONST Boolean type=kotlin.Boolean value=true then: BLOCK type=kotlin.Int origin=null CALL 'public open fun println (x: kotlin.String?): kotlin.Unit declared in java.io.PrintStream' type=kotlin.Unit origin=null - $this: GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:out type:java.io.PrintStream? visibility:public [final,static] ' type=java.io.PrintStream? origin=GET_PROPERTY + $this: TYPE_OP type=java.io.PrintStream origin=IMPLICIT_NOTNULL typeOperand=java.io.PrintStream + GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:out type:java.io.PrintStream? visibility:public [final,static] ' type=java.io.PrintStream? origin=GET_PROPERTY x: CONST String type=kotlin.String value="TestClass/test" CONST Int type=kotlin.Int value=42 FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.TestClass) returnType:kotlin.Int @@ -47,7 +51,8 @@ FILE fqName: fileName:/jvmStaticFieldReference.kt ANONYMOUS_INITIALIZER isStatic=false BLOCK_BODY CALL 'public open fun println (x: kotlin.String?): kotlin.Unit declared in java.io.PrintStream' type=kotlin.Unit origin=null - $this: GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:out type:java.io.PrintStream? visibility:public [final,static] ' type=java.io.PrintStream? origin=GET_PROPERTY + $this: TYPE_OP type=java.io.PrintStream origin=IMPLICIT_NOTNULL typeOperand=java.io.PrintStream + GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:out type:java.io.PrintStream? visibility:public [final,static] ' type=java.io.PrintStream? origin=GET_PROPERTY x: CONST String type=kotlin.String value="TestClass/init" FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean overridden: diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.txt b/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.txt index 6aa740e5193..bb3cc620284 100644 --- a/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.txt +++ b/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.txt @@ -106,9 +106,10 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt CALL 'public open fun run1 (r: java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null $this: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .J' type=.J origin=null r: TYPE_OP type=java.lang.Runnable? origin=SAM_CONVERSION typeOperand=java.lang.Runnable? - CALL 'public open fun id (x: T of .J.id?): T of .J.id? declared in .J' type=kotlin.Function0? origin=null - : kotlin.Function0? - x: GET_VAR 'a: kotlin.Function0 declared in .test8' type=kotlin.Function0 origin=null + TYPE_OP type=kotlin.Function0 origin=IMPLICIT_NOTNULL typeOperand=kotlin.Function0 + CALL 'public open fun id (x: T of .J.id?): T of .J.id? declared in .J' type=kotlin.Function0? origin=null + : kotlin.Function0? + x: GET_VAR 'a: kotlin.Function0 declared in .test8' type=kotlin.Function0 origin=null FUN name:test9 visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY CALL 'public open fun run1 (r: java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null diff --git a/compiler/testData/ir/irText/types/explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.fir.txt b/compiler/testData/ir/irText/types/explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.fir.txt new file mode 100644 index 00000000000..1b25680005a --- /dev/null +++ b/compiler/testData/ir/irText/types/explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.fir.txt @@ -0,0 +1,31 @@ +FILE fqName: fileName:/explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.kt + FUN name:testPlatformEqualsPlatform visibility:public modality:FINAL <> () returnType:IrErrorType + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testPlatformEqualsPlatform (): IrErrorType declared in ' + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + CALL 'public open fun null0 (): kotlin.Double? declared in .JavaClass' type=kotlin.Double? origin=null + FUN name:testPlatformEqualsKotlin visibility:public modality:FINAL <> () returnType:IrErrorType + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testPlatformEqualsKotlin (): IrErrorType declared in ' + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + CONST Double type=kotlin.Double value=0.0 + FUN name:testKotlinEqualsPlatform visibility:public modality:FINAL <> () returnType:IrErrorType + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testKotlinEqualsPlatform (): IrErrorType declared in ' + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + CALL 'public open fun null0 (): kotlin.Double? declared in .JavaClass' type=kotlin.Double? origin=null + FUN name:testPlatformCompareToPlatform visibility:public modality:FINAL <> () returnType:IrErrorType + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testPlatformCompareToPlatform (): IrErrorType declared in ' + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + CALL 'public open fun null0 (): kotlin.Double? declared in .JavaClass' type=kotlin.Double? origin=null + FUN name:testPlatformCompareToKotlin visibility:public modality:FINAL <> () returnType:IrErrorType + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testPlatformCompareToKotlin (): IrErrorType declared in ' + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + CONST Double type=kotlin.Double value=0.0 + FUN name:testKotlinCompareToPlatform visibility:public modality:FINAL <> () returnType:IrErrorType + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testKotlinCompareToPlatform (): IrErrorType declared in ' + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + CALL 'public open fun null0 (): kotlin.Double? declared in .JavaClass' type=kotlin.Double? origin=null diff --git a/compiler/testData/ir/irText/types/explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.kt b/compiler/testData/ir/irText/types/explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.kt new file mode 100644 index 00000000000..15d44533650 --- /dev/null +++ b/compiler/testData/ir/irText/types/explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.kt @@ -0,0 +1,28 @@ +// FILE: explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.kt + +fun JavaClass.testPlatformEqualsPlatform() = + null0().equals(null0()) + +fun JavaClass.testPlatformEqualsKotlin() = + null0().equals(0.0) + +fun JavaClass.testKotlinEqualsPlatform() = + 0.0.equals(null0()) + +fun JavaClass.testPlatformCompareToPlatform() = + null0().compareTo(null0()) + +fun JavaClass.testPlatformCompareToKotlin() = + null0().compareTo(0.0) + +fun JavaClass.testKotlinCompareToPlatform() = + 0.0.compareTo(null0()) + +// FILE: JavaClass.java + +public class JavaClass { + public Double null0(){ + return null; + } + +} \ No newline at end of file diff --git a/compiler/testData/ir/irText/types/explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.txt b/compiler/testData/ir/irText/types/explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.txt new file mode 100644 index 00000000000..a964ed2e968 --- /dev/null +++ b/compiler/testData/ir/irText/types/explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.txt @@ -0,0 +1,57 @@ +FILE fqName: fileName:/explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.kt + FUN name:testPlatformEqualsPlatform visibility:public modality:FINAL <> ($receiver:.JavaClass) returnType:kotlin.Boolean + $receiver: VALUE_PARAMETER name: type:.JavaClass + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testPlatformEqualsPlatform (): kotlin.Boolean declared in ' + CALL 'public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Double' type=kotlin.Boolean origin=null + $this: TYPE_OP type=kotlin.Double origin=IMPLICIT_NOTNULL typeOperand=kotlin.Double + CALL 'public open fun null0 (): kotlin.Double? declared in .JavaClass' type=kotlin.Double? origin=null + $this: GET_VAR ': .JavaClass declared in .testPlatformEqualsPlatform' type=.JavaClass origin=null + other: CALL 'public open fun null0 (): kotlin.Double? declared in .JavaClass' type=kotlin.Double? origin=null + $this: GET_VAR ': .JavaClass declared in .testPlatformEqualsPlatform' type=.JavaClass origin=null + FUN name:testPlatformEqualsKotlin visibility:public modality:FINAL <> ($receiver:.JavaClass) returnType:kotlin.Boolean + $receiver: VALUE_PARAMETER name: type:.JavaClass + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testPlatformEqualsKotlin (): kotlin.Boolean declared in ' + CALL 'public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Double' type=kotlin.Boolean origin=null + $this: TYPE_OP type=kotlin.Double origin=IMPLICIT_NOTNULL typeOperand=kotlin.Double + CALL 'public open fun null0 (): kotlin.Double? declared in .JavaClass' type=kotlin.Double? origin=null + $this: GET_VAR ': .JavaClass declared in .testPlatformEqualsKotlin' type=.JavaClass origin=null + other: CONST Double type=kotlin.Double value=0.0 + FUN name:testKotlinEqualsPlatform visibility:public modality:FINAL <> ($receiver:.JavaClass) returnType:kotlin.Boolean + $receiver: VALUE_PARAMETER name: type:.JavaClass + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testKotlinEqualsPlatform (): kotlin.Boolean declared in ' + CALL 'public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Double' type=kotlin.Boolean origin=null + $this: CONST Double type=kotlin.Double value=0.0 + other: CALL 'public open fun null0 (): kotlin.Double? declared in .JavaClass' type=kotlin.Double? origin=null + $this: GET_VAR ': .JavaClass declared in .testKotlinEqualsPlatform' type=.JavaClass origin=null + FUN name:testPlatformCompareToPlatform visibility:public modality:FINAL <> ($receiver:.JavaClass) returnType:kotlin.Int + $receiver: VALUE_PARAMETER name: type:.JavaClass + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testPlatformCompareToPlatform (): kotlin.Int declared in ' + CALL 'public open fun compareTo (other: kotlin.Double): kotlin.Int declared in kotlin.Double' type=kotlin.Int origin=null + $this: TYPE_OP type=kotlin.Double origin=IMPLICIT_NOTNULL typeOperand=kotlin.Double + CALL 'public open fun null0 (): kotlin.Double? declared in .JavaClass' type=kotlin.Double? origin=null + $this: GET_VAR ': .JavaClass declared in .testPlatformCompareToPlatform' type=.JavaClass origin=null + other: TYPE_OP type=kotlin.Double origin=IMPLICIT_NOTNULL typeOperand=kotlin.Double + CALL 'public open fun null0 (): kotlin.Double? declared in .JavaClass' type=kotlin.Double? origin=null + $this: GET_VAR ': .JavaClass declared in .testPlatformCompareToPlatform' type=.JavaClass origin=null + FUN name:testPlatformCompareToKotlin visibility:public modality:FINAL <> ($receiver:.JavaClass) returnType:kotlin.Int + $receiver: VALUE_PARAMETER name: type:.JavaClass + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testPlatformCompareToKotlin (): kotlin.Int declared in ' + CALL 'public open fun compareTo (other: kotlin.Double): kotlin.Int declared in kotlin.Double' type=kotlin.Int origin=null + $this: TYPE_OP type=kotlin.Double origin=IMPLICIT_NOTNULL typeOperand=kotlin.Double + CALL 'public open fun null0 (): kotlin.Double? declared in .JavaClass' type=kotlin.Double? origin=null + $this: GET_VAR ': .JavaClass declared in .testPlatformCompareToKotlin' type=.JavaClass origin=null + other: CONST Double type=kotlin.Double value=0.0 + FUN name:testKotlinCompareToPlatform visibility:public modality:FINAL <> ($receiver:.JavaClass) returnType:kotlin.Int + $receiver: VALUE_PARAMETER name: type:.JavaClass + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testKotlinCompareToPlatform (): kotlin.Int declared in ' + CALL 'public open fun compareTo (other: kotlin.Double): kotlin.Int declared in kotlin.Double' type=kotlin.Int origin=null + $this: CONST Double type=kotlin.Double value=0.0 + other: TYPE_OP type=kotlin.Double origin=IMPLICIT_NOTNULL typeOperand=kotlin.Double + CALL 'public open fun null0 (): kotlin.Double? declared in .JavaClass' type=kotlin.Double? origin=null + $this: GET_VAR ': .JavaClass declared in .testKotlinCompareToPlatform' type=.JavaClass origin=null diff --git a/compiler/testData/ir/irText/types/nullabilityAssertionOnExtensionReceiver.fir.txt b/compiler/testData/ir/irText/types/nullabilityAssertionOnExtensionReceiver.fir.txt new file mode 100644 index 00000000000..6451859a7c9 --- /dev/null +++ b/compiler/testData/ir/irText/types/nullabilityAssertionOnExtensionReceiver.fir.txt @@ -0,0 +1,31 @@ +FILE fqName: fileName:/nullabilityAssertionOnExtensionReceiver.kt + FUN name:extension visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.C + CONSTRUCTOR visibility:public <> () returnType:.C [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:memberExtension visibility:public modality:FINAL <> ($this:.C) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.C + BLOCK_BODY + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:testExt visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun extension (): kotlin.Unit declared in ' type=kotlin.Unit origin=null + FUN name:testMemberExt visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun memberExtension (): kotlin.Unit declared in .C' type=kotlin.Unit origin=null diff --git a/compiler/testData/ir/irText/types/nullabilityAssertionOnExtensionReceiver.kt b/compiler/testData/ir/irText/types/nullabilityAssertionOnExtensionReceiver.kt new file mode 100644 index 00000000000..96b7c8de473 --- /dev/null +++ b/compiler/testData/ir/irText/types/nullabilityAssertionOnExtensionReceiver.kt @@ -0,0 +1,20 @@ +// FILE: nullabilityAssertionOnExtensionReceiver.kt + +fun String.extension() {} + +class C { + fun String.memberExtension() {} +} + +fun testExt() { + J.s().extension() +} + +fun C.testMemberExt() { + J.s().memberExtension() +} + +// FILE: J.java +public class J { + public static String s() { return null; } +} diff --git a/compiler/testData/ir/irText/types/nullabilityAssertionOnExtensionReceiver.txt b/compiler/testData/ir/irText/types/nullabilityAssertionOnExtensionReceiver.txt new file mode 100644 index 00000000000..27054f3629f --- /dev/null +++ b/compiler/testData/ir/irText/types/nullabilityAssertionOnExtensionReceiver.txt @@ -0,0 +1,39 @@ +FILE fqName: fileName:/nullabilityAssertionOnExtensionReceiver.kt + FUN name:extension visibility:public modality:FINAL <> ($receiver:kotlin.String) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name: type:kotlin.String + BLOCK_BODY + CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.C + CONSTRUCTOR visibility:public <> () returnType:.C [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:memberExtension visibility:public modality:FINAL <> ($this:.C, $receiver:kotlin.String) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.C + $receiver: VALUE_PARAMETER name: type:kotlin.String + BLOCK_BODY + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:testExt visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun extension (): kotlin.Unit declared in ' type=kotlin.Unit origin=null + $receiver: TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String + CALL 'public open fun s (): kotlin.String? declared in .J' type=kotlin.String? origin=null + FUN name:testMemberExt visibility:public modality:FINAL <> ($receiver:.C) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name: type:.C + BLOCK_BODY + CALL 'public final fun memberExtension (): kotlin.Unit declared in .C' type=kotlin.Unit origin=null + $this: GET_VAR ': .C declared in .testMemberExt' type=.C origin=null + $receiver: TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String + CALL 'public open fun s (): kotlin.String? declared in .J' type=kotlin.String? origin=null diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index 160db98128d..18b09557331 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -1606,6 +1606,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/ir/irText/types"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.kt") + public void testExplicitEqualsAndCompareToCallsOnPlatformTypeReceiver() throws Exception { + runTest("compiler/testData/ir/irText/types/explicitEqualsAndCompareToCallsOnPlatformTypeReceiver.kt"); + } + @TestMetadata("intersectionType1_NI.kt") public void testIntersectionType1_NI() throws Exception { runTest("compiler/testData/ir/irText/types/intersectionType1_NI.kt"); @@ -1640,5 +1645,10 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { public void testLocalVariableOfIntersectionType_NI() throws Exception { runTest("compiler/testData/ir/irText/types/localVariableOfIntersectionType_NI.kt"); } + + @TestMetadata("nullabilityAssertionOnExtensionReceiver.kt") + public void testNullabilityAssertionOnExtensionReceiver() throws Exception { + runTest("compiler/testData/ir/irText/types/nullabilityAssertionOnExtensionReceiver.kt"); + } } }