Make FirArrayOfCallTransformer recursive #KT-49076 Fixed
This commit is contained in:
committed by
TeamCityServer
parent
ad3502a952
commit
c5a4a5de42
+6
@@ -5057,6 +5057,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayOfImports.kt")
|
||||
public void testArrayOfImports() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/arrayOfImports.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DailyAggregatedDoubleFactor.kt")
|
||||
public void testDailyAggregatedDoubleFactor() throws Exception {
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
FILE: arrayOfImports.kt
|
||||
@R|kotlin/Deprecated|(message = String(Use ...), replaceWith = R|kotlin/ReplaceWith.ReplaceWith|(String(bar), vararg(imports = <implicitArrayOf>(String(my.package.bar))))) @R|Third|(first = R|/First.First|(<implicitArrayOf>(<getClass>(Q|kotlin/String|))), second = R|/Second.Second|(<implicitArrayOf>(R|/First.First|(<implicitArrayOf>(<getClass>(Q|kotlin/Int|))), R|/First.First|(<implicitArrayOf>(<getClass>(Q|kotlin/Double|)))))) @R|Second|(value = <implicitArrayOf>(<implicitArrayOf>(String()), <implicitArrayOf>(R|/First.First|(<implicitArrayOf>())))) public final fun foo(): R|kotlin/Unit| {
|
||||
}
|
||||
public final annotation class First : R|kotlin/Annotation| {
|
||||
public constructor(value: R|kotlin/Array<kotlin/reflect/KClass<*>>|): R|First| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val value: R|kotlin/Array<kotlin/reflect/KClass<*>>| = R|<local>/value|
|
||||
public get(): R|kotlin/Array<kotlin/reflect/KClass<*>>|
|
||||
|
||||
}
|
||||
public final annotation class Second : R|kotlin/Annotation| {
|
||||
public constructor(value: R|kotlin/Array<First>|): R|Second| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val value: R|kotlin/Array<First>| = R|<local>/value|
|
||||
public get(): R|kotlin/Array<First>|
|
||||
|
||||
}
|
||||
public final annotation class Third : R|kotlin/Annotation| {
|
||||
public constructor(first: R|First|, second: R|Second|): R|Third| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val first: R|First| = R|<local>/first|
|
||||
public get(): R|First|
|
||||
|
||||
public final val second: R|Second| = R|<local>/second|
|
||||
public get(): R|Second|
|
||||
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
// See KT-49076
|
||||
|
||||
@Deprecated("Use ...", ReplaceWith("bar", imports = arrayOf("my.package.bar")))
|
||||
@Third(
|
||||
First(arrayOf(String::class)),
|
||||
Second(arrayOf(First(arrayOf(Int::class)), First(arrayOf(Double::class))))
|
||||
)
|
||||
// Incorrect array inside
|
||||
@Second(<!ARGUMENT_TYPE_MISMATCH!>arrayOf(arrayOf(""), arrayOf(First(arrayOf())))<!>)
|
||||
fun foo() {}
|
||||
|
||||
annotation class First(val value: Array<KClass<*>>)
|
||||
|
||||
annotation class Second(val value: Array<First>)
|
||||
|
||||
annotation class Third(val first: First, val second: Second)
|
||||
+6
@@ -5057,6 +5057,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayOfImports.kt")
|
||||
public void testArrayOfImports() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/arrayOfImports.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DailyAggregatedDoubleFactor.kt")
|
||||
public void testDailyAggregatedDoubleFactor() throws Exception {
|
||||
|
||||
+6
@@ -5057,6 +5057,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayOfImports.kt")
|
||||
public void testArrayOfImports() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/arrayOfImports.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("DailyAggregatedDoubleFactor.kt")
|
||||
public void testDailyAggregatedDoubleFactor() throws Exception {
|
||||
|
||||
+1
-3
@@ -251,9 +251,7 @@ class FirCallCompletionResultsWriterTransformer(
|
||||
}
|
||||
|
||||
if (enableArrayOfCallTransformation) {
|
||||
arrayOfCallTransformer.toArrayOfCall(result)?.let {
|
||||
return it
|
||||
}
|
||||
return arrayOfCallTransformer.transformFunctionCall(result, null)
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
+15
-2
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.resolve.transformers.body.resolve
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
@@ -14,13 +15,15 @@ import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.types.isArrayType
|
||||
import org.jetbrains.kotlin.fir.visitors.FirDefaultTransformer
|
||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
|
||||
/**
|
||||
* A transformer that converts resolved arrayOf() call to [FirArrayOfCall].
|
||||
*
|
||||
* Note that arrayOf() calls only in [FirAnnotation] or the default value of annotation constructor are transformed.
|
||||
*/
|
||||
internal class FirArrayOfCallTransformer {
|
||||
internal class FirArrayOfCallTransformer : FirDefaultTransformer<Nothing?>() {
|
||||
private val FirFunctionCall.isArrayOfCall: Boolean
|
||||
get() {
|
||||
val function: FirCallableDeclaration = getOriginalFunction() ?: return false
|
||||
@@ -30,7 +33,7 @@ internal class FirArrayOfCallTransformer {
|
||||
function.receiverTypeRef == null
|
||||
}
|
||||
|
||||
internal fun toArrayOfCall(functionCall: FirFunctionCall): FirArrayOfCall? {
|
||||
private fun toArrayOfCall(functionCall: FirFunctionCall): FirArrayOfCall? {
|
||||
if (!functionCall.isArrayOfCall) {
|
||||
return null
|
||||
}
|
||||
@@ -51,6 +54,16 @@ internal class FirArrayOfCallTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
override fun transformFunctionCall(functionCall: FirFunctionCall, data: Nothing?): FirStatement {
|
||||
functionCall.transformChildren(this, data)
|
||||
return toArrayOfCall(functionCall) ?: functionCall
|
||||
}
|
||||
|
||||
override fun <E : FirElement> transformElement(element: E, data: Nothing?): E {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return (element.transformChildren(this, data) as E)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val arrayOfNames = hashSetOf("kotlin/arrayOf") +
|
||||
hashSetOf(
|
||||
|
||||
+1
-3
@@ -380,9 +380,7 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
|
||||
dataFlowAnalyzer.exitFunctionCall(completeInference, callCompleted)
|
||||
if (callCompleted) {
|
||||
if (enableArrayOfCallTransformation) {
|
||||
arrayOfCallTransformer.toArrayOfCall(completeInference)?.let {
|
||||
return it
|
||||
}
|
||||
return arrayOfCallTransformer.transformFunctionCall(completeInference, null)
|
||||
}
|
||||
}
|
||||
return completeInference
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ fun foo1() {}
|
||||
@Anno(x = ["a", "b"], y = "a")
|
||||
fun foo2() {}
|
||||
|
||||
@Anno(x = <!ARGUMENT_TYPE_MISMATCH, NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION!>arrayOf(<!ANNOTATION_ARGUMENT_MUST_BE_CONST!>arrayOf("a")<!>, <!ANNOTATION_ARGUMENT_MUST_BE_CONST!>arrayOf("b")<!>)<!>, y = "a")
|
||||
@Anno(x = <!ARGUMENT_TYPE_MISMATCH!>arrayOf(arrayOf("a"), arrayOf("b"))<!>, y = "a")
|
||||
fun foo3() {}
|
||||
|
||||
@Anno(x = arrayOf("a", "b"), y = "a")
|
||||
|
||||
Reference in New Issue
Block a user