[IR] Fix unbound type parameter symbol for jvm corner cases
This commit is contained in:
+1
@@ -343,6 +343,7 @@ class AssignmentGenerator(statementGenerator: StatementGenerator) : StatementGen
|
||||
scope,
|
||||
ktExpression.startOffsetSkippingComments, ktExpression.endOffset, origin,
|
||||
context.symbolTable.referenceField(unwrappedPropertyDescriptor.original),
|
||||
unwrappedPropertyDescriptor,
|
||||
propertyIrType,
|
||||
propertyReceiver,
|
||||
superQualifierSymbol
|
||||
|
||||
@@ -187,7 +187,7 @@ class CallGenerator(statementGenerator: StatementGenerator) : StatementGenerator
|
||||
dispatchReceiverValue?.load(),
|
||||
IrStatementOrigin.GET_PROPERTY,
|
||||
superQualifierSymbol
|
||||
)
|
||||
).also { context.callToSubstitutedDescriptorMap[it] = descriptor }
|
||||
}
|
||||
} else {
|
||||
call.callReceiver.adjustForCallee(getMethodDescriptor).call { dispatchReceiverValue, extensionReceiverValue ->
|
||||
|
||||
+3
-3
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.NotFoundClasses
|
||||
import org.jetbrains.kotlin.ir.builders.IrGeneratorContext
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrDeclarationReference
|
||||
import org.jetbrains.kotlin.ir.util.ConstantValueGenerator
|
||||
import org.jetbrains.kotlin.ir.util.IdSignatureComposer
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
@@ -60,14 +60,14 @@ class GeneratorContext(
|
||||
override val irBuiltIns: IrBuiltIns
|
||||
) : IrGeneratorContext() {
|
||||
|
||||
val callToSubstitutedDescriptorMap = mutableMapOf<IrMemberAccessExpression, CallableDescriptor>()
|
||||
val callToSubstitutedDescriptorMap = mutableMapOf<IrDeclarationReference, CallableDescriptor>()
|
||||
|
||||
val sourceManager = PsiSourceManager()
|
||||
|
||||
// TODO: inject a correct StorageManager instance, or store NotFoundClasses inside ModuleDescriptor
|
||||
val reflectionTypes = ReflectionTypes(moduleDescriptor, NotFoundClasses(LockBasedStorageManager.NO_LOCKS, moduleDescriptor))
|
||||
|
||||
fun IrMemberAccessExpression.commitSubstituted(descriptor: CallableDescriptor) {
|
||||
fun IrDeclarationReference.commitSubstituted(descriptor: CallableDescriptor) {
|
||||
callToSubstitutedDescriptorMap[this] = descriptor
|
||||
}
|
||||
}
|
||||
|
||||
+5
-2
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.psi2ir.intermediate
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.ir.builders.Scope
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
@@ -72,6 +73,7 @@ class FieldPropertyLValue(
|
||||
endOffset: Int,
|
||||
origin: IrStatementOrigin?,
|
||||
val field: IrFieldSymbol,
|
||||
val descriptor: PropertyDescriptor,
|
||||
type: IrType,
|
||||
callReceiver: CallReceiver,
|
||||
superQualifier: IrClassSymbol?
|
||||
@@ -88,7 +90,7 @@ class FieldPropertyLValue(
|
||||
dispatchReceiverValue?.load(),
|
||||
origin,
|
||||
superQualifier
|
||||
)
|
||||
).also { context.callToSubstitutedDescriptorMap[it] = descriptor }
|
||||
}
|
||||
|
||||
override fun store(irExpression: IrExpression) =
|
||||
@@ -102,7 +104,7 @@ class FieldPropertyLValue(
|
||||
context.irBuiltIns.unitType,
|
||||
origin,
|
||||
superQualifier
|
||||
)
|
||||
).also { context.callToSubstitutedDescriptorMap[it] = descriptor }
|
||||
}
|
||||
|
||||
override fun withReceiver(dispatchReceiver: VariableLValue?, extensionReceiver: VariableLValue?): PropertyLValueBase =
|
||||
@@ -110,6 +112,7 @@ class FieldPropertyLValue(
|
||||
context,
|
||||
scope, startOffset, endOffset, origin,
|
||||
field,
|
||||
descriptor,
|
||||
type,
|
||||
SimpleCallReceiver(dispatchReceiver, extensionReceiver),
|
||||
superQualifier
|
||||
|
||||
+7
-9
@@ -19,10 +19,7 @@ package org.jetbrains.kotlin.psi2ir.transformations
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.isFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isSuspendFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
@@ -62,7 +59,7 @@ internal class InsertImplicitCasts(
|
||||
private val builtIns: KotlinBuiltIns,
|
||||
private val irBuiltIns: IrBuiltIns,
|
||||
private val typeTranslator: TypeTranslator,
|
||||
private val callToSubstitutedDescriptorMap: Map<IrMemberAccessExpression, CallableDescriptor>,
|
||||
private val callToSubstitutedDescriptorMap: Map<IrDeclarationReference, CallableDescriptor>,
|
||||
private val generatorExtensions: GeneratorExtensions
|
||||
) : IrElementTransformerVoid() {
|
||||
|
||||
@@ -84,7 +81,7 @@ internal class InsertImplicitCasts(
|
||||
|
||||
private fun KotlinType.toIrType() = typeTranslator.translateType(this)
|
||||
|
||||
private val IrMemberAccessExpression.substitutedDescriptor
|
||||
private val IrDeclarationReference.substitutedDescriptor
|
||||
get() = callToSubstitutedDescriptorMap[this] ?: symbol.descriptor as CallableDescriptor
|
||||
|
||||
override fun visitCallableReference(expression: IrCallableReference): IrExpression {
|
||||
@@ -189,13 +186,14 @@ internal class InsertImplicitCasts(
|
||||
|
||||
override fun visitGetField(expression: IrGetField): IrExpression =
|
||||
expression.transformPostfix {
|
||||
receiver = receiver?.cast(getEffectiveDispatchReceiverType(expression.symbol.descriptor))
|
||||
receiver = receiver?.cast(getEffectiveDispatchReceiverType(expression.substitutedDescriptor))
|
||||
}
|
||||
|
||||
override fun visitSetField(expression: IrSetField): IrExpression =
|
||||
expression.transformPostfix {
|
||||
receiver = receiver?.cast(getEffectiveDispatchReceiverType(expression.symbol.descriptor))
|
||||
value = value.cast(expression.symbol.descriptor.type)
|
||||
val substituted = expression.substitutedDescriptor as PropertyDescriptor
|
||||
receiver = receiver?.cast(getEffectiveDispatchReceiverType(substituted))
|
||||
value = value.cast(substituted.type)
|
||||
}
|
||||
|
||||
override fun visitVariable(declaration: IrVariable): IrVariable =
|
||||
|
||||
@@ -117,7 +117,7 @@ class ConstantValueGenerator(
|
||||
IrClassReferenceImpl(
|
||||
startOffset, endOffset,
|
||||
constantValue.getType(moduleDescriptor).toIrType(),
|
||||
classifierDescriptor.defaultType.toIrType().classifierOrFail,
|
||||
symbolTable.referenceClassifier(classifierDescriptor),
|
||||
classifierKtType.toIrType()
|
||||
)
|
||||
}
|
||||
|
||||
+3
-3
@@ -10,9 +10,9 @@ FILE fqName:<root> fileName:/smartCastOnFieldReceiverOfGenericType.kt
|
||||
TYPE_OP type=kotlin.String origin=CAST typeOperand=kotlin.String
|
||||
GET_VAR 'b: kotlin.Any declared in <root>.testSetField' type=kotlin.Any origin=null
|
||||
SET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:value type:T of <root>.JCell? visibility:public' type=kotlin.Unit origin=EQ
|
||||
receiver: TYPE_OP type=<root>.JCell<T of <root>.JCell> origin=IMPLICIT_CAST typeOperand=<root>.JCell<T of <root>.JCell>
|
||||
receiver: TYPE_OP type=<root>.JCell<kotlin.String> origin=IMPLICIT_CAST typeOperand=<root>.JCell<kotlin.String>
|
||||
GET_VAR 'a: kotlin.Any declared in <root>.testSetField' type=kotlin.Any origin=null
|
||||
value: TYPE_OP type=T of <root>.JCell origin=IMPLICIT_CAST typeOperand=T of <root>.JCell
|
||||
value: TYPE_OP type=kotlin.String origin=IMPLICIT_CAST typeOperand=kotlin.String
|
||||
GET_VAR 'b: kotlin.Any declared in <root>.testSetField' type=kotlin.Any origin=null
|
||||
FUN name:testGetField visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.String
|
||||
VALUE_PARAMETER name:a index:0 type:kotlin.Any
|
||||
@@ -23,5 +23,5 @@ FILE fqName:<root> fileName:/smartCastOnFieldReceiverOfGenericType.kt
|
||||
RETURN type=kotlin.Nothing from='public final fun testGetField (a: kotlin.Any): kotlin.String declared in <root>'
|
||||
TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String
|
||||
GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:value type:T of <root>.JCell? visibility:public' type=kotlin.String? origin=GET_PROPERTY
|
||||
receiver: TYPE_OP type=<root>.JCell<T of <root>.JCell> origin=IMPLICIT_CAST typeOperand=<root>.JCell<T of <root>.JCell>
|
||||
receiver: TYPE_OP type=<root>.JCell<kotlin.String> origin=IMPLICIT_CAST typeOperand=<root>.JCell<kotlin.String>
|
||||
GET_VAR 'a: kotlin.Any declared in <root>.testGetField' type=kotlin.Any origin=null
|
||||
|
||||
Reference in New Issue
Block a user