FIR2IR: make delegate field/accessors sources closer to PSI2IR
#KT-59864 Fixed
This commit is contained in:
committed by
Space Team
parent
47fec1a113
commit
4b2a122f80
+6
-2
@@ -43,8 +43,12 @@ object FirAmbiguousAnonymousTypeChecker : FirBasicDeclarationChecker() {
|
||||
*/
|
||||
val (type, source) = when (declaration) {
|
||||
is FirProperty -> {
|
||||
declaration.initializer?.resolvedType?.let { it to declaration.source }
|
||||
?: (declaration.getter?.body?.singleExpressionType to declaration.getter?.source)
|
||||
declaration.initializer?.resolvedType?.let { it to declaration.source } ?: run {
|
||||
val getter = declaration.getter
|
||||
// Getter can have delegate call as the source, but diagnostic must be reported on KtDeclaration
|
||||
val getterDeclarationSource = if (declaration.delegate != null) declaration.source else getter?.source
|
||||
(getter?.body?.singleExpressionType to getterDeclarationSource)
|
||||
}
|
||||
}
|
||||
is FirFunction -> declaration.body?.singleExpressionType to declaration.source
|
||||
else -> error("Should not be there")
|
||||
|
||||
+18
-16
@@ -566,22 +566,24 @@ class Fir2IrCallableDeclarationsGenerator(val components: Fir2IrComponents) : Fi
|
||||
): IrField = convertCatching(firProperty) {
|
||||
val inferredType = type ?: firInitializerExpression!!.resolvedType.toIrType()
|
||||
return declareIrField { symbol ->
|
||||
irFactory.createField(
|
||||
startOffset = irProperty.startOffset,
|
||||
endOffset = irProperty.endOffset,
|
||||
origin = origin,
|
||||
name = name,
|
||||
visibility = visibility,
|
||||
symbol = symbol,
|
||||
type = inferredType,
|
||||
isFinal = isFinal,
|
||||
isStatic = firProperty.isStatic || !(irProperty.parent is IrClass || irProperty.parent is IrScript),
|
||||
isExternal = firProperty.isExternal,
|
||||
).also {
|
||||
it.correspondingPropertySymbol = irProperty.symbol
|
||||
}.apply {
|
||||
metadata = FirMetadataSource.Property(firProperty)
|
||||
convertAnnotationsForNonDeclaredMembers(firProperty, origin)
|
||||
(firProperty.delegate ?: firProperty.backingField ?: firProperty).convertWithOffsets { startOffset: Int, endOffset: Int ->
|
||||
irFactory.createField(
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = origin,
|
||||
name = name,
|
||||
visibility = visibility,
|
||||
symbol = symbol,
|
||||
type = inferredType,
|
||||
isFinal = isFinal,
|
||||
isStatic = firProperty.isStatic || !(irProperty.parent is IrClass || irProperty.parent is IrScript),
|
||||
isExternal = firProperty.isExternal,
|
||||
).also {
|
||||
it.correspondingPropertySymbol = irProperty.symbol
|
||||
}.apply {
|
||||
metadata = FirMetadataSource.Property(firProperty)
|
||||
convertAnnotationsForNonDeclaredMembers(firProperty, origin)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.builder
|
||||
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.KtRealSourceElementKind
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.contracts.description.LogicOperationKind
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
@@ -446,7 +447,9 @@ fun <T> FirPropertyBuilder.generateAccessorsByDelegate(
|
||||
val annotations = getter?.annotations
|
||||
val returnTarget = FirFunctionTarget(null, isLambda = false)
|
||||
val getterStatus = getter?.status
|
||||
val getterElement = getter?.source?.fakeElement(KtFakeSourceElementKind.DelegatedPropertyAccessor) ?: fakeSource
|
||||
val getterElement = getter?.source?.takeIf {
|
||||
it.kind == KtRealSourceElementKind
|
||||
}?.fakeElement(KtFakeSourceElementKind.DelegatedPropertyAccessor) ?: fakeSource
|
||||
getter = buildPropertyAccessor {
|
||||
this.source = getterElement
|
||||
this.moduleData = moduleData
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
@5:0..13:1 DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||
@5:0..13:1 INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:MyClass modality:FINAL visibility:public superTypes:[kotlin.Any]'
|
||||
@6:4..8:5 PROPERTY name:lazyProp visibility:public modality:FINAL [delegated,val]
|
||||
@6:4..8:5 FIELD PROPERTY_DELEGATE name:lazyProp$delegate type:kotlin.Lazy<kotlin.Int> visibility:private [final]
|
||||
@6:20..8:5 FIELD PROPERTY_DELEGATE name:lazyProp$delegate type:kotlin.Lazy<kotlin.Int> visibility:private [final]
|
||||
@6:20..8:5 EXPRESSION_BODY
|
||||
@6:20..8:5 CALL 'public final fun lazy <T> (initializer: kotlin.Function0<T of kotlin.lazy>): kotlin.Lazy<T of kotlin.lazy> declared in kotlin' type=kotlin.Lazy<kotlin.Int> origin=null
|
||||
@6:25..8:5 FUN_EXPR type=kotlin.Function0<kotlin.Int> origin=LAMBDA
|
||||
@@ -13,8 +13,8 @@
|
||||
@7:8..9 BLOCK_BODY
|
||||
@7:9..9 RETURN type=kotlin.Nothing from='local final fun <anonymous> (): kotlin.Int declared in <root>.MyClass.lazyProp$delegate'
|
||||
@7:8..9 CONST Int type=kotlin.Int value=5
|
||||
@6:4..8:5 FUN DELEGATED_PROPERTY_ACCESSOR name:<get-lazyProp> visibility:public modality:FINAL <> ($this:<root>.MyClass) returnType:kotlin.Int
|
||||
@6:4..8:5 VALUE_PARAMETER name:<this> type:<root>.MyClass
|
||||
@6:20..8:5 FUN DELEGATED_PROPERTY_ACCESSOR name:<get-lazyProp> visibility:public modality:FINAL <> ($this:<root>.MyClass) returnType:kotlin.Int
|
||||
@6:20..8:5 VALUE_PARAMETER name:<this> type:<root>.MyClass
|
||||
@6:20..8:5 BLOCK_BODY
|
||||
@6:20..8:5 RETURN type=kotlin.Nothing from='public final fun <get-lazyProp> (): kotlin.Int declared in <root>.MyClass'
|
||||
@6:20..8:5 CALL 'public final fun getValue <T> (thisRef: kotlin.Any?, property: kotlin.reflect.KProperty<*>): T of kotlin.getValue [inline,operator] declared in kotlin' type=kotlin.Int origin=null
|
||||
@@ -23,7 +23,7 @@
|
||||
@6:20..8:5 GET_VAR '<this>: <root>.MyClass declared in <root>.MyClass.<get-lazyProp>' type=<root>.MyClass origin=null
|
||||
@6:20..8:5 PROPERTY_REFERENCE 'public final lazyProp: kotlin.Int [delegated,val]' field=null getter='public final fun <get-lazyProp> (): kotlin.Int declared in <root>.MyClass' setter=null type=kotlin.reflect.KProperty1<<root>.MyClass, kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE
|
||||
@10:4..12:5 PROPERTY name:observableProp visibility:public modality:FINAL [delegated,var]
|
||||
@10:4..12:5 FIELD PROPERTY_DELEGATE name:observableProp$delegate type:kotlin.properties.ReadWriteProperty<kotlin.Any?, kotlin.String> visibility:private [final]
|
||||
@10:34..12:5 FIELD PROPERTY_DELEGATE name:observableProp$delegate type:kotlin.properties.ReadWriteProperty<kotlin.Any?, kotlin.String> visibility:private [final]
|
||||
@10:44..12:5 EXPRESSION_BODY
|
||||
@10:44..12:5 CALL 'public final fun observable <T> (initialValue: T of kotlin.properties.Delegates.observable, onChange: kotlin.Function3<@[ParameterName(name = 'property')] kotlin.reflect.KProperty<*>, @[ParameterName(name = 'oldValue')] T of kotlin.properties.Delegates.observable, @[ParameterName(name = 'newValue')] T of kotlin.properties.Delegates.observable, kotlin.Unit>): kotlin.properties.ReadWriteProperty<kotlin.Any?, T of kotlin.properties.Delegates.observable> [inline] declared in kotlin.properties.Delegates' type=kotlin.properties.ReadWriteProperty<kotlin.Any?, kotlin.String> origin=null
|
||||
@10:34..43 GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Delegates modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.properties.Delegates
|
||||
@@ -40,8 +40,8 @@
|
||||
@11:22..25 GET_VAR 'old: @[ParameterName(name = 'oldValue')] kotlin.String declared in <root>.MyClass.observableProp$delegate.<anonymous>' type=@[ParameterName(name = 'oldValue')] kotlin.String origin=null
|
||||
@11:25..31 CONST String type=kotlin.String value=", now "
|
||||
@11:32..35 GET_VAR 'new: @[ParameterName(name = 'newValue')] kotlin.String declared in <root>.MyClass.observableProp$delegate.<anonymous>' type=@[ParameterName(name = 'newValue')] kotlin.String origin=null
|
||||
@10:4..12:5 FUN DELEGATED_PROPERTY_ACCESSOR name:<get-observableProp> visibility:public modality:FINAL <> ($this:<root>.MyClass) returnType:kotlin.String
|
||||
@10:4..12:5 VALUE_PARAMETER name:<this> type:<root>.MyClass
|
||||
@10:34..12:5 FUN DELEGATED_PROPERTY_ACCESSOR name:<get-observableProp> visibility:public modality:FINAL <> ($this:<root>.MyClass) returnType:kotlin.String
|
||||
@10:34..12:5 VALUE_PARAMETER name:<this> type:<root>.MyClass
|
||||
@10:34..12:5 BLOCK_BODY
|
||||
@10:34..12:5 RETURN type=kotlin.Nothing from='public final fun <get-observableProp> (): kotlin.String declared in <root>.MyClass'
|
||||
@10:34..12:5 CALL 'public abstract fun getValue (thisRef: T of kotlin.properties.ReadWriteProperty, property: kotlin.reflect.KProperty<*>): V of kotlin.properties.ReadWriteProperty [operator] declared in kotlin.properties.ReadWriteProperty' type=kotlin.String origin=null
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
@0:0..9:0 FILE fqName:<root> fileName:/kt24258.kt
|
||||
@3:0..53 PROPERTY name:lazyNullString visibility:public modality:FINAL [delegated,val]
|
||||
@3:0..53 FIELD PROPERTY_DELEGATE name:lazyNullString$delegate type:kotlin.Lazy<@[FlexibleNullability] kotlin.String?> visibility:private [final,static]
|
||||
@3:30..53 FIELD PROPERTY_DELEGATE name:lazyNullString$delegate type:kotlin.Lazy<@[FlexibleNullability] kotlin.String?> visibility:private [final,static]
|
||||
@3:30..53 EXPRESSION_BODY
|
||||
@3:30..53 CALL 'public final fun lazy <T> (initializer: kotlin.Function0<T of kotlin.lazy>): kotlin.Lazy<T of kotlin.lazy> declared in kotlin' type=kotlin.Lazy<@[FlexibleNullability] kotlin.String?> origin=null
|
||||
@3:35..53 FUN_EXPR type=kotlin.Function0<@[FlexibleNullability] kotlin.String?> origin=LAMBDA
|
||||
@@ -8,7 +8,7 @@
|
||||
@3:37..51 BLOCK_BODY
|
||||
@3:51..51 RETURN type=kotlin.Nothing from='local final fun <anonymous> (): @[FlexibleNullability] kotlin.String? declared in <root>.lazyNullString$delegate'
|
||||
@3:39..51 CALL 'public open fun nullString (): @[FlexibleNullability] kotlin.String? declared in <root>.J' type=@[FlexibleNullability] kotlin.String? origin=null
|
||||
@3:0..53 FUN DELEGATED_PROPERTY_ACCESSOR name:<get-lazyNullString> visibility:public modality:FINAL <> () returnType:kotlin.String
|
||||
@3:30..53 FUN DELEGATED_PROPERTY_ACCESSOR name:<get-lazyNullString> visibility:public modality:FINAL <> () returnType:kotlin.String
|
||||
@3:30..53 BLOCK_BODY
|
||||
@3:30..53 RETURN type=kotlin.Nothing from='public final fun <get-lazyNullString> (): kotlin.String declared in <root>'
|
||||
@3:30..53 TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String
|
||||
|
||||
Reference in New Issue
Block a user