FIR: recursive transform annotation if it has annotation as argument
#KT-42344 Fixed
This commit is contained in:
+12
-6
@@ -61,12 +61,16 @@ class IrConstTransformer(irBuiltIns: IrBuiltIns) : IrElementTransformerVoid() {
|
||||
|
||||
private fun transformAnnotations(annotationContainer: IrAnnotationContainer) {
|
||||
annotationContainer.annotations.forEach { annotation ->
|
||||
for (i in 0 until annotation.valueArgumentsCount) {
|
||||
val arg = annotation.getValueArgument(i) ?: continue
|
||||
when (arg) {
|
||||
is IrVararg -> annotation.putValueArgument(i, arg.transformVarArg())
|
||||
else -> annotation.putValueArgument(i, arg.transformSingleArg(annotation.symbol.owner.valueParameters[i].type))
|
||||
}
|
||||
transformAnnotation(annotation)
|
||||
}
|
||||
}
|
||||
|
||||
private fun transformAnnotation(annotation: IrConstructorCall) {
|
||||
for (i in 0 until annotation.valueArgumentsCount) {
|
||||
val arg = annotation.getValueArgument(i) ?: continue
|
||||
when (arg) {
|
||||
is IrVararg -> annotation.putValueArgument(i, arg.transformVarArg())
|
||||
else -> annotation.putValueArgument(i, arg.transformSingleArg(annotation.symbol.owner.valueParameters[i].type))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,6 +96,8 @@ class IrConstTransformer(irBuiltIns: IrBuiltIns) : IrElementTransformerVoid() {
|
||||
if (this.accept(IrCompileTimeChecker(mode = EvaluationMode.ONLY_BUILTINS), null)) {
|
||||
val const = interpreter.interpret(this).replaceIfError(this)
|
||||
return const.convertToConstIfPossible(expectedType)
|
||||
} else if (this is IrConstructorCall) {
|
||||
transformAnnotation(this)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
+5
@@ -1717,6 +1717,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/irText/firProblems"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("AnnotationInAnnotation.kt")
|
||||
public void testAnnotationInAnnotation() throws Exception {
|
||||
runTest("compiler/testData/ir/irText/firProblems/AnnotationInAnnotation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("candidateSymbol.kt")
|
||||
public void testCandidateSymbol() throws Exception {
|
||||
runTest("compiler/testData/ir/irText/firProblems/candidateSymbol.kt");
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
FILE fqName:<root> fileName:/AnnotationInAnnotation.kt
|
||||
CLASS ANNOTATION_CLASS name:Storage modality:FINAL visibility:public superTypes:[kotlin.Annotation]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Storage
|
||||
CONSTRUCTOR visibility:public <> (value:kotlin.String) returnType:<root>.Storage [primary]
|
||||
VALUE_PARAMETER name:value index:0 type:kotlin.String
|
||||
PROPERTY name:value visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:value type:kotlin.String visibility:private [final]
|
||||
EXPRESSION_BODY
|
||||
GET_VAR 'value: kotlin.String declared in <root>.Storage.<init>' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-value> visibility:public modality:FINAL <> ($this:<root>.Storage) returnType:kotlin.String
|
||||
correspondingProperty: PROPERTY name:value visibility:public modality:FINAL [val]
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Storage
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-value> (): kotlin.String declared in <root>.Storage'
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:value type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
|
||||
receiver: GET_VAR '<this>: <root>.Storage declared in <root>.Storage.<get-value>' type=<root>.Storage 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
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
|
||||
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
|
||||
overridden:
|
||||
public open fun hashCode (): kotlin.Int declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
|
||||
overridden:
|
||||
public open fun toString (): kotlin.String declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
CLASS ANNOTATION_CLASS name:State modality:FINAL visibility:public superTypes:[kotlin.Annotation]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.State
|
||||
CONSTRUCTOR visibility:public <> (name:kotlin.String, storages:kotlin.Array<<root>.Storage>) returnType:<root>.State [primary]
|
||||
VALUE_PARAMETER name:name index:0 type:kotlin.String
|
||||
VALUE_PARAMETER name:storages index:1 type:kotlin.Array<<root>.Storage>
|
||||
PROPERTY name:name visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:name type:kotlin.String visibility:private [final]
|
||||
EXPRESSION_BODY
|
||||
GET_VAR 'name: kotlin.String declared in <root>.State.<init>' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-name> visibility:public modality:FINAL <> ($this:<root>.State) returnType:kotlin.String
|
||||
correspondingProperty: PROPERTY name:name visibility:public modality:FINAL [val]
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.State
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-name> (): kotlin.String declared in <root>.State'
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:name type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
|
||||
receiver: GET_VAR '<this>: <root>.State declared in <root>.State.<get-name>' type=<root>.State origin=null
|
||||
PROPERTY name:storages visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:storages type:kotlin.Array<<root>.Storage> visibility:private [final]
|
||||
EXPRESSION_BODY
|
||||
GET_VAR 'storages: kotlin.Array<<root>.Storage> declared in <root>.State.<init>' type=kotlin.Array<<root>.Storage> origin=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-storages> visibility:public modality:FINAL <> ($this:<root>.State) returnType:kotlin.Array<<root>.Storage>
|
||||
correspondingProperty: PROPERTY name:storages visibility:public modality:FINAL [val]
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.State
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-storages> (): kotlin.Array<<root>.Storage> declared in <root>.State'
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:storages type:kotlin.Array<<root>.Storage> visibility:private [final]' type=kotlin.Array<<root>.Storage> origin=null
|
||||
receiver: GET_VAR '<this>: <root>.State declared in <root>.State.<get-storages>' type=<root>.State 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
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
|
||||
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
|
||||
overridden:
|
||||
public open fun hashCode (): kotlin.Int declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
|
||||
overridden:
|
||||
public open fun toString (): kotlin.String declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
CLASS CLASS name:Test modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
annotations:
|
||||
State(name = '1', storages = [Storage(value = 'HELLO')])
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Test
|
||||
CONSTRUCTOR visibility:public <> () returnType:<root>.Test [primary]
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Test modality:FINAL visibility:public superTypes:[kotlin.Any]'
|
||||
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
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
|
||||
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
|
||||
overridden:
|
||||
public open fun hashCode (): kotlin.Int declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
|
||||
overridden:
|
||||
public open fun toString (): kotlin.String declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
@@ -0,0 +1,17 @@
|
||||
// FILE: Some.java
|
||||
|
||||
public class Some {
|
||||
public static final String HELLO = "HELLO";
|
||||
}
|
||||
|
||||
// FILE: AnnotationInAnnotation.kt
|
||||
|
||||
annotation class Storage(val value: String)
|
||||
|
||||
annotation class State(val name: String, val storages: Array<Storage>)
|
||||
|
||||
@State(
|
||||
name = "1",
|
||||
storages = [Storage(value = Some.HELLO)]
|
||||
)
|
||||
class Test
|
||||
@@ -0,0 +1,90 @@
|
||||
FILE fqName:<root> fileName:/AnnotationInAnnotation.kt
|
||||
CLASS ANNOTATION_CLASS name:Storage modality:FINAL visibility:public superTypes:[kotlin.Annotation]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Storage
|
||||
CONSTRUCTOR visibility:public <> (value:kotlin.String) returnType:<root>.Storage [primary]
|
||||
VALUE_PARAMETER name:value index:0 type:kotlin.String
|
||||
PROPERTY name:value visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:value type:kotlin.String visibility:private [final]
|
||||
EXPRESSION_BODY
|
||||
GET_VAR 'value: kotlin.String declared in <root>.Storage.<init>' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-value> visibility:public modality:FINAL <> ($this:<root>.Storage) returnType:kotlin.String
|
||||
correspondingProperty: PROPERTY name:value visibility:public modality:FINAL [val]
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Storage
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-value> (): kotlin.String declared in <root>.Storage'
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:value type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
|
||||
receiver: GET_VAR '<this>: <root>.Storage declared in <root>.Storage.<get-value>' type=<root>.Storage 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 [fake_override,operator] declared in kotlin.Annotation
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
|
||||
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
|
||||
overridden:
|
||||
public open fun hashCode (): kotlin.Int [fake_override] declared in kotlin.Annotation
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
|
||||
overridden:
|
||||
public open fun toString (): kotlin.String [fake_override] declared in kotlin.Annotation
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
CLASS ANNOTATION_CLASS name:State modality:FINAL visibility:public superTypes:[kotlin.Annotation]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.State
|
||||
CONSTRUCTOR visibility:public <> (name:kotlin.String, storages:kotlin.Array<<root>.Storage>) returnType:<root>.State [primary]
|
||||
VALUE_PARAMETER name:name index:0 type:kotlin.String
|
||||
VALUE_PARAMETER name:storages index:1 type:kotlin.Array<<root>.Storage>
|
||||
PROPERTY name:name visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:name type:kotlin.String visibility:private [final]
|
||||
EXPRESSION_BODY
|
||||
GET_VAR 'name: kotlin.String declared in <root>.State.<init>' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-name> visibility:public modality:FINAL <> ($this:<root>.State) returnType:kotlin.String
|
||||
correspondingProperty: PROPERTY name:name visibility:public modality:FINAL [val]
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.State
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-name> (): kotlin.String declared in <root>.State'
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:name type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
|
||||
receiver: GET_VAR '<this>: <root>.State declared in <root>.State.<get-name>' type=<root>.State origin=null
|
||||
PROPERTY name:storages visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:storages type:kotlin.Array<<root>.Storage> visibility:private [final]
|
||||
EXPRESSION_BODY
|
||||
GET_VAR 'storages: kotlin.Array<<root>.Storage> declared in <root>.State.<init>' type=kotlin.Array<<root>.Storage> origin=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-storages> visibility:public modality:FINAL <> ($this:<root>.State) returnType:kotlin.Array<<root>.Storage>
|
||||
correspondingProperty: PROPERTY name:storages visibility:public modality:FINAL [val]
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.State
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-storages> (): kotlin.Array<<root>.Storage> declared in <root>.State'
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:storages type:kotlin.Array<<root>.Storage> visibility:private [final]' type=kotlin.Array<<root>.Storage> origin=null
|
||||
receiver: GET_VAR '<this>: <root>.State declared in <root>.State.<get-storages>' type=<root>.State 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 [fake_override,operator] declared in kotlin.Annotation
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
|
||||
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
|
||||
overridden:
|
||||
public open fun hashCode (): kotlin.Int [fake_override] declared in kotlin.Annotation
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
|
||||
overridden:
|
||||
public open fun toString (): kotlin.String [fake_override] declared in kotlin.Annotation
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
CLASS CLASS name:Test modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
annotations:
|
||||
State(name = '1', storages = [Storage(value = 'HELLO')])
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Test
|
||||
CONSTRUCTOR visibility:public <> () returnType:<root>.Test [primary]
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Test modality:FINAL visibility:public superTypes:[kotlin.Any]'
|
||||
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
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
|
||||
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
|
||||
overridden:
|
||||
public open fun hashCode (): kotlin.Int declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
|
||||
overridden:
|
||||
public open fun toString (): kotlin.String declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
@@ -1716,6 +1716,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/irText/firProblems"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("AnnotationInAnnotation.kt")
|
||||
public void testAnnotationInAnnotation() throws Exception {
|
||||
runTest("compiler/testData/ir/irText/firProblems/AnnotationInAnnotation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("candidateSymbol.kt")
|
||||
public void testCandidateSymbol() throws Exception {
|
||||
runTest("compiler/testData/ir/irText/firProblems/candidateSymbol.kt");
|
||||
|
||||
Reference in New Issue
Block a user