FIR2IR: pass annotationMode through arrayOf calls properly

#KT-50163 Fixed
This commit is contained in:
Mikhail Glukhikh
2021-12-10 08:41:45 +03:00
parent 09585d116e
commit 66231baa06
4 changed files with 87 additions and 8 deletions
@@ -357,19 +357,19 @@ class Fir2IrVisitor(
endOffset,
varargArgumentsExpression.typeRef.toIrType(),
varargArgumentsExpression.varargElementType.toIrType(),
varargArgumentsExpression.arguments.map { it.convertToIrVarargElement() }
varargArgumentsExpression.arguments.map { it.convertToIrVarargElement(annotationMode = false) }
)
}
}
private fun FirExpression.convertToIrVarargElement(): IrVarargElement =
private fun FirExpression.convertToIrVarargElement(annotationMode: Boolean): IrVarargElement =
if (this is FirSpreadArgumentExpression || this is FirNamedArgumentExpression && this.isSpread) {
IrSpreadElementImpl(
source?.startOffset ?: UNDEFINED_OFFSET,
source?.endOffset ?: UNDEFINED_OFFSET,
convertToIrExpression(this)
convertToIrExpression(this, annotationMode)
)
} else convertToIrExpression(this)
} else convertToIrExpression(this, annotationMode)
private fun convertToIrCall(functionCall: FirFunctionCall, annotationMode: Boolean): IrExpression {
val explicitReceiverExpression = convertToIrReceiverExpression(
@@ -535,8 +535,12 @@ class Fir2IrVisitor(
}
else -> {
val unwrappedExpression = expression.unwrapArgument()
if (annotationMode && unwrappedExpression is FirFunctionCall) {
convertToIrCall(unwrappedExpression, annotationMode)
if (annotationMode) {
when (unwrappedExpression) {
is FirFunctionCall -> convertToIrCall(unwrappedExpression, annotationMode)
is FirArrayOfCall -> convertToArrayOfCall(unwrappedExpression, annotationMode)
else -> expression.accept(this, null) as IrExpression
}
} else {
expression.accept(this, null) as IrExpression
}
@@ -1113,7 +1117,7 @@ class Fir2IrVisitor(
classifierStorage.getIrClassSymbol(it)
}
override fun visitArrayOfCall(arrayOfCall: FirArrayOfCall, data: Any?): IrElement {
private fun convertToArrayOfCall(arrayOfCall: FirArrayOfCall, annotationMode: Boolean): IrVararg {
return arrayOfCall.convertWithOffsets { startOffset, endOffset ->
lateinit var elementType: IrType
lateinit var arrayType: IrType
@@ -1132,11 +1136,15 @@ class Fir2IrVisitor(
startOffset, endOffset,
type = arrayType,
varargElementType = elementType,
elements = arrayOfCall.arguments.map { it.convertToIrVarargElement() }
elements = arrayOfCall.arguments.map { it.convertToIrVarargElement(annotationMode) }
)
}
}
override fun visitArrayOfCall(arrayOfCall: FirArrayOfCall, data: Any?): IrElement {
return convertToArrayOfCall(arrayOfCall, annotationMode = false)
}
override fun visitAugmentedArraySetCall(augmentedArraySetCall: FirAugmentedArraySetCall, data: Any?): IrElement {
return augmentedArraySetCall.convertWithOffsets { startOffset, endOffset ->
IrErrorCallExpressionImpl(
@@ -16839,6 +16839,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/fir/ColorValuePanel.kt");
}
@Test
@TestMetadata("complexAnnotations.kt")
public void testComplexAnnotations() throws Exception {
runTest("compiler/testData/codegen/box/fir/complexAnnotations.kt");
}
@Test
@TestMetadata("ConstValAccess.kt")
public void testConstValAccess() throws Exception {
+59
View File
@@ -0,0 +1,59 @@
// TARGET_BACKEND: JVM_IR
// MODULE: m1
// FILE: State.java
public @interface State {
String name();
Storage[] storages() default {};
boolean reloadable() default true;
boolean defaultStateAsResource() default false;
boolean reportStatistic() default false;
}
// FILE: Storage.java
public @interface Storage {
String file() default "";
String value() default "";
boolean deprecated() default false;
RoamingType roamingType() default RoamingType.DEFAULT;
}
// FILE: RoamingType.java
public enum RoamingType {
DISABLED,
PER_OS,
DEFAULT,
}
// FILE: StoragePathMacros.java
public class StoragePathMacros {
public static final String NON_ROAMABLE_FILE = "NON_ROAMABLE_FILE";
}
// MODULE: m2(m1)
// FILE: test.kt
@State(name = "RecentDirectoryProjectsManager",
storages = [Storage(value = "recentProjectDirectories.xml", roamingType = RoamingType.DISABLED, deprecated = true)],
reportStatistic = false)
class Some
@State(name = "RecentProjectsManager", storages = [Storage(value = "recentProjects.xml", roamingType = RoamingType.DISABLED)])
class Other
@State(name = "A", storages = [(Storage(value = StoragePathMacros.NON_ROAMABLE_FILE))])
class Another
fun box(): String {
Some()
Other()
Another()
return "OK"
}
@@ -16839,6 +16839,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/fir/ColorValuePanel.kt");
}
@Test
@TestMetadata("complexAnnotations.kt")
public void testComplexAnnotations() throws Exception {
runTest("compiler/testData/codegen/box/fir/complexAnnotations.kt");
}
@Test
@TestMetadata("ConstValAccess.kt")
public void testConstValAccess() throws Exception {