JVM IR: fix IOOBE from remapTypeParameters for synthetic property annotations method

This commit is contained in:
Alexander Udalov
2019-09-18 14:55:05 +02:00
parent c972bf5882
commit acbe5c4e21
6 changed files with 41 additions and 2 deletions
@@ -137,7 +137,7 @@ fun IrValueParameter.copyTo(
(parent as IrTypeParametersContainer).classIfConstructor,
irFunction.classIfConstructor
),
varargElementType: IrType? = this.varargElementType,
varargElementType: IrType? = this.varargElementType, // TODO: remapTypeParameters here as well
defaultValue: IrExpressionBody? = this.defaultValue,
isCrossinline: Boolean = this.isCrossinline,
isNoinline: Boolean = this.isNoinline
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.backend.common.BackendContext
import org.jetbrains.kotlin.backend.common.FileLoweringPass
import org.jetbrains.kotlin.backend.common.descriptors.WrappedSimpleFunctionDescriptor
import org.jetbrains.kotlin.backend.common.ir.copyTo
import org.jetbrains.kotlin.backend.common.ir.copyTypeParametersFrom
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.ir.IrElement
@@ -19,7 +20,10 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrBlockBodyImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrBlockImpl
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
import org.jetbrains.kotlin.ir.types.classifierOrFail
import org.jetbrains.kotlin.ir.types.typeWith
import org.jetbrains.kotlin.ir.util.isEffectivelyExternal
import org.jetbrains.kotlin.ir.util.render
import org.jetbrains.kotlin.ir.util.transformDeclarationsFlat
import org.jetbrains.kotlin.ir.visitors.*
import org.jetbrains.kotlin.name.Name
@@ -81,7 +85,11 @@ class PropertiesLowering(
).apply {
descriptor.bind(this)
extensionReceiverParameter = declaration.getter?.extensionReceiverParameter?.copyTo(this)
val extensionReceiver = declaration.getter?.extensionReceiverParameter
if (extensionReceiver != null) {
// Use raw type of extension receiver to avoid generic signature, which would be useless for this method.
extensionReceiverParameter = extensionReceiver.copyTo(this, type = extensionReceiver.type.classifierOrFail.typeWith())
}
body = IrBlockBodyImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET)
@@ -0,0 +1,16 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
@Retention(AnnotationRetention.RUNTIME)
annotation class Simple(val value: String)
interface A<T>
@Simple("OK")
public val <T> A<T>.p: String
get() = TODO()
fun box(): String {
val o = object : A<Int> {}
return (o::p.annotations.single() as Simple).value
}
@@ -20301,6 +20301,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/reflection/annotations/findAnnotation.kt");
}
@TestMetadata("genericExtensionProperty.kt")
public void testGenericExtensionProperty() throws Exception {
runTest("compiler/testData/codegen/box/reflection/annotations/genericExtensionProperty.kt");
}
@TestMetadata("hasAnnotation.kt")
public void testHasAnnotation() throws Exception {
runTest("compiler/testData/codegen/box/reflection/annotations/hasAnnotation.kt");
@@ -20301,6 +20301,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/reflection/annotations/findAnnotation.kt");
}
@TestMetadata("genericExtensionProperty.kt")
public void testGenericExtensionProperty() throws Exception {
runTest("compiler/testData/codegen/box/reflection/annotations/genericExtensionProperty.kt");
}
@TestMetadata("hasAnnotation.kt")
public void testHasAnnotation() throws Exception {
runTest("compiler/testData/codegen/box/reflection/annotations/hasAnnotation.kt");
@@ -19186,6 +19186,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/reflection/annotations/findAnnotation.kt");
}
@TestMetadata("genericExtensionProperty.kt")
public void testGenericExtensionProperty() throws Exception {
runTest("compiler/testData/codegen/box/reflection/annotations/genericExtensionProperty.kt");
}
@TestMetadata("hasAnnotation.kt")
public void testHasAnnotation() throws Exception {
runTest("compiler/testData/codegen/box/reflection/annotations/hasAnnotation.kt");