From 714ab7c37f7309e4ddb724dea61922825362bb92 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Thu, 3 Sep 2020 10:39:05 +0300 Subject: [PATCH] Handle java raw types in IR Raw type Q is represented as a flexible type Q .. Q<*, ... *> where Bi is a representative upper bound of the corresponding ith type parameter of Q. When mapping generic signature, JVM takes type arguments of lower bound (which is 'Q'). There is still some difference in how JVM and JVM_IR handle raw type in signature. It requires additional investigation. --- .../kotlin/fir/Fir2IrTextTestGenerated.java | 5 + .../kotlin/ir/util/TypeTranslator.kt | 53 +++--- .../bytecodeListing/rawTypeInSignature.kt | 31 +++ .../bytecodeListing/rawTypeInSignature.txt | 40 ++++ .../bytecodeListing/rawTypeInSignature_ir.txt | 40 ++++ .../irText/types/rawTypeInSignature.fir.txt | 139 ++++++++++++++ .../ir/irText/types/rawTypeInSignature.kt | 28 +++ .../ir/irText/types/rawTypeInSignature.txt | 178 ++++++++++++++++++ .../codegen/BytecodeListingTestGenerated.java | 5 + .../ir/IrBytecodeListingTestGenerated.java | 5 + .../kotlin/ir/IrTextTestCaseGenerated.java | 5 + 11 files changed, 507 insertions(+), 22 deletions(-) create mode 100644 compiler/testData/codegen/bytecodeListing/rawTypeInSignature.kt create mode 100644 compiler/testData/codegen/bytecodeListing/rawTypeInSignature.txt create mode 100644 compiler/testData/codegen/bytecodeListing/rawTypeInSignature_ir.txt create mode 100644 compiler/testData/ir/irText/types/rawTypeInSignature.fir.txt create mode 100644 compiler/testData/ir/irText/types/rawTypeInSignature.kt create mode 100644 compiler/testData/ir/irText/types/rawTypeInSignature.txt 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 b70c2fd7478..e6cd98d0722 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/Fir2IrTextTestGenerated.java @@ -2040,6 +2040,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/types/localVariableOfIntersectionType_NI.kt"); } + @TestMetadata("rawTypeInSignature.kt") + public void testRawTypeInSignature() throws Exception { + runTest("compiler/testData/ir/irText/types/rawTypeInSignature.kt"); + } + @TestMetadata("receiverOfIntersectionType.kt") public void testReceiverOfIntersectionType() throws Exception { runTest("compiler/testData/ir/irText/types/receiverOfIntersectionType.kt"); 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 8e39aa803ed..f96ab834faa 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 @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET +import org.jetbrains.kotlin.ir.declarations.IrConstructor import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl @@ -116,27 +117,22 @@ class TypeTranslator( when (ktTypeDescriptor) { is TypeParameterDescriptor -> { classifier = resolveTypeParameter(ktTypeDescriptor) - annotations = translateTypeAnnotations(approximatedType) + annotations = translateTypeAnnotations(approximatedType, flexibleApproximatedType) } is ClassDescriptor -> { classifier = symbolTable.referenceClass(ktTypeDescriptor) - arguments = translateTypeArguments(approximatedType.arguments) - annotations = translateTypeAnnotations(approximatedType) + arguments = + if (flexibleApproximatedType is RawType) + translateTypeArguments(flexibleApproximatedType.arguments) + else + translateTypeArguments(approximatedType.arguments) + annotations = translateTypeAnnotations(approximatedType, flexibleApproximatedType) } else -> throw AssertionError("Unexpected type descriptor $ktTypeDescriptor :: ${ktTypeDescriptor::class}") } - if (flexibleApproximatedType.isNullabilityFlexible()) - extensions.flexibleNullabilityAnnotationConstructor?.let { flexibleTypeAnnotationConstructor -> - annotations += IrConstructorCallImpl( - UNDEFINED_OFFSET, UNDEFINED_OFFSET, - flexibleTypeAnnotationConstructor.constructedClassType, - flexibleTypeAnnotationConstructor.symbol, - 0, 0, 0 - ) - } }.buildTypeProjection() } @@ -194,27 +190,40 @@ class TypeTranslator( approximateCapturedTypes(ktType).upper } - private fun translateTypeAnnotations(kotlinType: KotlinType): List { + private fun translateTypeAnnotations(kotlinType: KotlinType, flexibleType: KotlinType = kotlinType): List { val annotations = kotlinType.annotations val irAnnotations = ArrayList() + annotations.mapNotNullTo(irAnnotations) { constantValueGenerator.generateAnnotationConstructorCall(it) } + // EnhancedNullability annotation is not present in 'annotations', see 'EnhancedTypeAnnotations::iterator()'. + // Also, EnhancedTypeAnnotationDescriptor is not a "real" annotation descriptor, there's no corresponding ClassDescriptor, etc. if (extensions.enhancedNullability.hasEnhancedNullability(kotlinType)) { - extensions.enhancedNullabilityAnnotationConstructor?.let { irConstructor -> - irAnnotations.add( - IrConstructorCallImpl.fromSymbolOwner( - UNDEFINED_OFFSET, UNDEFINED_OFFSET, - irConstructor.constructedClassType, - irConstructor.symbol - ) - ) - } + irAnnotations.addSpecialAnnotation(extensions.enhancedNullabilityAnnotationConstructor) } + + if (flexibleType.isNullabilityFlexible()) { + irAnnotations.addSpecialAnnotation(extensions.flexibleNullabilityAnnotationConstructor) + } + return irAnnotations } + private fun MutableList.addSpecialAnnotation(irConstructor: IrConstructor?) { + if (irConstructor != null) { + add( + IrConstructorCallImpl.fromSymbolOwner( + UNDEFINED_OFFSET, + UNDEFINED_OFFSET, + irConstructor.constructedClassType, + irConstructor.symbol + ) + ) + } + } + private fun translateTypeArguments(arguments: List) = arguments.map { if (it.isStarProjection) diff --git a/compiler/testData/codegen/bytecodeListing/rawTypeInSignature.kt b/compiler/testData/codegen/bytecodeListing/rawTypeInSignature.kt new file mode 100644 index 00000000000..e518f0f8cd5 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/rawTypeInSignature.kt @@ -0,0 +1,31 @@ +// FILE: rawTypeInSignature.kt +// WITH_SIGNATURES + +class GenericInv +class GenericIn +class GenericOut + +fun testReturnsRawGenericInv(j: JRaw) = j.returnsRawGenericInv() + +fun testReturnsRawGenericIn(j: JRaw) = j.returnsRawGenericIn() + +fun testReturnsRawGenericOut(j: JRaw) = j.returnsRawGenericOut() + +class KRaw(j: JRaw) : JRaw by j +// JVM: public <(Ljava/util/List;)V> method takesRawList(p0: java.util.List): void +// JVM_IR: public <(Ljava/util/List<+Ljava/lang/Object;>;)V> method takesRawList(p0: java.util.List): void + +// FILE: JRaw.java + +import java.util.*; + +public interface JRaw { + void takesRawList(List list); + List returnsRawList(); + void takesRawGenericInv(GenericInv g); + GenericInv returnsRawGenericInv(); + void takesRawGenericIn(GenericIn g); + GenericIn returnsRawGenericIn(); + void takesRawGenericOut(GenericOut g); + GenericOut returnsRawGenericOut(); +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/rawTypeInSignature.txt b/compiler/testData/codegen/bytecodeListing/rawTypeInSignature.txt new file mode 100644 index 00000000000..9668b887eaf --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/rawTypeInSignature.txt @@ -0,0 +1,40 @@ +@kotlin.Metadata +public final class<Ljava/lang/Object;> GenericIn { + // source: 'rawTypeInSignature.kt' + public method (): void +} + +@kotlin.Metadata +public final class<Ljava/lang/Object;> GenericInv { + // source: 'rawTypeInSignature.kt' + public method (): void +} + +@kotlin.Metadata +public final class<Ljava/lang/Object;> GenericOut { + // source: 'rawTypeInSignature.kt' + public method (): void +} + +@kotlin.Metadata +public final class KRaw { + // source: 'rawTypeInSignature.kt' + public <()LGenericIn;> method returnsRawGenericIn(): GenericIn + public <()LGenericInv;> method returnsRawGenericInv(): GenericInv + public <()LGenericOut;> method returnsRawGenericOut(): GenericOut + public <()Ljava/util/List;> method returnsRawList(): java.util.List + public <(LGenericIn<-Ljava/lang/Number;>;)V> method takesRawGenericIn(p0: GenericIn): void + public <(LGenericInv;)V> method takesRawGenericInv(p0: GenericInv): void + public <(LGenericOut<+Ljava/lang/Number;>;)V> method takesRawGenericOut(p0: GenericOut): void + public <(Ljava/util/List;)V> method takesRawList(p0: java.util.List): void + public method (@org.jetbrains.annotations.NotNull p0: JRaw): void + private synthetic final field $$delegate_0: JRaw +} + +@kotlin.Metadata +public final class RawTypeInSignatureKt { + // source: 'rawTypeInSignature.kt' + public final static <(LJRaw;)LGenericIn;> method testReturnsRawGenericIn(@org.jetbrains.annotations.NotNull p0: JRaw): GenericIn + public final static <(LJRaw;)LGenericInv;> method testReturnsRawGenericInv(@org.jetbrains.annotations.NotNull p0: JRaw): GenericInv + public final static <(LJRaw;)LGenericOut;> method testReturnsRawGenericOut(@org.jetbrains.annotations.NotNull p0: JRaw): GenericOut +} diff --git a/compiler/testData/codegen/bytecodeListing/rawTypeInSignature_ir.txt b/compiler/testData/codegen/bytecodeListing/rawTypeInSignature_ir.txt new file mode 100644 index 00000000000..8e51f05b1be --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/rawTypeInSignature_ir.txt @@ -0,0 +1,40 @@ +@kotlin.Metadata +public final class<Ljava/lang/Object;> GenericIn { + // source: 'rawTypeInSignature.kt' + public method (): void +} + +@kotlin.Metadata +public final class<Ljava/lang/Object;> GenericInv { + // source: 'rawTypeInSignature.kt' + public method (): void +} + +@kotlin.Metadata +public final class<Ljava/lang/Object;> GenericOut { + // source: 'rawTypeInSignature.kt' + public method (): void +} + +@kotlin.Metadata +public final class KRaw { + // source: 'rawTypeInSignature.kt' + public <()LGenericIn;> method returnsRawGenericIn(): GenericIn + public <()LGenericInv;> method returnsRawGenericInv(): GenericInv + public <()LGenericOut;> method returnsRawGenericOut(): GenericOut + public <()Ljava/util/List;> method returnsRawList(): java.util.List + public <(LGenericIn<-Ljava/lang/Number;>;)V> method takesRawGenericIn(p0: GenericIn): void + public <(LGenericInv;)V> method takesRawGenericInv(p0: GenericInv): void + public <(LGenericOut<+Ljava/lang/Number;>;)V> method takesRawGenericOut(p0: GenericOut): void + public <(Ljava/util/List<+Ljava/lang/Object;>;)V> method takesRawList(p0: java.util.List): void + public method (@org.jetbrains.annotations.NotNull p0: JRaw): void + private synthetic final field $$delegate_0: JRaw +} + +@kotlin.Metadata +public final class RawTypeInSignatureKt { + // source: 'rawTypeInSignature.kt' + public final static <(LJRaw;)LGenericIn;> method testReturnsRawGenericIn(@org.jetbrains.annotations.NotNull p0: JRaw): GenericIn + public final static <(LJRaw;)LGenericInv;> method testReturnsRawGenericInv(@org.jetbrains.annotations.NotNull p0: JRaw): GenericInv + public final static <(LJRaw;)LGenericOut;> method testReturnsRawGenericOut(@org.jetbrains.annotations.NotNull p0: JRaw): GenericOut +} diff --git a/compiler/testData/ir/irText/types/rawTypeInSignature.fir.txt b/compiler/testData/ir/irText/types/rawTypeInSignature.fir.txt new file mode 100644 index 00000000000..ac2ae9c130b --- /dev/null +++ b/compiler/testData/ir/irText/types/rawTypeInSignature.fir.txt @@ -0,0 +1,139 @@ +FILE fqName: fileName:/rawTypeInSignature.kt + CLASS CLASS name:GenericInv modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.GenericInv.GenericInv> + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Number] + CONSTRUCTOR visibility:public <> () returnType:.GenericInv.GenericInv> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:GenericInv modality:FINAL visibility:public superTypes:[kotlin.Any]' + 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 [operator] 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 [fake_override] + 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 [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:GenericIn modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.GenericIn.GenericIn> + TYPE_PARAMETER name:T index:0 variance:in superTypes:[kotlin.Number] + CONSTRUCTOR visibility:public <> () returnType:.GenericIn.GenericIn> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:GenericIn modality:FINAL visibility:public superTypes:[kotlin.Any]' + 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 [operator] 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 [fake_override] + 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 [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:GenericOut modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.GenericOut.GenericOut> + TYPE_PARAMETER name:T index:0 variance:out superTypes:[kotlin.Number] + CONSTRUCTOR visibility:public <> () returnType:.GenericOut.GenericOut> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:GenericOut modality:FINAL visibility:public superTypes:[kotlin.Any]' + 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 [operator] 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 [fake_override] + 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 [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:testReturnsRawGenericInv visibility:public modality:FINAL <> (j:.JRaw) returnType:.GenericInv<*>? + VALUE_PARAMETER name:j index:0 type:.JRaw + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testReturnsRawGenericInv (j: .JRaw): .GenericInv<*>? declared in ' + CALL 'public abstract fun returnsRawGenericInv (): .GenericInv<*>? declared in .JRaw' type=.GenericInv<*>? origin=null + $this: GET_VAR 'j: .JRaw declared in .testReturnsRawGenericInv' type=.JRaw origin=null + FUN name:testReturnsRawGenericIn visibility:public modality:FINAL <> (j:.JRaw) returnType:.GenericIn? + VALUE_PARAMETER name:j index:0 type:.JRaw + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testReturnsRawGenericIn (j: .JRaw): .GenericIn? declared in ' + CALL 'public abstract fun returnsRawGenericIn (): .GenericIn? declared in .JRaw' type=.GenericIn? origin=null + $this: GET_VAR 'j: .JRaw declared in .testReturnsRawGenericIn' type=.JRaw origin=null + FUN name:testReturnsRawGenericOut visibility:public modality:FINAL <> (j:.JRaw) returnType:.GenericOut<*>? + VALUE_PARAMETER name:j index:0 type:.JRaw + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testReturnsRawGenericOut (j: .JRaw): .GenericOut<*>? declared in ' + CALL 'public abstract fun returnsRawGenericOut (): .GenericOut<*>? declared in .JRaw' type=.GenericOut<*>? origin=null + $this: GET_VAR 'j: .JRaw declared in .testReturnsRawGenericOut' type=.JRaw origin=null + CLASS CLASS name:KRaw modality:FINAL visibility:public superTypes:[.JRaw] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.KRaw + CONSTRUCTOR visibility:public <> (j:.JRaw) returnType:.KRaw [primary] + VALUE_PARAMETER name:j index:0 type:.JRaw + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:KRaw modality:FINAL visibility:public superTypes:[.JRaw]' + SET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:.JRaw visibility:local [final]' type=kotlin.Unit origin=EQ + receiver: GET_VAR ': .KRaw declared in .KRaw' type=.KRaw origin=null + value: GET_VAR 'j: .JRaw declared in .KRaw.' type=.JRaw origin=null + FIELD DELEGATE name:<$$delegate_0> type:.JRaw visibility:local [final] + FUN FAKE_OVERRIDE name:takesRawList visibility:public modality:OPEN <> ($this:.JRaw, list:kotlin.collections.List<*>?) returnType:kotlin.Unit [fake_override] + overridden: + public abstract fun takesRawList (list: kotlin.collections.List<*>?): kotlin.Unit declared in .JRaw + $this: VALUE_PARAMETER name: type:.JRaw + VALUE_PARAMETER name:list index:0 type:kotlin.collections.List<*>? + FUN FAKE_OVERRIDE name:returnsRawList visibility:public modality:OPEN <> ($this:.JRaw) returnType:kotlin.collections.List<*>? [fake_override] + overridden: + public abstract fun returnsRawList (): kotlin.collections.List<*>? declared in .JRaw + $this: VALUE_PARAMETER name: type:.JRaw + FUN FAKE_OVERRIDE name:takesRawGenericInv visibility:public modality:OPEN <> ($this:.JRaw, g:.GenericInv<*>?) returnType:kotlin.Unit [fake_override] + overridden: + public abstract fun takesRawGenericInv (g: .GenericInv<*>?): kotlin.Unit declared in .JRaw + $this: VALUE_PARAMETER name: type:.JRaw + VALUE_PARAMETER name:g index:0 type:.GenericInv<*>? + FUN FAKE_OVERRIDE name:returnsRawGenericInv visibility:public modality:OPEN <> ($this:.JRaw) returnType:.GenericInv<*>? [fake_override] + overridden: + public abstract fun returnsRawGenericInv (): .GenericInv<*>? declared in .JRaw + $this: VALUE_PARAMETER name: type:.JRaw + FUN FAKE_OVERRIDE name:takesRawGenericIn visibility:public modality:OPEN <> ($this:.JRaw, g:.GenericIn?) returnType:kotlin.Unit [fake_override] + overridden: + public abstract fun takesRawGenericIn (g: .GenericIn?): kotlin.Unit declared in .JRaw + $this: VALUE_PARAMETER name: type:.JRaw + VALUE_PARAMETER name:g index:0 type:.GenericIn? + FUN FAKE_OVERRIDE name:returnsRawGenericIn visibility:public modality:OPEN <> ($this:.JRaw) returnType:.GenericIn? [fake_override] + overridden: + public abstract fun returnsRawGenericIn (): .GenericIn? declared in .JRaw + $this: VALUE_PARAMETER name: type:.JRaw + FUN FAKE_OVERRIDE name:takesRawGenericOut visibility:public modality:OPEN <> ($this:.JRaw, g:.GenericOut<*>?) returnType:kotlin.Unit [fake_override] + overridden: + public abstract fun takesRawGenericOut (g: .GenericOut<*>?): kotlin.Unit declared in .JRaw + $this: VALUE_PARAMETER name: type:.JRaw + VALUE_PARAMETER name:g index:0 type:.GenericOut<*>? + FUN FAKE_OVERRIDE name:returnsRawGenericOut visibility:public modality:OPEN <> ($this:.JRaw) returnType:.GenericOut<*>? [fake_override] + overridden: + public abstract fun returnsRawGenericOut (): .GenericOut<*>? declared in .JRaw + $this: VALUE_PARAMETER name: type:.JRaw + 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 [operator] 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 [fake_override] + 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 [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/testData/ir/irText/types/rawTypeInSignature.kt b/compiler/testData/ir/irText/types/rawTypeInSignature.kt new file mode 100644 index 00000000000..bf9abee719b --- /dev/null +++ b/compiler/testData/ir/irText/types/rawTypeInSignature.kt @@ -0,0 +1,28 @@ +// FILE: rawTypeInSignature.kt + +class GenericInv +class GenericIn +class GenericOut + +fun testReturnsRawGenericInv(j: JRaw) = j.returnsRawGenericInv() + +fun testReturnsRawGenericIn(j: JRaw) = j.returnsRawGenericIn() + +fun testReturnsRawGenericOut(j: JRaw) = j.returnsRawGenericOut() + +class KRaw(j: JRaw) : JRaw by j + +// FILE: JRaw.java + +import java.util.*; + +public interface JRaw { + void takesRawList(List list); + List returnsRawList(); + void takesRawGenericInv(GenericInv g); + GenericInv returnsRawGenericInv(); + void takesRawGenericIn(GenericIn g); + GenericIn returnsRawGenericIn(); + void takesRawGenericOut(GenericOut g); + GenericOut returnsRawGenericOut(); +} \ No newline at end of file diff --git a/compiler/testData/ir/irText/types/rawTypeInSignature.txt b/compiler/testData/ir/irText/types/rawTypeInSignature.txt new file mode 100644 index 00000000000..5fa1a2bf5a4 --- /dev/null +++ b/compiler/testData/ir/irText/types/rawTypeInSignature.txt @@ -0,0 +1,178 @@ +FILE fqName: fileName:/rawTypeInSignature.kt + CLASS CLASS name:GenericInv modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.GenericInv.GenericInv> + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Number] + CONSTRUCTOR visibility:public <> () returnType:.GenericInv.GenericInv> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:GenericInv modality:FINAL visibility:public superTypes:[kotlin.Any]' + 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 [operator] 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 [fake_override] + 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 [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:GenericIn modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.GenericIn.GenericIn> + TYPE_PARAMETER name:T index:0 variance:in superTypes:[kotlin.Number] + CONSTRUCTOR visibility:public <> () returnType:.GenericIn.GenericIn> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:GenericIn modality:FINAL visibility:public superTypes:[kotlin.Any]' + 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 [operator] 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 [fake_override] + 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 [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:GenericOut modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.GenericOut.GenericOut> + TYPE_PARAMETER name:T index:0 variance:out superTypes:[kotlin.Number] + CONSTRUCTOR visibility:public <> () returnType:.GenericOut.GenericOut> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:GenericOut modality:FINAL visibility:public superTypes:[kotlin.Any]' + 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 [operator] 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 [fake_override] + 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 [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:testReturnsRawGenericInv visibility:public modality:FINAL <> (j:.JRaw) returnType:@[FlexibleNullability] .GenericInv? + VALUE_PARAMETER name:j index:0 type:.JRaw + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testReturnsRawGenericInv (j: .JRaw): @[FlexibleNullability] .GenericInv? declared in ' + CALL 'public abstract fun returnsRawGenericInv (): @[FlexibleNullability] .GenericInv? declared in .JRaw' type=@[FlexibleNullability] .GenericInv? origin=null + $this: GET_VAR 'j: .JRaw declared in .testReturnsRawGenericInv' type=.JRaw origin=null + FUN name:testReturnsRawGenericIn visibility:public modality:FINAL <> (j:.JRaw) returnType:@[FlexibleNullability] .GenericIn? + VALUE_PARAMETER name:j index:0 type:.JRaw + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testReturnsRawGenericIn (j: .JRaw): @[FlexibleNullability] .GenericIn? declared in ' + CALL 'public abstract fun returnsRawGenericIn (): @[FlexibleNullability] .GenericIn? declared in .JRaw' type=@[FlexibleNullability] .GenericIn? origin=null + $this: GET_VAR 'j: .JRaw declared in .testReturnsRawGenericIn' type=.JRaw origin=null + FUN name:testReturnsRawGenericOut visibility:public modality:FINAL <> (j:.JRaw) returnType:@[FlexibleNullability] .GenericOut? + VALUE_PARAMETER name:j index:0 type:.JRaw + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testReturnsRawGenericOut (j: .JRaw): @[FlexibleNullability] .GenericOut? declared in ' + CALL 'public abstract fun returnsRawGenericOut (): @[FlexibleNullability] .GenericOut? declared in .JRaw' type=@[FlexibleNullability] .GenericOut? origin=null + $this: GET_VAR 'j: .JRaw declared in .testReturnsRawGenericOut' type=.JRaw origin=null + CLASS CLASS name:KRaw modality:FINAL visibility:public superTypes:[.JRaw] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.KRaw + CONSTRUCTOR visibility:public <> (j:.JRaw) returnType:.KRaw [primary] + VALUE_PARAMETER name:j index:0 type:.JRaw + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:KRaw modality:FINAL visibility:public superTypes:[.JRaw]' + FIELD DELEGATE name:$$delegate_0 type:.JRaw visibility:private [final] + EXPRESSION_BODY + GET_VAR 'j: .JRaw declared in .KRaw.' type=.JRaw origin=null + FUN DELEGATED_MEMBER name:returnsRawGenericIn visibility:public modality:OPEN <> ($this:.KRaw) returnType:@[FlexibleNullability] .GenericIn? + overridden: + public abstract fun returnsRawGenericIn (): @[FlexibleNullability] .GenericIn? declared in .JRaw + $this: VALUE_PARAMETER name: type:.KRaw + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun returnsRawGenericIn (): @[FlexibleNullability] .GenericIn? declared in .KRaw' + CALL 'public abstract fun returnsRawGenericIn (): @[FlexibleNullability] .GenericIn? declared in .JRaw' type=@[FlexibleNullability] .GenericIn? origin=null + $this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:.JRaw visibility:private [final]' type=.JRaw origin=null + receiver: GET_VAR ': .KRaw declared in .KRaw.returnsRawGenericIn' type=.KRaw origin=null + FUN DELEGATED_MEMBER name:returnsRawGenericInv visibility:public modality:OPEN <> ($this:.KRaw) returnType:@[FlexibleNullability] .GenericInv? + overridden: + public abstract fun returnsRawGenericInv (): @[FlexibleNullability] .GenericInv? declared in .JRaw + $this: VALUE_PARAMETER name: type:.KRaw + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun returnsRawGenericInv (): @[FlexibleNullability] .GenericInv? declared in .KRaw' + CALL 'public abstract fun returnsRawGenericInv (): @[FlexibleNullability] .GenericInv? declared in .JRaw' type=@[FlexibleNullability] .GenericInv? origin=null + $this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:.JRaw visibility:private [final]' type=.JRaw origin=null + receiver: GET_VAR ': .KRaw declared in .KRaw.returnsRawGenericInv' type=.KRaw origin=null + FUN DELEGATED_MEMBER name:returnsRawGenericOut visibility:public modality:OPEN <> ($this:.KRaw) returnType:@[FlexibleNullability] .GenericOut? + overridden: + public abstract fun returnsRawGenericOut (): @[FlexibleNullability] .GenericOut? declared in .JRaw + $this: VALUE_PARAMETER name: type:.KRaw + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun returnsRawGenericOut (): @[FlexibleNullability] .GenericOut? declared in .KRaw' + CALL 'public abstract fun returnsRawGenericOut (): @[FlexibleNullability] .GenericOut? declared in .JRaw' type=@[FlexibleNullability] .GenericOut? origin=null + $this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:.JRaw visibility:private [final]' type=.JRaw origin=null + receiver: GET_VAR ': .KRaw declared in .KRaw.returnsRawGenericOut' type=.KRaw origin=null + FUN DELEGATED_MEMBER name:returnsRawList visibility:public modality:OPEN <> ($this:.KRaw) returnType:@[FlexibleNullability] kotlin.collections.List? + overridden: + public abstract fun returnsRawList (): @[FlexibleNullability] kotlin.collections.List? declared in .JRaw + $this: VALUE_PARAMETER name: type:.KRaw + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun returnsRawList (): @[FlexibleNullability] kotlin.collections.List? declared in .KRaw' + CALL 'public abstract fun returnsRawList (): @[FlexibleNullability] kotlin.collections.List? declared in .JRaw' type=@[FlexibleNullability] kotlin.collections.List? origin=null + $this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:.JRaw visibility:private [final]' type=.JRaw origin=null + receiver: GET_VAR ': .KRaw declared in .KRaw.returnsRawList' type=.KRaw origin=null + FUN DELEGATED_MEMBER name:takesRawGenericIn visibility:public modality:OPEN <> ($this:.KRaw, g:@[FlexibleNullability] .GenericIn?) returnType:kotlin.Unit + overridden: + public abstract fun takesRawGenericIn (g: @[FlexibleNullability] .GenericIn?): kotlin.Unit declared in .JRaw + $this: VALUE_PARAMETER name: type:.KRaw + VALUE_PARAMETER name:g index:0 type:@[FlexibleNullability] .GenericIn? + BLOCK_BODY + CALL 'public abstract fun takesRawGenericIn (g: @[FlexibleNullability] .GenericIn?): kotlin.Unit declared in .JRaw' type=kotlin.Unit origin=null + $this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:.JRaw visibility:private [final]' type=.JRaw origin=null + receiver: GET_VAR ': .KRaw declared in .KRaw.takesRawGenericIn' type=.KRaw origin=null + g: GET_VAR 'g: @[FlexibleNullability] .GenericIn? declared in .KRaw.takesRawGenericIn' type=@[FlexibleNullability] .GenericIn? origin=null + FUN DELEGATED_MEMBER name:takesRawGenericInv visibility:public modality:OPEN <> ($this:.KRaw, g:@[FlexibleNullability] .GenericInv?) returnType:kotlin.Unit + overridden: + public abstract fun takesRawGenericInv (g: @[FlexibleNullability] .GenericInv?): kotlin.Unit declared in .JRaw + $this: VALUE_PARAMETER name: type:.KRaw + VALUE_PARAMETER name:g index:0 type:@[FlexibleNullability] .GenericInv? + BLOCK_BODY + CALL 'public abstract fun takesRawGenericInv (g: @[FlexibleNullability] .GenericInv?): kotlin.Unit declared in .JRaw' type=kotlin.Unit origin=null + $this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:.JRaw visibility:private [final]' type=.JRaw origin=null + receiver: GET_VAR ': .KRaw declared in .KRaw.takesRawGenericInv' type=.KRaw origin=null + g: GET_VAR 'g: @[FlexibleNullability] .GenericInv? declared in .KRaw.takesRawGenericInv' type=@[FlexibleNullability] .GenericInv? origin=null + FUN DELEGATED_MEMBER name:takesRawGenericOut visibility:public modality:OPEN <> ($this:.KRaw, g:@[FlexibleNullability] .GenericOut?) returnType:kotlin.Unit + overridden: + public abstract fun takesRawGenericOut (g: @[FlexibleNullability] .GenericOut?): kotlin.Unit declared in .JRaw + $this: VALUE_PARAMETER name: type:.KRaw + VALUE_PARAMETER name:g index:0 type:@[FlexibleNullability] .GenericOut? + BLOCK_BODY + CALL 'public abstract fun takesRawGenericOut (g: @[FlexibleNullability] .GenericOut?): kotlin.Unit declared in .JRaw' type=kotlin.Unit origin=null + $this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:.JRaw visibility:private [final]' type=.JRaw origin=null + receiver: GET_VAR ': .KRaw declared in .KRaw.takesRawGenericOut' type=.KRaw origin=null + g: GET_VAR 'g: @[FlexibleNullability] .GenericOut? declared in .KRaw.takesRawGenericOut' type=@[FlexibleNullability] .GenericOut? origin=null + FUN DELEGATED_MEMBER name:takesRawList visibility:public modality:OPEN <> ($this:.KRaw, list:@[FlexibleNullability] kotlin.collections.List?) returnType:kotlin.Unit + overridden: + public abstract fun takesRawList (list: @[FlexibleNullability] kotlin.collections.List?): kotlin.Unit declared in .JRaw + $this: VALUE_PARAMETER name: type:.KRaw + VALUE_PARAMETER name:list index:0 type:@[FlexibleNullability] kotlin.collections.List? + BLOCK_BODY + CALL 'public abstract fun takesRawList (list: @[FlexibleNullability] kotlin.collections.List?): kotlin.Unit declared in .JRaw' type=kotlin.Unit origin=null + $this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:.JRaw visibility:private [final]' type=.JRaw origin=null + receiver: GET_VAR ': .KRaw declared in .KRaw.takesRawList' type=.KRaw origin=null + list: GET_VAR 'list: @[FlexibleNullability] kotlin.collections.List? declared in .KRaw.takesRawList' type=@[FlexibleNullability] kotlin.collections.List? origin=null + 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 .JRaw + $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 [fake_override] + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in .JRaw + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String [fake_override] declared in .JRaw + $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java index 15bcce7f744..cd83cfdd569 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java @@ -149,6 +149,11 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { runTest("compiler/testData/codegen/bytecodeListing/privateNestedClassInInterface.kt"); } + @TestMetadata("rawTypeInSignature.kt") + public void testRawTypeInSignature() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/rawTypeInSignature.kt"); + } + @TestMetadata("samAdapterAndInlinedOne.kt") public void testSamAdapterAndInlinedOne() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/samAdapterAndInlinedOne.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java index 54728756c34..5398e502481 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java @@ -149,6 +149,11 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes runTest("compiler/testData/codegen/bytecodeListing/privateNestedClassInInterface.kt"); } + @TestMetadata("rawTypeInSignature.kt") + public void testRawTypeInSignature() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/rawTypeInSignature.kt"); + } + @TestMetadata("samAdapterAndInlinedOne.kt") public void testSamAdapterAndInlinedOne() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/samAdapterAndInlinedOne.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index 90c639365b0..d32a8a9d013 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -2039,6 +2039,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { runTest("compiler/testData/ir/irText/types/localVariableOfIntersectionType_NI.kt"); } + @TestMetadata("rawTypeInSignature.kt") + public void testRawTypeInSignature() throws Exception { + runTest("compiler/testData/ir/irText/types/rawTypeInSignature.kt"); + } + @TestMetadata("receiverOfIntersectionType.kt") public void testReceiverOfIntersectionType() throws Exception { runTest("compiler/testData/ir/irText/types/receiverOfIntersectionType.kt");