FIR2IR: generate this reference to non-source class properly

#KT-53983 Fixed
This commit is contained in:
Mikhail Glukhikh
2022-11-18 16:24:43 +01:00
committed by Space Team
parent dc8ac50ddf
commit 1aae9d6456
10 changed files with 228 additions and 1 deletions
@@ -515,7 +515,14 @@ class Fir2IrVisitor(
if (boundSymbol is FirClassSymbol) {
// Object case
val firClass = boundSymbol.fir as FirClass
val irClass = classifierStorage.getCachedIrClass(firClass)!!
val irClass = if (firClass.origin == FirDeclarationOrigin.Source) {
// We anyway can use 'else' branch as fallback, but
// this is an additional check of FIR2IR invariants
// (source classes should be already built when we analyze bodies)
classifierStorage.getCachedIrClass(firClass)!!
} else {
classifierStorage.getIrClassSymbol(boundSymbol).owner
}
// NB: IR generates anonymous objects as classes, not singleton objects
if (firClass is FirRegularClass && firClass.classKind == ClassKind.OBJECT && !isThisForClassPhysicallyAvailable(irClass)) {
return thisReceiverExpression.convertWithOffsets { startOffset, endOffset ->
@@ -2750,6 +2750,12 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
runTest("compiler/testData/ir/irText/firProblems/SyntheticSetterType.kt");
}
@Test
@TestMetadata("thisInEnumConstructor.kt")
public void testThisInEnumConstructor() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/thisInEnumConstructor.kt");
}
@Test
@TestMetadata("throwableStackTrace.kt")
public void testThrowableStackTrace() throws Exception {
@@ -2750,6 +2750,12 @@ public class LightTreeFir2IrTextTestGenerated extends AbstractLightTreeFir2IrTex
runTest("compiler/testData/ir/irText/firProblems/SyntheticSetterType.kt");
}
@Test
@TestMetadata("thisInEnumConstructor.kt")
public void testThisInEnumConstructor() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/thisInEnumConstructor.kt");
}
@Test
@TestMetadata("throwableStackTrace.kt")
public void testThrowableStackTrace() throws Exception {
@@ -0,0 +1,76 @@
FILE fqName:<root> fileName:/thisInEnumConstructor.kt
CLASS ENUM_CLASS name:EE modality:OPEN visibility:public superTypes:[kotlin.Enum<<root>.EE>]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.EE
CONSTRUCTOR visibility:private <> (myName:kotlin.String) returnType:<root>.EE [primary]
VALUE_PARAMETER name:myName index:0 type:kotlin.String
EXPRESSION_BODY
CALL 'public final fun lowercase (): kotlin.String [inline] declared in kotlin.text.StringsKt' type=kotlin.String origin=null
$receiver: CALL 'public open fun toString (): kotlin.String [fake_override] declared in kotlin.Enum.Companion' type=kotlin.String origin=null
$this: GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Companion modality:FINAL visibility:public [companion] superTypes:[kotlin.Any]' type=kotlin.Enum.Companion
BLOCK_BODY
ENUM_CONSTRUCTOR_CALL 'public constructor <init> (name: kotlin.String, ordinal: kotlin.Int) [primary] declared in kotlin.Enum'
<E>: <root>.EE
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_CLASS name:EE modality:OPEN visibility:public superTypes:[kotlin.Enum<<root>.EE>]'
PROPERTY name:myName visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:myName type:kotlin.String visibility:private [final]
EXPRESSION_BODY
GET_VAR 'myName: kotlin.String declared in <root>.EE.<init>' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-myName> visibility:public modality:FINAL <> ($this:<root>.EE) returnType:kotlin.String
correspondingProperty: PROPERTY name:myName visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.EE
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-myName> (): kotlin.String declared in <root>.EE'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:myName type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
receiver: GET_VAR '<this>: <root>.EE declared in <root>.EE.<get-myName>' type=<root>.EE origin=null
ENUM_ENTRY name:ENTRY
init: EXPRESSION_BODY
ENUM_CONSTRUCTOR_CALL 'private constructor <init> (myName: kotlin.String) [primary] declared in <root>.EE'
FUN ENUM_CLASS_SPECIAL_MEMBER name:values visibility:public modality:FINAL <> () returnType:kotlin.Array<<root>.EE>
SYNTHETIC_BODY kind=ENUM_VALUES
FUN ENUM_CLASS_SPECIAL_MEMBER name:valueOf visibility:public modality:FINAL <> (value:kotlin.String) returnType:<root>.EE
VALUE_PARAMETER name:value index:0 type:kotlin.String
SYNTHETIC_BODY kind=ENUM_VALUEOF
FUN FAKE_OVERRIDE name:clone visibility:protected modality:FINAL <> ($this:kotlin.Enum<E of kotlin.Enum>) returnType:kotlin.Any [fake_override]
overridden:
protected final fun clone (): kotlin.Any declared in kotlin.Enum
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<E of kotlin.Enum>
FUN FAKE_OVERRIDE name:compareTo visibility:public modality:FINAL <> ($this:kotlin.Enum<E of kotlin.Enum>, other:<root>.EE) returnType:kotlin.Int [fake_override,operator]
overridden:
public final fun compareTo (other: E of kotlin.Enum): kotlin.Int [operator] declared in kotlin.Enum
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<E of kotlin.Enum>
VALUE_PARAMETER name:other index:0 type:<root>.EE
FUN FAKE_OVERRIDE name:equals visibility:public modality:FINAL <> ($this:kotlin.Enum<E of kotlin.Enum>, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public final fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Enum
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<E of kotlin.Enum>
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:FINAL <> ($this:kotlin.Enum<E of kotlin.Enum>) returnType:kotlin.Int [fake_override]
overridden:
public final fun hashCode (): kotlin.Int declared in kotlin.Enum
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<E of kotlin.Enum>
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Enum<E of kotlin.Enum>) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Enum
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<E of kotlin.Enum>
PROPERTY FAKE_OVERRIDE name:name visibility:public modality:FINAL [fake_override,val]
annotations:
IntrinsicConstEvaluation
overridden:
public final name: kotlin.String [val]
FUN FAKE_OVERRIDE name:<get-name> visibility:public modality:FINAL <> ($this:kotlin.Enum<E of kotlin.Enum>) returnType:kotlin.String [fake_override]
correspondingProperty: PROPERTY FAKE_OVERRIDE name:name visibility:public modality:FINAL [fake_override,val]
overridden:
public final fun <get-name> (): kotlin.String declared in kotlin.Enum
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<E of kotlin.Enum>
PROPERTY FAKE_OVERRIDE name:ordinal visibility:public modality:FINAL [fake_override,val]
overridden:
public final ordinal: kotlin.Int [val]
FUN FAKE_OVERRIDE name:<get-ordinal> visibility:public modality:FINAL <> ($this:kotlin.Enum<E of kotlin.Enum>) returnType:kotlin.Int [fake_override]
correspondingProperty: PROPERTY FAKE_OVERRIDE name:ordinal visibility:public modality:FINAL [fake_override,val]
overridden:
public final fun <get-ordinal> (): kotlin.Int declared in kotlin.Enum
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<E of kotlin.Enum>
FUN FAKE_OVERRIDE name:getDeclaringClass visibility:public modality:FINAL <> ($this:kotlin.Enum<E of kotlin.Enum>) returnType:@[FlexibleNullability] java.lang.Class<@[FlexibleNullability] <root>.EE?>? [fake_override]
overridden:
public final fun getDeclaringClass (): @[FlexibleNullability] java.lang.Class<@[FlexibleNullability] E of kotlin.Enum?>? declared in kotlin.Enum
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<E of kotlin.Enum>
@@ -0,0 +1,18 @@
open enum class EE : Enum<EE> {
private constructor(myName: String = Companion.toString().lowercase()) /* primary */ {
super/*Enum*/<EE>()
/* <init>() */
}
val myName: String
field = myName
get
ENTRY = EE()
fun values(): Array<EE> /* Synthetic body for ENUM_VALUES */
fun valueOf(value: String): EE /* Synthetic body for ENUM_VALUEOF */
}
@@ -0,0 +1,80 @@
FILE fqName:<root> fileName:/thisInEnumConstructor.kt
CLASS ENUM_CLASS name:EE modality:FINAL visibility:public superTypes:[kotlin.Enum<<root>.EE>]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.EE
CONSTRUCTOR visibility:private <> (myName:kotlin.String) returnType:<root>.EE [primary]
VALUE_PARAMETER name:myName index:0 type:kotlin.String
EXPRESSION_BODY
CALL 'public final fun lowercase (): kotlin.String [inline] declared in kotlin.text.StringsKt' type=kotlin.String origin=null
$receiver: CALL 'public open fun toString (): kotlin.String [fake_override] declared in kotlin.Enum.Companion' type=kotlin.String origin=null
$this: GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Companion modality:FINAL visibility:public [companion] superTypes:[kotlin.Any]' type=kotlin.Enum.Companion
BLOCK_BODY
ENUM_CONSTRUCTOR_CALL 'public constructor <init> (name: kotlin.String, ordinal: kotlin.Int) [primary] declared in kotlin.Enum'
<E>: <root>.EE
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_CLASS name:EE modality:FINAL visibility:public superTypes:[kotlin.Enum<<root>.EE>]'
PROPERTY name:myName visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:myName type:kotlin.String visibility:private [final]
EXPRESSION_BODY
GET_VAR 'myName: kotlin.String declared in <root>.EE.<init>' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-myName> visibility:public modality:FINAL <> ($this:<root>.EE) returnType:kotlin.String
correspondingProperty: PROPERTY name:myName visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.EE
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-myName> (): kotlin.String declared in <root>.EE'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:myName type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
receiver: GET_VAR '<this>: <root>.EE declared in <root>.EE.<get-myName>' type=<root>.EE origin=null
ENUM_ENTRY name:ENTRY
init: EXPRESSION_BODY
ENUM_CONSTRUCTOR_CALL 'private constructor <init> (myName: kotlin.String) [primary] declared in <root>.EE'
PROPERTY FAKE_OVERRIDE name:name visibility:public modality:FINAL [fake_override,val]
annotations:
IntrinsicConstEvaluation
overridden:
public final name: kotlin.String [val]
FUN FAKE_OVERRIDE name:<get-name> visibility:public modality:FINAL <> ($this:kotlin.Enum<<root>.EE>) returnType:kotlin.String [fake_override]
correspondingProperty: PROPERTY FAKE_OVERRIDE name:name visibility:public modality:FINAL [fake_override,val]
overridden:
public final fun <get-name> (): kotlin.String declared in kotlin.Enum
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<<root>.EE>
PROPERTY FAKE_OVERRIDE name:ordinal visibility:public modality:FINAL [fake_override,val]
overridden:
public final ordinal: kotlin.Int [val]
FUN FAKE_OVERRIDE name:<get-ordinal> visibility:public modality:FINAL <> ($this:kotlin.Enum<<root>.EE>) returnType:kotlin.Int [fake_override]
correspondingProperty: PROPERTY FAKE_OVERRIDE name:ordinal visibility:public modality:FINAL [fake_override,val]
overridden:
public final fun <get-ordinal> (): kotlin.Int declared in kotlin.Enum
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<<root>.EE>
FUN FAKE_OVERRIDE name:clone visibility:protected modality:FINAL <> ($this:kotlin.Enum<<root>.EE>) returnType:kotlin.Any [fake_override]
overridden:
protected final fun clone (): kotlin.Any declared in kotlin.Enum
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<<root>.EE>
FUN FAKE_OVERRIDE name:compareTo visibility:public modality:FINAL <> ($this:kotlin.Enum<<root>.EE>, other:<root>.EE) returnType:kotlin.Int [fake_override,operator]
overridden:
public final fun compareTo (other: E of kotlin.Enum): kotlin.Int [operator] declared in kotlin.Enum
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<<root>.EE>
VALUE_PARAMETER name:other index:0 type:<root>.EE
FUN FAKE_OVERRIDE name:equals visibility:public modality:FINAL <> ($this:kotlin.Enum<<root>.EE>, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public final fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Enum
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<<root>.EE>
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:finalize visibility:protected/*protected and package*/ modality:FINAL <> ($this:kotlin.Enum<<root>.EE>) returnType:kotlin.Unit [fake_override]
overridden:
protected/*protected and package*/ final fun finalize (): kotlin.Unit declared in kotlin.Enum
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<<root>.EE>
FUN FAKE_OVERRIDE name:getDeclaringClass visibility:public modality:FINAL <> ($this:kotlin.Enum<<root>.EE>) returnType:@[FlexibleNullability] java.lang.Class<@[FlexibleNullability] <root>.EE?>? [fake_override]
overridden:
public final fun getDeclaringClass (): @[FlexibleNullability] java.lang.Class<@[FlexibleNullability] E of kotlin.Enum?>? declared in kotlin.Enum
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<<root>.EE>
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:FINAL <> ($this:kotlin.Enum<<root>.EE>) returnType:kotlin.Int [fake_override]
overridden:
public final fun hashCode (): kotlin.Int declared in kotlin.Enum
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<<root>.EE>
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Enum<<root>.EE>) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Enum
$this: VALUE_PARAMETER name:<this> type:kotlin.Enum<<root>.EE>
FUN ENUM_CLASS_SPECIAL_MEMBER name:values visibility:public modality:FINAL <> () returnType:kotlin.Array<<root>.EE>
SYNTHETIC_BODY kind=ENUM_VALUES
FUN ENUM_CLASS_SPECIAL_MEMBER name:valueOf visibility:public modality:FINAL <> (value:kotlin.String) returnType:<root>.EE
VALUE_PARAMETER name:value index:0 type:kotlin.String
SYNTHETIC_BODY kind=ENUM_VALUEOF
@@ -0,0 +1,5 @@
// WITH_STDLIB
enum class EE(val myName: String = this.toString().lowercase()) {
ENTRY;
}
@@ -0,0 +1,18 @@
enum class EE : Enum<EE> {
private constructor(myName: String = Companion.toString().lowercase()) /* primary */ {
super/*Enum*/<EE>()
/* <init>() */
}
val myName: String
field = myName
get
ENTRY = EE()
fun values(): Array<EE> /* Synthetic body for ENUM_VALUES */
fun valueOf(value: String): EE /* Synthetic body for ENUM_VALUEOF */
}
@@ -2750,6 +2750,12 @@ public class IrTextTestGenerated extends AbstractIrTextTest {
runTest("compiler/testData/ir/irText/firProblems/SyntheticSetterType.kt");
}
@Test
@TestMetadata("thisInEnumConstructor.kt")
public void testThisInEnumConstructor() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/thisInEnumConstructor.kt");
}
@Test
@TestMetadata("throwableStackTrace.kt")
public void testThrowableStackTrace() throws Exception {
@@ -1990,6 +1990,11 @@ public class KlibTextTestCaseGenerated extends AbstractKlibTextTestCase {
runTest("compiler/testData/ir/irText/firProblems/SimpleTypeMarker.kt");
}
@TestMetadata("thisInEnumConstructor.kt")
public void testThisInEnumConstructor() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/thisInEnumConstructor.kt");
}
@TestMetadata("TypeParameterBounds.kt")
public void testTypeParameterBounds() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/TypeParameterBounds.kt");