FIR: extend arrayOf call transformation to other variants
This commit is contained in:
committed by
Mikhail Glukhikh
parent
7ec8716d65
commit
4a511c7721
+16
-4
@@ -23,11 +23,8 @@ internal class FirArrayOfCallTransformer {
|
|||||||
get() {
|
get() {
|
||||||
val function: FirCallableDeclaration<*> = getOriginalFunction() ?: return false
|
val function: FirCallableDeclaration<*> = getOriginalFunction() ?: return false
|
||||||
return function is FirSimpleFunction &&
|
return function is FirSimpleFunction &&
|
||||||
// TODO: extend it to other variants, like emptyArray, intArrayOf, floatArrayOf, etc.
|
|
||||||
function.name.asString() == "arrayOf" &&
|
|
||||||
function.returnTypeRef.isArrayType &&
|
function.returnTypeRef.isArrayType &&
|
||||||
function.valueParameters.size == 1 && function.valueParameters[0].isVararg &&
|
isArrayOf(function, arguments) &&
|
||||||
arguments.size == 1 &&
|
|
||||||
function.receiverTypeRef == null
|
function.receiverTypeRef == null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,4 +48,19 @@ internal class FirArrayOfCallTransformer {
|
|||||||
replaceTypeRef(typeRef)
|
replaceTypeRef(typeRef)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val arrayOfNames = hashSetOf("kotlin/arrayOf") +
|
||||||
|
hashSetOf(
|
||||||
|
"boolean", "byte", "char", "double", "float", "int", "long", "short",
|
||||||
|
"ubyte", "uint", "ulong", "ushort"
|
||||||
|
).map { "kotlin/" + it + "ArrayOf" }
|
||||||
|
|
||||||
|
private fun isArrayOf(function: FirSimpleFunction, arguments: List<FirExpression>): Boolean =
|
||||||
|
when (function.symbol.callableId.toString()) {
|
||||||
|
"kotlin/emptyArray" -> function.valueParameters.isEmpty() && arguments.isEmpty()
|
||||||
|
in arrayOfNames -> function.valueParameters.size == 1 && function.valueParameters[0].isVararg && arguments.size == 1
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// IGNORE_BACKEND: JS_IR
|
// IGNORE_BACKEND: JS_IR
|
||||||
// IGNORE_BACKEND: JS_IR_ES6
|
// IGNORE_BACKEND: JS_IR_ES6
|
||||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||||
|
|||||||
-1
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
annotation class Anno(val x: Array<String> = emptyArray())
|
annotation class Anno(val x: Array<String> = emptyArray())
|
||||||
|
|
||||||
@Anno fun test1() = 1
|
@Anno fun test1() = 1
|
||||||
|
|||||||
+1
-1
@@ -57,7 +57,7 @@ FILE fqName:<root> fileName:/arrayInAnnotationArguments.kt
|
|||||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||||
FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||||
annotations:
|
annotations:
|
||||||
TestAnnWithIntArray(x = CALL 'public final fun intArrayOf (vararg elements: kotlin.Int): kotlin.IntArray declared in kotlin' type=kotlin.IntArray origin=null)
|
TestAnnWithIntArray(x = ['1', '2', '3'])
|
||||||
TestAnnWithStringArray(x = ['a', 'b', 'c'])
|
TestAnnWithStringArray(x = ['a', 'b', 'c'])
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||||
|
|||||||
Reference in New Issue
Block a user