[Psi2Ir] Fix generation of hashcode for generic inline class

This commit is contained in:
Roman Artemev
2020-02-14 17:42:12 +03:00
committed by romanart
parent 6a37955a36
commit 5004bb3636
13 changed files with 313 additions and 0 deletions
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.builders.*
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
import org.jetbrains.kotlin.ir.expressions.mapTypeParameters
import org.jetbrains.kotlin.ir.expressions.mapValueParameters
@@ -56,6 +57,8 @@ class DataClassMembersGenerator(
MyDataClassMethodGenerator(ktClassOrObject, irClass, IrDeclarationOrigin.GENERATED_DATA_CLASS_MEMBER).generate()
}
fun IrMemberAccessExpression.commitSubstituted(descriptor: CallableDescriptor) = context.run { commitSubstituted(descriptor) }
private fun declareSimpleFunction(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, function: FunctionDescriptor) =
context.symbolTable.declareSimpleFunctionWithOverrides(
startOffset, endOffset, origin,
@@ -257,7 +260,9 @@ class DataClassMembersGenerator(
}
private fun MemberFunctionBuilder.getHashCodeOf(kotlinType: KotlinType, irValue: IrExpression): IrExpression {
var substituted: FunctionDescriptor? = null
val hashCodeFunctionSymbol = getHashCodeFunction(kotlinType) {
substituted = it
declarationGenerator.context.symbolTable.referenceSimpleFunction(it.original)
}
@@ -267,6 +272,7 @@ class DataClassMembersGenerator(
} else {
putValueArgument(0, irValue)
}
commitSubstituted(substituted ?: hashCodeFunctionSymbol.descriptor)
}
}
@@ -55,4 +55,8 @@ class GeneratorContext(
// 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) {
callToSubstitutedDescriptorMap[this] = descriptor
}
}