FIR2IR: handle non-ambiguous super references properly
This commit is contained in:
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirUnitExpression
|
||||
import org.jetbrains.kotlin.fir.references.FirReference
|
||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||
import org.jetbrains.kotlin.fir.references.FirSuperReference
|
||||
import org.jetbrains.kotlin.fir.references.impl.FirPropertyFromParameterResolvedNamedReference
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.buildUseSiteMemberScope
|
||||
@@ -705,6 +706,15 @@ class Fir2IrVisitor(
|
||||
val type = typeRef.toIrType(this@Fir2IrVisitor.session, declarationStorage)
|
||||
val symbol = calleeReference.toSymbol(declarationStorage)
|
||||
return typeRef.convertWithOffsets { startOffset, endOffset ->
|
||||
if (calleeReference is FirSuperReference) {
|
||||
if (typeRef !is FirComposedSuperTypeRef) {
|
||||
val dispatchReceiver = functionStack.lastOrNull()?.dispatchReceiverParameter
|
||||
if (dispatchReceiver != null) {
|
||||
// Use the dispatch receiver of the containing function
|
||||
return@convertWithOffsets IrGetValueImpl(startOffset, endOffset, dispatchReceiver.type, dispatchReceiver.symbol)
|
||||
}
|
||||
}
|
||||
}
|
||||
when {
|
||||
symbol is IrConstructorSymbol -> IrConstructorCallImpl.fromSymbolOwner(startOffset, endOffset, type, symbol)
|
||||
symbol is IrSimpleFunctionSymbol -> IrCallImpl(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
open class A {
|
||||
internal open val field = "F"
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
open class A {
|
||||
internal open val field = "F"
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
interface I
|
||||
class C : I { fun foo() = super<I>.hashCode() }
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ FILE fqName:<root> fileName:/enumWithMultipleCtors.kt
|
||||
RETURN type=kotlin.Nothing from='public final fun f (): kotlin.String declared in <root>.A.Y'
|
||||
CALL 'public final fun plus (other: kotlin.Any?): kotlin.String [operator] declared in kotlin.String' type=kotlin.String origin=null
|
||||
$this: CALL 'public open fun f (): kotlin.String declared in <root>.A' type=kotlin.String origin=null
|
||||
$this: GET_VAR '<this>: <uninitialized parent>.<anonymous> declared in <no parent>.<anonymous>' type=<uninitialized parent>.<anonymous> origin=null
|
||||
$this: GET_VAR '<this>: <root>.A.Y declared in <root>.A.Y.f' type=<root>.A.Y origin=null
|
||||
other: CONST String type=kotlin.String value="#Y"
|
||||
ENUM_ENTRY name:Z
|
||||
class: CLASS ENUM_ENTRY name:Z modality:FINAL visibility:local superTypes:[<root>.A]
|
||||
|
||||
+3
-4
@@ -93,12 +93,11 @@ FILE fqName:<root> fileName:/implicitNotNullOnDelegatedImplementation.kt
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.JUnrelatedFoo'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:K4 modality:FINAL visibility:public superTypes:[<root>.JUnrelatedFoo; <root>.IFoo]'
|
||||
FUN name:foo visibility:public modality:FINAL <> ($this:<root>.K4) returnType:kotlin.String
|
||||
FUN name:foo visibility:public modality:FINAL <> ($this:<root>.K4) returnType:IrErrorType
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.K4
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun foo (): kotlin.String declared in <root>.K4'
|
||||
CALL 'public abstract fun foo (): kotlin.String declared in <root>.IFoo' type=kotlin.String origin=null
|
||||
$this: GET_VAR '<this>: <root>.K4 declared in <root>.K4.foo' type=<root>.K4 origin=null
|
||||
RETURN type=kotlin.Nothing from='public final fun foo (): IrErrorType declared in <root>.K4'
|
||||
ERROR_CALL 'Unresolved reference: <Ambiguity: foo, [/JUnrelatedFoo.foo, /IFoo.foo]>#' type=IrErrorType
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
overridden:
|
||||
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
|
||||
|
||||
@@ -59,9 +59,9 @@ FILE fqName:<root> fileName:/qualifiedSuperCalls.kt
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.CBoth
|
||||
BLOCK_BODY
|
||||
CALL 'public open fun foo (): kotlin.Unit declared in <root>.ILeft' type=kotlin.Unit origin=null
|
||||
$this: ERROR_CALL 'Unresolved reference: super<R|ILeft|>' type=<root>.ILeft
|
||||
$this: GET_VAR '<this>: <root>.CBoth declared in <root>.CBoth.foo' type=<root>.CBoth origin=null
|
||||
CALL 'public open fun foo (): kotlin.Unit declared in <root>.IRight' type=kotlin.Unit origin=null
|
||||
$this: ERROR_CALL 'Unresolved reference: super<R|IRight|>' type=<root>.IRight
|
||||
$this: GET_VAR '<this>: <root>.CBoth declared in <root>.CBoth.foo' type=<root>.CBoth origin=null
|
||||
PROPERTY name:bar visibility:public modality:FINAL [val]
|
||||
FUN name:<get-bar> visibility:public modality:FINAL <> ($this:<root>.CBoth) returnType:kotlin.Int
|
||||
correspondingProperty: PROPERTY name:bar visibility:public modality:FINAL [val]
|
||||
@@ -70,9 +70,9 @@ FILE fqName:<root> fileName:/qualifiedSuperCalls.kt
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-bar> (): kotlin.Int declared in <root>.CBoth'
|
||||
CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null
|
||||
$this: CALL 'public open fun <get-bar> (): kotlin.Int declared in <root>.ILeft' type=kotlin.Int origin=null
|
||||
$this: ERROR_CALL 'Unresolved reference: super<R|ILeft|>' type=<root>.ILeft
|
||||
$this: GET_VAR '<this>: <root>.CBoth declared in <root>.CBoth.<get-bar>' type=<root>.CBoth origin=null
|
||||
other: CALL 'public open fun <get-bar> (): kotlin.Int declared in <root>.IRight' type=kotlin.Int origin=null
|
||||
$this: ERROR_CALL 'Unresolved reference: super<R|IRight|>' type=<root>.IRight
|
||||
$this: GET_VAR '<this>: <root>.CBoth declared in <root>.CBoth.<get-bar>' type=<root>.CBoth origin=null
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
overridden:
|
||||
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
|
||||
|
||||
Reference in New Issue
Block a user