FIR2IR: set origin correctly for synthetic property accesses

This commit is contained in:
Mikhail Glukhikh
2019-07-10 19:02:52 +03:00
parent c6a09dba4e
commit 43c6049f02
4 changed files with 20 additions and 18 deletions
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.references.FirPropertyFromParameterCallableRefer
import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider
import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.fir.resolve.ScopeSession
import org.jetbrains.kotlin.fir.resolve.buildUseSiteScope 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.resolve.toSymbol
import org.jetbrains.kotlin.fir.scopes.ProcessorAction import org.jetbrains.kotlin.fir.scopes.ProcessorAction
import org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope 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.expressions.impl.*
import org.jetbrains.kotlin.ir.symbols.* import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.types.IrType 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.classifierOrNull
import org.jetbrains.kotlin.ir.types.impl.IrErrorTypeImpl import org.jetbrains.kotlin.ir.types.impl.IrErrorTypeImpl
import org.jetbrains.kotlin.ir.types.makeNullable import org.jetbrains.kotlin.ir.types.makeNullable
@@ -632,13 +632,27 @@ internal class Fir2IrVisitor(
return wrappedArgumentExpression.expression.toIrExpression() 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 { private fun FirQualifiedAccess.toIrExpression(typeRef: FirTypeRef): IrExpression {
val type = typeRef.toIrType(this@Fir2IrVisitor.session, declarationStorage) val type = typeRef.toIrType(this@Fir2IrVisitor.session, declarationStorage)
val symbol = calleeReference.toSymbol(declarationStorage) val symbol = calleeReference.toSymbol(declarationStorage)
return typeRef.convertWithOffsets { startOffset, endOffset -> return typeRef.convertWithOffsets { startOffset, endOffset ->
when { when {
symbol is IrConstructorSymbol -> IrConstructorCallImpl.fromSymbolOwner(startOffset, endOffset, type, symbol) 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 -> { symbol is IrPropertySymbol && symbol.isBound -> {
val getter = symbol.owner.getter val getter = symbol.owner.getter
if (getter != null) { if (getter != null) {
@@ -650,9 +664,7 @@ internal class Fir2IrVisitor(
symbol is IrFieldSymbol -> IrGetFieldImpl(startOffset, endOffset, symbol, type, origin = IrStatementOrigin.GET_PROPERTY) symbol is IrFieldSymbol -> IrGetFieldImpl(startOffset, endOffset, symbol, type, origin = IrStatementOrigin.GET_PROPERTY)
symbol is IrValueSymbol -> IrGetValueImpl( symbol is IrValueSymbol -> IrGetValueImpl(
startOffset, endOffset, type, symbol, startOffset, endOffset, type, symbol,
if (calleeReference is FirPropertyFromParameterCallableReference) { origin = calleeReference.statementOrigin()
IrStatementOrigin.INITIALIZE_PROPERTY_FROM_PARAMETER
} else null
) )
else -> IrErrorCallExpressionImpl(startOffset, endOffset, type, "Unresolved reference: ${calleeReference.render()}") else -> IrErrorCallExpressionImpl(startOffset, endOffset, type, "Unresolved reference: ${calleeReference.render()}")
} }
@@ -2,11 +2,11 @@ FILE fqName:<root> fileName:/javaSyntheticPropertyAccess.kt
FUN name:test visibility:public modality:FINAL <> (j:<root>.J) returnType:kotlin.Unit FUN name:test visibility:public modality:FINAL <> (j:<root>.J) returnType:kotlin.Unit
VALUE_PARAMETER name:j index:0 type:<root>.J VALUE_PARAMETER name:j index:0 type:<root>.J
BLOCK_BODY BLOCK_BODY
CALL 'public open fun getFoo (): kotlin.Int declared in <root>.J' type=kotlin.Int origin=null CALL 'public open fun getFoo (): kotlin.Int declared in <root>.J' type=kotlin.Int origin=GET_PROPERTY
$this: GET_VAR 'j: <root>.J declared in <root>.test' type=<root>.J origin=null $this: GET_VAR 'j: <root>.J declared in <root>.test' type=<root>.J origin=null
ERROR_CALL 'Unresolved reference: R|/J.foo|' type=IrErrorType ERROR_CALL 'Unresolved reference: R|/J.foo|' type=IrErrorType
VAR name:<unary> type:kotlin.Int [val] VAR name:<unary> type:kotlin.Int [val]
CALL 'public open fun getFoo (): kotlin.Int declared in <root>.J' type=kotlin.Int origin=null CALL 'public open fun getFoo (): kotlin.Int declared in <root>.J' type=kotlin.Int origin=GET_PROPERTY
$this: GET_VAR 'j: <root>.J declared in <root>.test' type=<root>.J origin=null $this: GET_VAR 'j: <root>.J declared in <root>.test' type=<root>.J origin=null
ERROR_CALL 'Unresolved reference: R|/J.foo|' type=IrErrorType ERROR_CALL 'Unresolved reference: R|/J.foo|' type=IrErrorType
GET_VAR 'val <unary>: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null GET_VAR 'val <unary>: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null
@@ -1,11 +0,0 @@
FILE fqName:<root> 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 <root>.J' type=kotlin.String? origin=null
$this: CONSTRUCTOR_CALL 'public/*package*/ constructor <init> () [primary] declared in <root>.J' type=<root>.J origin=null
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test> 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 <get-test> (): kotlin.String? declared in <root>'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.String? visibility:public [final,static] ' type=kotlin.String? origin=null
@@ -1,5 +1,6 @@
// !DUMP_DEPENDENCIES // !DUMP_DEPENDENCIES
// FILE: javaSyntheticProperty.kt // FILE: javaSyntheticProperty.kt
// FIR_IDENTICAL
val test = J().foo val test = J().foo
// FILE: J.java // FILE: J.java