diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt index 19a0b7c596a..52444579a92 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.references.FirPropertyFromParameterCallableRefer import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.fir.resolve.buildUseSiteScope +import org.jetbrains.kotlin.fir.resolve.calls.SyntheticPropertySymbol import org.jetbrains.kotlin.fir.resolve.toSymbol import org.jetbrains.kotlin.fir.scopes.ProcessorAction import org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope @@ -39,7 +40,6 @@ import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.symbols.* import org.jetbrains.kotlin.ir.types.IrType -import org.jetbrains.kotlin.ir.types.classifierOrFail import org.jetbrains.kotlin.ir.types.classifierOrNull import org.jetbrains.kotlin.ir.types.impl.IrErrorTypeImpl import org.jetbrains.kotlin.ir.types.makeNullable @@ -632,13 +632,27 @@ internal class Fir2IrVisitor( return wrappedArgumentExpression.expression.toIrExpression() } + private fun FirReference.statementOrigin(): IrStatementOrigin? { + return when (this) { + is FirPropertyFromParameterCallableReference -> IrStatementOrigin.INITIALIZE_PROPERTY_FROM_PARAMETER + is FirResolvedCallableReference -> when (coneSymbol) { + is FirAccessorSymbol, is SyntheticPropertySymbol -> IrStatementOrigin.GET_PROPERTY + else -> null + } + else -> null + } + } + private fun FirQualifiedAccess.toIrExpression(typeRef: FirTypeRef): IrExpression { val type = typeRef.toIrType(this@Fir2IrVisitor.session, declarationStorage) val symbol = calleeReference.toSymbol(declarationStorage) return typeRef.convertWithOffsets { startOffset, endOffset -> when { symbol is IrConstructorSymbol -> IrConstructorCallImpl.fromSymbolOwner(startOffset, endOffset, type, symbol) - symbol is IrSimpleFunctionSymbol -> IrCallImpl(startOffset, endOffset, type, symbol) + symbol is IrSimpleFunctionSymbol -> IrCallImpl( + startOffset, endOffset, type, symbol, symbol.descriptor, + origin = calleeReference.statementOrigin() + ) symbol is IrPropertySymbol && symbol.isBound -> { val getter = symbol.owner.getter if (getter != null) { @@ -650,9 +664,7 @@ internal class Fir2IrVisitor( symbol is IrFieldSymbol -> IrGetFieldImpl(startOffset, endOffset, symbol, type, origin = IrStatementOrigin.GET_PROPERTY) symbol is IrValueSymbol -> IrGetValueImpl( startOffset, endOffset, type, symbol, - if (calleeReference is FirPropertyFromParameterCallableReference) { - IrStatementOrigin.INITIALIZE_PROPERTY_FROM_PARAMETER - } else null + origin = calleeReference.statementOrigin() ) else -> IrErrorCallExpressionImpl(startOffset, endOffset, type, "Unresolved reference: ${calleeReference.render()}") } diff --git a/compiler/testData/ir/irText/expressions/javaSyntheticPropertyAccess.fir.txt b/compiler/testData/ir/irText/expressions/javaSyntheticPropertyAccess.fir.txt index b482fbd1ebc..5541ffb5067 100644 --- a/compiler/testData/ir/irText/expressions/javaSyntheticPropertyAccess.fir.txt +++ b/compiler/testData/ir/irText/expressions/javaSyntheticPropertyAccess.fir.txt @@ -2,11 +2,11 @@ FILE fqName: fileName:/javaSyntheticPropertyAccess.kt FUN name:test visibility:public modality:FINAL <> (j:.J) returnType:kotlin.Unit VALUE_PARAMETER name:j index:0 type:.J BLOCK_BODY - CALL 'public open fun getFoo (): kotlin.Int declared in .J' type=kotlin.Int origin=null + CALL 'public open fun getFoo (): kotlin.Int declared in .J' type=kotlin.Int origin=GET_PROPERTY $this: GET_VAR 'j: .J declared in .test' type=.J origin=null ERROR_CALL 'Unresolved reference: R|/J.foo|' type=IrErrorType VAR name: type:kotlin.Int [val] - CALL 'public open fun getFoo (): kotlin.Int declared in .J' type=kotlin.Int origin=null + CALL 'public open fun getFoo (): kotlin.Int declared in .J' type=kotlin.Int origin=GET_PROPERTY $this: GET_VAR 'j: .J declared in .test' type=.J origin=null ERROR_CALL 'Unresolved reference: R|/J.foo|' type=IrErrorType GET_VAR 'val : kotlin.Int [val] declared in .test' type=kotlin.Int origin=null diff --git a/compiler/testData/ir/irText/stubs/javaSyntheticProperty.fir.txt b/compiler/testData/ir/irText/stubs/javaSyntheticProperty.fir.txt deleted file mode 100644 index a72e0aaed5e..00000000000 --- a/compiler/testData/ir/irText/stubs/javaSyntheticProperty.fir.txt +++ /dev/null @@ -1,11 +0,0 @@ -FILE fqName: fileName:/javaSyntheticProperty.kt - PROPERTY name:test visibility:public modality:FINAL [val] - FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.String? visibility:public [final,static] - EXPRESSION_BODY - CALL 'public open fun getFoo (): kotlin.String? declared in .J' type=kotlin.String? origin=null - $this: CONSTRUCTOR_CALL 'public/*package*/ constructor () [primary] declared in .J' type=.J origin=null - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.String? - correspondingProperty: PROPERTY name:test visibility:public modality:FINAL [val] - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): kotlin.String? declared in ' - GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.String? visibility:public [final,static] ' type=kotlin.String? origin=null diff --git a/compiler/testData/ir/irText/stubs/javaSyntheticProperty.kt b/compiler/testData/ir/irText/stubs/javaSyntheticProperty.kt index 3fed59d2988..5b1920c2104 100644 --- a/compiler/testData/ir/irText/stubs/javaSyntheticProperty.kt +++ b/compiler/testData/ir/irText/stubs/javaSyntheticProperty.kt @@ -1,5 +1,6 @@ // !DUMP_DEPENDENCIES // FILE: javaSyntheticProperty.kt +// FIR_IDENTICAL val test = J().foo // FILE: J.java