From ba770f7b61461ac89897cb00ea994152a391d76c Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 12 Feb 2020 17:02:41 +0300 Subject: [PATCH] FIR2IR: fix type parameter indexes & fix some black-box & FIR2IR tests --- .../fir/backend/Fir2IrDeclarationStorage.kt | 15 ++++++--------- .../declarations/localDelegatedProperties.fir.txt | 6 ++++-- .../declarations/parameters/constructor.fir.txt | 2 +- .../expressions/funInterface/partialSam.fir.txt | 2 +- .../ir/irText/expressions/kt30020.fir.txt | 5 ++--- .../smartCastsWithDestructuring.fir.txt | 6 ++++-- .../newInference/fixationOrder1.fir.txt | 2 +- ...edNullabilityInDestructuringAssignment.fir.txt | 2 +- .../types/smartCastOnFakeOverrideReceiver.fir.txt | 2 +- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index 84ec10e2687..7efce98fa60 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -130,15 +130,11 @@ class Fir2IrDeclarationStorage( } } - private fun IrClass.setThisReceiver(typeParameters: List? = null) { + private fun IrClass.setThisReceiver() { enterScope(descriptor) - val typeArguments = typeParameters?.map { - IrSimpleTypeImpl( - it.symbol.toTypeParameterSymbol(this@Fir2IrDeclarationStorage), - false, - emptyList(), - emptyList()) - } ?: emptyList() + val typeArguments = this.typeParameters.map { + IrSimpleTypeImpl(it.symbol, false, emptyList(), emptyList()) + } thisReceiver = declareThisReceiverParameter( parent = this, thisType = IrSimpleTypeImpl(symbol, false, typeArguments, emptyList()), @@ -204,7 +200,6 @@ class Fir2IrDeclarationStorage( parent = getIrExternalPackageFragment(packageFqName) } } - setThisReceiver((klass as? FirRegularClass)?.typeParameters) } } } @@ -216,11 +211,13 @@ class Fir2IrDeclarationStorage( val created = create() localStorage.putLocalClass(klass, created) created.declareSupertypesAndTypeParameters(klass) + created.setThisReceiver() return created } // NB: klass can be either FirRegularClass or FirAnonymousObject return classCache.getOrPut(klass as FirRegularClass, { create() }) { it.declareSupertypesAndTypeParameters(klass) + it.setThisReceiver() } } diff --git a/compiler/testData/ir/irText/declarations/localDelegatedProperties.fir.txt b/compiler/testData/ir/irText/declarations/localDelegatedProperties.fir.txt index 5d7aecd75e3..57d05105d5a 100644 --- a/compiler/testData/ir/irText/declarations/localDelegatedProperties.fir.txt +++ b/compiler/testData/ir/irText/declarations/localDelegatedProperties.fir.txt @@ -14,8 +14,10 @@ FILE fqName: fileName:/localDelegatedProperties.kt GET_VAR 'var x: IrErrorType [var] declared in .test2' type=IrErrorType origin=null SET_VAR 'var x: IrErrorType [var] declared in .test2' type=IrErrorType origin=null CALL 'public final fun inc (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null - $this: GET_VAR 'val tmp_0: kotlin.Int [val] declared in .test2' type=kotlin.Int origin=null - GET_VAR 'val tmp_0: kotlin.Int [val] declared in .test2' type=kotlin.Int origin=null + $this: TYPE_OP type=IrErrorType origin=IMPLICIT_CAST typeOperand=IrErrorType + GET_VAR 'val tmp_0: kotlin.Int [val] declared in .test2' type=kotlin.Int origin=null + TYPE_OP type=IrErrorType origin=IMPLICIT_CAST typeOperand=IrErrorType + GET_VAR 'val tmp_0: kotlin.Int [val] declared in .test2' type=kotlin.Int origin=null SET_VAR 'var x: IrErrorType [var] declared in .test2' type=IrErrorType origin=null CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null $this: GET_VAR 'var x: IrErrorType [var] declared in .test2' type=kotlin.Int origin=null diff --git a/compiler/testData/ir/irText/declarations/parameters/constructor.fir.txt b/compiler/testData/ir/irText/declarations/parameters/constructor.fir.txt index 7012f9f9b3a..385f3a38364 100644 --- a/compiler/testData/ir/irText/declarations/parameters/constructor.fir.txt +++ b/compiler/testData/ir/irText/declarations/parameters/constructor.fir.txt @@ -2,7 +2,7 @@ FILE fqName: fileName:/constructor.kt CLASS CLASS name:Test1 modality:FINAL visibility:public superTypes:[kotlin.Any] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Test1.Test1, T2 of .Test1> TYPE_PARAMETER name:T1 index:0 variance: superTypes:[kotlin.Any?] - TYPE_PARAMETER name:T2 index:0 variance: superTypes:[kotlin.Any?] + TYPE_PARAMETER name:T2 index:1 variance: superTypes:[kotlin.Any?] CONSTRUCTOR visibility:public <> (x:T1 of .Test1, y:T2 of .Test1) returnType:.Test1.Test1, T2 of .Test1> [primary] VALUE_PARAMETER name:x index:0 type:T1 of .Test1 VALUE_PARAMETER name:y index:1 type:T2 of .Test1 diff --git a/compiler/testData/ir/irText/expressions/funInterface/partialSam.fir.txt b/compiler/testData/ir/irText/expressions/funInterface/partialSam.fir.txt index 1cb468e9559..23de6d185b3 100644 --- a/compiler/testData/ir/irText/expressions/funInterface/partialSam.fir.txt +++ b/compiler/testData/ir/irText/expressions/funInterface/partialSam.fir.txt @@ -2,7 +2,7 @@ FILE fqName: fileName:/partialSam.kt CLASS INTERFACE name:Fn modality:ABSTRACT visibility:public superTypes:[kotlin.Any] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Fn.Fn, R of .Fn> TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] - TYPE_PARAMETER name:R index:0 variance: superTypes:[kotlin.Any?] + TYPE_PARAMETER name:R index:1 variance: superTypes:[kotlin.Any?] FUN name:run visibility:public modality:ABSTRACT <> ($this:.Fn.Fn, R of .Fn>, s:kotlin.String, i:kotlin.Int, t:T of .Fn) returnType:R of .Fn $this: VALUE_PARAMETER name: type:.Fn.Fn, R of .Fn> VALUE_PARAMETER name:s index:0 type:kotlin.String diff --git a/compiler/testData/ir/irText/expressions/kt30020.fir.txt b/compiler/testData/ir/irText/expressions/kt30020.fir.txt index 60ced3602c0..4eb8f16441f 100644 --- a/compiler/testData/ir/irText/expressions/kt30020.fir.txt +++ b/compiler/testData/ir/irText/expressions/kt30020.fir.txt @@ -37,7 +37,7 @@ FILE fqName: fileName:/kt30020.kt CALL 'public final fun plusAssign (element: T of kotlin.collections.plusAssign): kotlin.Unit [inline,operator] declared in kotlin.collections' type=kotlin.Unit origin=null : kotlin.Int $receiver: TYPE_OP type=kotlin.collections.MutableList origin=CAST typeOperand=kotlin.collections.MutableList - CALL 'public abstract fun (): kotlin.collections.MutableList declared in .X' type=kotlin.collections.MutableList origin=null + CALL 'public abstract fun (): kotlin.collections.MutableList declared in .X' type=kotlin.collections.MutableList origin=null $this: GET_VAR 'x: .X declared in .test' type=.X origin=null element: CONST Int type=kotlin.Int value=3 CALL 'public final fun plusAssign (element: T of kotlin.collections.plusAssign): kotlin.Unit [inline,operator] declared in kotlin.collections' type=kotlin.Unit origin=null @@ -58,8 +58,7 @@ FILE fqName: fileName:/kt30020.kt $receiver: CALL 'public final fun CHECK_NOT_NULL (arg0: T0 of kotlin.internal.ir.CHECK_NOT_NULL?): T0 of kotlin.internal.ir.CHECK_NOT_NULL declared in kotlin.internal.ir' type=kotlin.collections.MutableList origin=EXCLEXCL : kotlin.collections.MutableList arg0: CALL 'public abstract fun f (): kotlin.collections.MutableList declared in .X' type=kotlin.collections.MutableList? origin=null - $this: TYPE_OP type=.X origin=IMPLICIT_CAST typeOperand=.X - GET_VAR 'nx: .X? declared in .test' type=.X? origin=null + $this: GET_VAR 'nx: .X? declared in .test' type=.X? origin=null element: CONST Int type=kotlin.Int value=6 FUN name:testExtensionReceiver visibility:public modality:FINAL <> ($receiver:kotlin.collections.MutableList) returnType:kotlin.Unit $receiver: VALUE_PARAMETER name: type:kotlin.collections.MutableList diff --git a/compiler/testData/ir/irText/expressions/smartCastsWithDestructuring.fir.txt b/compiler/testData/ir/irText/expressions/smartCastsWithDestructuring.fir.txt index 5776b9e0b2c..cc5b7599bec 100644 --- a/compiler/testData/ir/irText/expressions/smartCastsWithDestructuring.fir.txt +++ b/compiler/testData/ir/irText/expressions/smartCastsWithDestructuring.fir.txt @@ -53,7 +53,9 @@ FILE fqName: fileName:/smartCastsWithDestructuring.kt GET_VAR 'x: .I1 declared in .test' type=.I1 origin=null VAR name:c1 type:kotlin.Int [val] CALL 'public final fun component1 (): kotlin.Int [operator] declared in ' type=kotlin.Int origin=null - $receiver: GET_VAR 'val tmp_0: .I2 [val] declared in .test' type=.I2 origin=null + $receiver: TYPE_OP type=.I1 origin=IMPLICIT_CAST typeOperand=.I1 + GET_VAR 'val tmp_0: .I2 [val] declared in .test' type=.I2 origin=null VAR name:c2 type:kotlin.String [val] CALL 'public final fun component2 (): kotlin.String [operator] declared in ' type=kotlin.String origin=null - $receiver: GET_VAR 'val tmp_0: .I2 [val] declared in .test' type=.I2 origin=null + $receiver: TYPE_OP type=.I1 origin=IMPLICIT_CAST typeOperand=.I1 + GET_VAR 'val tmp_0: .I2 [val] declared in .test' type=.I2 origin=null diff --git a/compiler/testData/ir/irText/regressions/newInference/fixationOrder1.fir.txt b/compiler/testData/ir/irText/regressions/newInference/fixationOrder1.fir.txt index afa5bf17fa0..3839b8632fd 100644 --- a/compiler/testData/ir/irText/regressions/newInference/fixationOrder1.fir.txt +++ b/compiler/testData/ir/irText/regressions/newInference/fixationOrder1.fir.txt @@ -8,7 +8,7 @@ FILE fqName: fileName:/fixationOrder1.kt CLASS INTERFACE name:Inv2 modality:ABSTRACT visibility:public superTypes:[kotlin.Any] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Inv2.Inv2, B of .Inv2> TYPE_PARAMETER name:A index:0 variance: superTypes:[kotlin.Any?] - TYPE_PARAMETER name:B index:0 variance: superTypes:[kotlin.Any?] + TYPE_PARAMETER name:B index:1 variance: 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 diff --git a/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInDestructuringAssignment.fir.txt b/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInDestructuringAssignment.fir.txt index 27a9c869801..1a833a74212 100644 --- a/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInDestructuringAssignment.fir.txt +++ b/compiler/testData/ir/irText/types/nullChecks/enhancedNullabilityInDestructuringAssignment.fir.txt @@ -61,7 +61,7 @@ FILE fqName: fileName:/enhancedNullabilityInDestructuringAssignment.kt CLASS CLASS name:Q modality:FINAL visibility:public superTypes:[kotlin.Any] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Q.Q, T2 of .Q> TYPE_PARAMETER name:T1 index:0 variance: superTypes:[kotlin.Any?] - TYPE_PARAMETER name:T2 index:0 variance: superTypes:[kotlin.Any?] + TYPE_PARAMETER name:T2 index:1 variance: superTypes:[kotlin.Any?] CONSTRUCTOR visibility:public <> (x:T1 of .Q, y:T2 of .Q) returnType:.Q.Q, T2 of .Q> [primary] VALUE_PARAMETER name:x index:0 type:T1 of .Q VALUE_PARAMETER name:y index:1 type:T2 of .Q diff --git a/compiler/testData/ir/irText/types/smartCastOnFakeOverrideReceiver.fir.txt b/compiler/testData/ir/irText/types/smartCastOnFakeOverrideReceiver.fir.txt index 5daeb806f97..659078757e9 100644 --- a/compiler/testData/ir/irText/types/smartCastOnFakeOverrideReceiver.fir.txt +++ b/compiler/testData/ir/irText/types/smartCastOnFakeOverrideReceiver.fir.txt @@ -172,7 +172,7 @@ FILE fqName: fileName:/smartCastOnFakeOverrideReceiver.kt CLASS CLASS name:GB modality:FINAL visibility:public superTypes:[.GA.GB>] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.GB.GB, S of .GB> TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] - TYPE_PARAMETER name:S index:0 variance: superTypes:[kotlin.Any?] + TYPE_PARAMETER name:S index:1 variance: superTypes:[kotlin.Any?] CONSTRUCTOR visibility:public <> () returnType:.GB.GB, S of .GB> [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in .GA'