mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-22 15:51:33 +00:00
IR: IrField.isFakeOverride
This commit is contained in:
@@ -21,6 +21,7 @@ interface IrField :
|
||||
val isFinal: Boolean
|
||||
val isExternal: Boolean
|
||||
val isStatic: Boolean
|
||||
val isFakeOverride: Boolean
|
||||
|
||||
var initializer: IrExpressionBody?
|
||||
|
||||
|
||||
@@ -43,7 +43,8 @@ class IrFieldImpl(
|
||||
override val visibility: Visibility,
|
||||
override val isFinal: Boolean,
|
||||
override val isExternal: Boolean,
|
||||
override val isStatic: Boolean
|
||||
override val isStatic: Boolean,
|
||||
override val isFakeOverride: Boolean
|
||||
) : IrDeclarationBase(startOffset, endOffset, origin),
|
||||
IrField {
|
||||
|
||||
@@ -60,7 +61,8 @@ class IrFieldImpl(
|
||||
symbol.descriptor.name, type, visibility,
|
||||
isFinal = !symbol.descriptor.isVar,
|
||||
isExternal = symbol.descriptor.isEffectivelyExternal(),
|
||||
isStatic = symbol.descriptor.dispatchReceiverParameter == null
|
||||
isStatic = symbol.descriptor.dispatchReceiverParameter == null,
|
||||
isFakeOverride = origin == IrDeclarationOrigin.FAKE_OVERRIDE
|
||||
)
|
||||
|
||||
constructor(
|
||||
|
||||
@@ -34,6 +34,7 @@ class IrLazyField(
|
||||
override val isFinal: Boolean,
|
||||
override val isExternal: Boolean,
|
||||
override val isStatic: Boolean,
|
||||
override val isFakeOverride: Boolean,
|
||||
stubGenerator: DeclarationStubGenerator,
|
||||
typeTranslator: TypeTranslator
|
||||
) : IrLazyDeclarationBase(startOffset, endOffset, origin, stubGenerator, typeTranslator),
|
||||
@@ -50,11 +51,12 @@ class IrLazyField(
|
||||
startOffset, endOffset, origin, symbol,
|
||||
symbol.descriptor.name,
|
||||
symbol.descriptor.visibility,
|
||||
!symbol.descriptor.isVar,
|
||||
symbol.descriptor.isEffectivelyExternal(),
|
||||
symbol.descriptor.dispatchReceiverParameter == null,
|
||||
stubGenerator,
|
||||
typeTranslator
|
||||
isFinal = !symbol.descriptor.isVar,
|
||||
isExternal = symbol.descriptor.isEffectivelyExternal(),
|
||||
isStatic = symbol.descriptor.dispatchReceiverParameter == null,
|
||||
isFakeOverride = origin == IrDeclarationOrigin.FAKE_OVERRIDE,
|
||||
stubGenerator = stubGenerator,
|
||||
typeTranslator = typeTranslator
|
||||
)
|
||||
|
||||
init {
|
||||
|
||||
@@ -243,9 +243,10 @@ open class DeepCopyIrTreeWithSymbols(
|
||||
symbolRenamer.getFieldName(declaration.symbol),
|
||||
declaration.type.remapType(),
|
||||
declaration.visibility,
|
||||
declaration.isFinal,
|
||||
declaration.isExternal,
|
||||
declaration.isStatic
|
||||
isFinal = declaration.isFinal,
|
||||
isExternal = declaration.isExternal,
|
||||
isStatic = declaration.isStatic,
|
||||
isFakeOverride = declaration.isFakeOverride
|
||||
).apply {
|
||||
transformAnnotations(declaration)
|
||||
declaration.overriddenSymbols.mapTo(overriddenSymbols) {
|
||||
|
||||
@@ -431,7 +431,8 @@ class RenderIrElementVisitor : IrElementVisitor<String, Nothing?> {
|
||||
renderFlagsList(
|
||||
"final".takeIf { isFinal },
|
||||
"external".takeIf { isExternal },
|
||||
"static".takeIf { isStatic }
|
||||
"static".takeIf { isStatic },
|
||||
"fake_override".takeIf { isFakeOverride }
|
||||
)
|
||||
|
||||
override fun visitClass(declaration: IrClass, data: Nothing?): String =
|
||||
|
||||
@@ -7,24 +7,24 @@ FILE fqName:<root> fileName:/Derived.kt
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Derived modality:FINAL visibility:public superTypes:[<root>.Base]'
|
||||
ANONYMOUS_INITIALIZER isStatic=false
|
||||
BLOCK_BODY
|
||||
SET_FIELD 'FIELD FAKE_OVERRIDE name:value type:kotlin.Int visibility:public' type=kotlin.Unit origin=EQ
|
||||
SET_FIELD 'FIELD FAKE_OVERRIDE name:value type:kotlin.Int visibility:public [fake_override]' type=kotlin.Unit origin=EQ
|
||||
receiver: GET_VAR '<this>: <root>.Derived declared in <root>.Derived' type=<root>.Derived origin=null
|
||||
value: CONST Int type=kotlin.Int value=0
|
||||
FUN name:getValue visibility:public modality:FINAL <> ($this:<root>.Derived) returnType:kotlin.Int
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Derived
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun getValue (): kotlin.Int declared in <root>.Derived'
|
||||
GET_FIELD 'FIELD FAKE_OVERRIDE name:value type:kotlin.Int visibility:public' type=kotlin.Int origin=GET_PROPERTY
|
||||
GET_FIELD 'FIELD FAKE_OVERRIDE name:value type:kotlin.Int visibility:public [fake_override]' type=kotlin.Int origin=GET_PROPERTY
|
||||
receiver: GET_VAR '<this>: <root>.Derived declared in <root>.Derived.getValue' type=<root>.Derived origin=null
|
||||
FUN name:setValue visibility:public modality:FINAL <> ($this:<root>.Derived, value:kotlin.Int) returnType:kotlin.Unit
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Derived
|
||||
VALUE_PARAMETER name:value index:0 type:kotlin.Int
|
||||
BLOCK_BODY
|
||||
SET_FIELD 'FIELD FAKE_OVERRIDE name:value type:kotlin.Int visibility:public' type=kotlin.Unit origin=EQ
|
||||
SET_FIELD 'FIELD FAKE_OVERRIDE name:value type:kotlin.Int visibility:public [fake_override]' type=kotlin.Unit origin=EQ
|
||||
receiver: GET_VAR '<this>: <root>.Derived declared in <root>.Derived.setValue' type=<root>.Derived origin=null
|
||||
value: GET_VAR 'value: kotlin.Int declared in <root>.Derived.setValue' type=kotlin.Int origin=null
|
||||
PROPERTY FAKE_OVERRIDE name:value visibility:public modality:FINAL [fake_override,var]
|
||||
FIELD FAKE_OVERRIDE name:value type:kotlin.Int visibility:public
|
||||
FIELD FAKE_OVERRIDE name:value type:kotlin.Int visibility:public [fake_override]
|
||||
overridden:
|
||||
FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:value type:kotlin.Int visibility:public
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override]
|
||||
|
||||
@@ -132,11 +132,11 @@ FILE fqName:<root> fileName:/kt16904.kt
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Test2 modality:FINAL visibility:public superTypes:[<root>.J]'
|
||||
ANONYMOUS_INITIALIZER isStatic=false
|
||||
BLOCK_BODY
|
||||
SET_FIELD 'FIELD FAKE_OVERRIDE name:field type:kotlin.Int visibility:public' type=kotlin.Unit origin=EQ
|
||||
SET_FIELD 'FIELD FAKE_OVERRIDE name:field type:kotlin.Int visibility:public [fake_override]' type=kotlin.Unit origin=EQ
|
||||
receiver: GET_VAR '<this>: <root>.Test2 declared in <root>.Test2' type=<root>.Test2 origin=null
|
||||
value: CONST Int type=kotlin.Int value=42
|
||||
PROPERTY FAKE_OVERRIDE name:field visibility:public modality:FINAL [fake_override,var]
|
||||
FIELD FAKE_OVERRIDE name:field type:kotlin.Int visibility:public
|
||||
FIELD FAKE_OVERRIDE name:field type:kotlin.Int visibility:public [fake_override]
|
||||
overridden:
|
||||
FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:field type:kotlin.Int visibility:public
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override]
|
||||
|
||||
@@ -14,12 +14,12 @@ FILE fqName:<root> fileName:/Derived.kt
|
||||
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=kotlin.String
|
||||
GET_VAR 'v: kotlin.Any declared in <root>.Derived.setValue' type=kotlin.Any origin=null
|
||||
then: BLOCK type=kotlin.Unit origin=null
|
||||
SET_FIELD 'FIELD FAKE_OVERRIDE name:value type:kotlin.String? visibility:public' type=kotlin.Unit origin=EQ
|
||||
SET_FIELD 'FIELD FAKE_OVERRIDE name:value type:kotlin.String? visibility:public [fake_override]' type=kotlin.Unit origin=EQ
|
||||
receiver: GET_VAR '<this>: <root>.Derived declared in <root>.Derived.setValue' type=<root>.Derived origin=null
|
||||
value: TYPE_OP type=kotlin.String origin=IMPLICIT_CAST typeOperand=kotlin.String
|
||||
GET_VAR 'v: kotlin.Any declared in <root>.Derived.setValue' type=kotlin.Any origin=null
|
||||
PROPERTY FAKE_OVERRIDE name:value visibility:public modality:FINAL [fake_override,var]
|
||||
FIELD FAKE_OVERRIDE name:value type:kotlin.String? visibility:public
|
||||
FIELD FAKE_OVERRIDE name:value type:kotlin.String? visibility:public [fake_override]
|
||||
overridden:
|
||||
FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:value type:kotlin.String? visibility:public
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override]
|
||||
|
||||
@@ -18,7 +18,7 @@ FILE fqName:<root> fileName:/javaInnerClass.kt
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test type:<root>.J.JInner visibility:private [final]' type=<root>.J.JInner origin=null
|
||||
receiver: GET_VAR '<this>: <root>.Test1 declared in <root>.Test1.<get-test>' type=<root>.Test1 origin=null
|
||||
PROPERTY FAKE_OVERRIDE name:x visibility:public modality:FINAL [fake_override,var]
|
||||
FIELD FAKE_OVERRIDE name:x type:kotlin.Int visibility:public
|
||||
FIELD FAKE_OVERRIDE name:x type:kotlin.Int visibility:public [fake_override]
|
||||
overridden:
|
||||
FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:x type:kotlin.Int visibility:public
|
||||
FUN FAKE_OVERRIDE name:bar visibility:public modality:OPEN <> ($this:<root>.J) returnType:kotlin.Unit [fake_override]
|
||||
|
||||
@@ -205,6 +205,14 @@ abstract class AbstractIrTextTestCase : AbstractIrGeneratorTestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitField(declaration: IrField) {
|
||||
visitDeclaration(declaration)
|
||||
|
||||
require((declaration.origin == IrDeclarationOrigin.FAKE_OVERRIDE) == declaration.isFakeOverride) {
|
||||
"${declaration.descriptor}: origin: ${declaration.origin}; isFakeOverride: ${declaration.isFakeOverride}"
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitFunction(declaration: IrFunction) {
|
||||
visitDeclaration(declaration)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user