FIR: add tests which checks that every declaration in file has body resolve phase after resolving the fiile

This commit is contained in:
Ilya Kirillov
2021-02-26 19:22:19 +01:00
parent 0dd18006e8
commit d49913944c
28 changed files with 435 additions and 0 deletions
@@ -86,6 +86,7 @@ import org.jetbrains.kotlin.idea.fir.low.level.api.AbstractFirMultiModuleResolve
import org.jetbrains.kotlin.idea.fir.low.level.api.diagnostic.AbstractDiagnosticTraversalCounterTest
import org.jetbrains.kotlin.idea.fir.low.level.api.file.structure.AbstractFileStructureAndOutOfBlockModificationTrackerConsistencyTest
import org.jetbrains.kotlin.idea.fir.low.level.api.file.structure.AbstractFileStructureTest
import org.jetbrains.kotlin.idea.fir.low.level.api.resolve.AbstractInnerDeclarationsResolvePhaseTest
import org.jetbrains.kotlin.idea.fir.low.level.api.sessions.AbstractSessionsInvalidationTest
import org.jetbrains.kotlin.idea.fir.low.level.api.trackers.AbstractProjectWideOutOfBlockKotlinModificationTrackerTest
import org.jetbrains.kotlin.idea.folding.AbstractKotlinFoldingTest
@@ -1085,6 +1086,9 @@ fun main(args: Array<String>) {
testClass<AbstractSessionsInvalidationTest> {
model("sessionInvalidation", recursive = false, extension = null)
}
testClass<AbstractInnerDeclarationsResolvePhaseTest> {
model("innerDeclarationsResolve")
}
}
testGroup("idea/idea-fir/tests", "idea") {
@@ -0,0 +1,13 @@
FILE: annonymousClass.kt
public final [BODY_RESOLVE] fun x(): R|kotlin/Unit| {
[BODY_RESOLVE] lval x: R|<anonymous>| = object : R|kotlin/Any| {
private [BODY_RESOLVE] constructor(): R|<anonymous>| {
super<R|kotlin/Any|>()
}
public final [BODY_RESOLVE] fun foo(): R|kotlin/Unit| {
}
}
}
@@ -0,0 +1,5 @@
fun x() {
val x = object: Any() {
fun foo(){}
}
}
@@ -0,0 +1,20 @@
FILE: class.kt
public final [BODY_RESOLVE] class B : R|kotlin/Any| {
public [BODY_RESOLVE] constructor(): R|B| {
super<R|kotlin/Any|>()
}
public final [BODY_RESOLVE] fun q(): <ERROR TYPE REF: Symbol not found, for `C`> {
}
private final [BODY_RESOLVE] val y: R|ERROR CLASS: Symbol not found, for `C`| = this@R|/B|.R|/B.q|()
[BODY_RESOLVE] private get(): R|ERROR CLASS: Symbol not found, for `C`|
public final [BODY_RESOLVE] fun foo([BODY_RESOLVE] a: <ERROR TYPE REF: Symbol not found, for `A`>): <ERROR TYPE REF: Unresolved name: with> {
^foo <Unresolved name: with>#(R|<local>/a|, <L> = [BODY_RESOLVE] with@fun <anonymous>(): R|ERROR CLASS: Unresolved name: bar| {
^ <Unresolved name: bar>#(String(a), this@R|/B|.R|/B.y|)
}
)
}
}
@@ -0,0 +1,8 @@
class B {
fun q(): C {}
private val y = q()
fun foo(a: A) = with(a) {
bar("a", y)
}
}
@@ -0,0 +1,10 @@
FILE: constructorParameter.kt
public final [BODY_RESOLVE] class A : R|kotlin/Any| {
public [BODY_RESOLVE] constructor([BODY_RESOLVE] x: R|kotlin/String|): R|A| {
super<R|kotlin/Any|>()
}
public final [BODY_RESOLVE] val x: R|kotlin/String| = R|<local>/x|
[BODY_RESOLVE] public get(): R|kotlin/String|
}
@@ -0,0 +1 @@
class A(val x: String)
@@ -0,0 +1,3 @@
FILE: funWithoutTypes.kt
public final [BODY_RESOLVE] fun main(): R|kotlin/Unit| {
}
@@ -0,0 +1,3 @@
fun main() {
}
@@ -0,0 +1,12 @@
FILE: functionValueParameter.kt
public final [BODY_RESOLVE] fun bar([BODY_RESOLVE] a: R|kotlin/Int|, [BODY_RESOLVE] b: R|(kotlin/Boolean) -> kotlin/Unit|): R|kotlin/Unit| {
}
public final [BODY_RESOLVE] class A : R|kotlin/Any| {
public [BODY_RESOLVE] constructor(): R|A| {
super<R|kotlin/Any|>()
}
public final [BODY_RESOLVE] fun foo([BODY_RESOLVE] x: R|kotlin/String|, [BODY_RESOLVE] y: R|() -> kotlin/String|): R|kotlin/Unit| {
}
}
@@ -0,0 +1,9 @@
fun bar(a: Int, b: (Boolean) -> Unit) {
}
class A {
fun foo(x: String, y: () -> String) {
}
}
@@ -0,0 +1,6 @@
FILE: functionWithImplicitType.kt
public final [BODY_RESOLVE] fun <T> checkSubtype([BODY_RESOLVE] t: R|T|): R|T| {
^checkSubtype R|<local>/t|
}
public final [BODY_RESOLVE] val ab: R|kotlin/collections/List<kotlin/Int>?| = R|/checkSubtype|<R|kotlin/collections/List<kotlin/Int>?|>(Q|java/util/Collections|.R|java/util/Collections.emptyList|<R|ft<kotlin/Int, kotlin/Int?>!|>())
[BODY_RESOLVE] public get(): R|kotlin/collections/List<kotlin/Int>?|
@@ -0,0 +1,5 @@
import java.util.Collections
fun <T> checkSubtype(t: T) = t
val ab = checkSubtype<List<Int>?>(Collections.emptyList<Int>())
@@ -0,0 +1,23 @@
FILE: lambda.kt
public final inline [BODY_RESOLVE] fun <T, R> with([BODY_RESOLVE] receiver: R|T|, [BODY_RESOLVE] block: R|T.() -> R|): R|R| {
^with R|<local>/block|.R|SubstitutionOverride<kotlin/Function1.invoke: R|R|>|(R|<local>/receiver|)
}
public final inline [BODY_RESOLVE] fun <T, R> R|T|.let([BODY_RESOLVE] block: R|(T) -> R|): R|R| {
^let R|<local>/block|.R|SubstitutionOverride<kotlin/Function1.invoke: R|R|>|(this@R|/let|)
}
public final [BODY_RESOLVE] class B : R|kotlin/Any| {
public [BODY_RESOLVE] constructor(): R|B| {
super<R|kotlin/Any|>()
}
public final [BODY_RESOLVE] fun foo([BODY_RESOLVE] a: R|kotlin/Int|): R|kotlin/String| {
^foo R|/with|<R|kotlin/Int|, R|kotlin/String|>(R|<local>/a|, <L> = [BODY_RESOLVE] with@fun R|kotlin/Int|.<anonymous>(): R|kotlin/String| <kind=UNKNOWN> {
^ this@R|special/anonymous|.R|kotlin/Any.toString|().R|/let|<R|kotlin/String|, R|kotlin/String|>(<L> = [BODY_RESOLVE] let@fun <anonymous>([BODY_RESOLVE] it: R|kotlin/String|): R|kotlin/String| <kind=UNKNOWN> {
^ R|<local>/it|
}
)
}
)
}
}
@@ -0,0 +1,23 @@
FILE: lambdaInImplicitFunBody.kt
public final inline [BODY_RESOLVE] fun <T, R> with([BODY_RESOLVE] receiver: R|T|, [BODY_RESOLVE] block: R|T.() -> R|): R|R| {
^with R|<local>/block|.R|SubstitutionOverride<kotlin/Function1.invoke: R|R|>|(R|<local>/receiver|)
}
public final inline [BODY_RESOLVE] fun <T, R> R|T|.let([BODY_RESOLVE] block: R|(T) -> R|): R|R| {
^let R|<local>/block|.R|SubstitutionOverride<kotlin/Function1.invoke: R|R|>|(this@R|/let|)
}
public final [BODY_RESOLVE] class B : R|kotlin/Any| {
public [BODY_RESOLVE] constructor(): R|B| {
super<R|kotlin/Any|>()
}
public final [BODY_RESOLVE] fun foo([BODY_RESOLVE] a: R|kotlin/Int|): R|kotlin/String| {
^foo R|/with|<R|kotlin/Int|, R|kotlin/String|>(R|<local>/a|, <L> = [BODY_RESOLVE] with@fun R|kotlin/Int|.<anonymous>(): R|kotlin/String| <kind=UNKNOWN> {
^ this@R|special/anonymous|.R|kotlin/Any.toString|().R|/let|<R|kotlin/String|, R|kotlin/String|>(<L> = [BODY_RESOLVE] let@fun <anonymous>([BODY_RESOLVE] it: R|kotlin/String|): R|kotlin/String| <kind=UNKNOWN> {
^ R|<local>/it|
}
)
}
)
}
}
@@ -0,0 +1,13 @@
inline fun <T, R> with(receiver: T, block: T.() -> R): R {
return receiver.block()
}
inline fun <T, R> T.let(block: (T) -> R): R {
return block(this)
}
class B {
fun foo(a: Int) = with(a) {
toString().let { it }
}
}
@@ -0,0 +1,25 @@
FILE: lambdaInImplicitPropertyBody.kt
public final inline [BODY_RESOLVE] fun <T, R> with([BODY_RESOLVE] receiver: R|T|, [BODY_RESOLVE] block: R|T.() -> R|): R|R| {
^with R|<local>/block|.R|SubstitutionOverride<kotlin/Function1.invoke: R|R|>|(R|<local>/receiver|)
}
public final inline [BODY_RESOLVE] fun <T, R> R|T|.let([BODY_RESOLVE] block: R|(T) -> R|): R|R| {
^let R|<local>/block|.R|SubstitutionOverride<kotlin/Function1.invoke: R|R|>|(this@R|/let|)
}
public final [BODY_RESOLVE] class B : R|kotlin/Any| {
public [BODY_RESOLVE] constructor(): R|B| {
super<R|kotlin/Any|>()
}
public final [BODY_RESOLVE] val a: R|kotlin/Int| = Int(10)
[BODY_RESOLVE] public get(): R|kotlin/Int|
public final [BODY_RESOLVE] val x: R|kotlin/String| = R|/with|<R|kotlin/Int|, R|kotlin/String|>(this@R|/B|.R|/B.a|, <L> = [BODY_RESOLVE] with@fun R|kotlin/Int|.<anonymous>(): R|kotlin/String| <kind=UNKNOWN> {
^ this@R|special/anonymous|.R|kotlin/Any.toString|().R|/let|<R|kotlin/String|, R|kotlin/String|>(<L> = [BODY_RESOLVE] let@fun <anonymous>([BODY_RESOLVE] it: R|kotlin/String|): R|kotlin/String| <kind=UNKNOWN> {
^ R|<local>/it|
}
)
}
)
[BODY_RESOLVE] public get(): R|kotlin/String|
}
@@ -0,0 +1,14 @@
inline fun <T, R> with(receiver: T, block: T.() -> R): R {
return receiver.block()
}
inline fun <T, R> T.let(block: (T) -> R): R {
return block(this)
}
class B {
val a: Int = 10
val x = with(a) {
toString().let { it }
}
}
@@ -0,0 +1,26 @@
FILE: lambdasInWithBodyFunction.kt
public final inline [BODY_RESOLVE] fun <T, R> with([BODY_RESOLVE] receiver: R|T|, [BODY_RESOLVE] block: R|T.() -> R|): R|R| {
^with R|<local>/block|.R|SubstitutionOverride<kotlin/Function1.invoke: R|R|>|(R|<local>/receiver|)
}
public final inline [BODY_RESOLVE] fun <T, R> R|T|.let([BODY_RESOLVE] block: R|(T) -> R|): R|R| {
^let R|<local>/block|.R|SubstitutionOverride<kotlin/Function1.invoke: R|R|>|(this@R|/let|)
}
public final [BODY_RESOLVE] class A : R|kotlin/Any| {
public [BODY_RESOLVE] constructor(): R|A| {
super<R|kotlin/Any|>()
}
public final [BODY_RESOLVE] fun foo(): R|kotlin/Unit| {
[BODY_RESOLVE] lval a: R|kotlin/Int| = R|/with|<R|kotlin/Int|, R|kotlin/Int|>(Int(1), <L> = [BODY_RESOLVE] with@fun R|kotlin/Int|.<anonymous>(): R|kotlin/Int| <kind=UNKNOWN> {
^ this@R|special/anonymous|.R|/let|<R|kotlin/Int|, R|kotlin/Int|>(<L> = [BODY_RESOLVE] let@fun <anonymous>([BODY_RESOLVE] it: R|kotlin/Int|): R|kotlin/Int| <kind=UNKNOWN> {
^ R|<local>/it|
}
)
}
).R|/let|<R|kotlin/Int|, R|kotlin/Int|>(<L> = [BODY_RESOLVE] let@fun <anonymous>([BODY_RESOLVE] it: R|kotlin/Int|): R|kotlin/Int| <kind=UNKNOWN> {
^ Int(2)
}
)
}
}
@@ -0,0 +1,15 @@
inline fun <T, R> with(receiver: T, block: T.() -> R): R {
return receiver.block()
}
inline fun <T, R> T.let(block: (T) -> R): R {
return block(this)
}
class A {
fun foo() {
val a = with(1) {
this.let { it }
}.let { 2 }
}
}
@@ -0,0 +1,13 @@
FILE: localClass.kt
public final [BODY_RESOLVE] fun x(): R|kotlin/Unit| {
local final [BODY_RESOLVE] class Local : R|kotlin/Any| {
public [BODY_RESOLVE] constructor(): R|Local| {
super<R|kotlin/Any|>()
}
public final [BODY_RESOLVE] fun foo(): R|kotlin/Unit| {
}
}
}
@@ -0,0 +1,5 @@
fun x() {
class Local {
fun foo(){}
}
}
@@ -0,0 +1,8 @@
FILE: propertyWithGetterAndSetter.kt
public final [BODY_RESOLVE] var withGetterAndSetter: R|kotlin/Int| = Int(42)
[BODY_RESOLVE] public get(): R|kotlin/Int| {
^ F|/withGetterAndSetter|
}
[BODY_RESOLVE] public set([BODY_RESOLVE] value: R|kotlin/Int|): R|kotlin/Unit| {
F|/withGetterAndSetter| = R|<local>/value|
}
@@ -0,0 +1,5 @@
var withGetterAndSetter: Int = 42
get() = field
set(value) {
field = value
}
@@ -0,0 +1,25 @@
FILE: propertyWithSetter.kt
public abstract [BODY_RESOLVE] class Foo : R|kotlin/Any| {
public [BODY_RESOLVE] constructor(): R|Foo| {
super<R|kotlin/Any|>()
}
public abstract [BODY_RESOLVE] var id: R|kotlin/Int|
[BODY_RESOLVE] public get(): R|kotlin/Int|
[BODY_RESOLVE] protected set([BODY_RESOLVE] value: R|kotlin/Int|): R|kotlin/Unit|
}
public final [BODY_RESOLVE] class Bar : R|Foo| {
public [BODY_RESOLVE] constructor(): R|Bar| {
super<R|Foo|>()
}
public final override [BODY_RESOLVE] var id: R|kotlin/Int| = Int(1)
[BODY_RESOLVE] public get(): R|kotlin/Int|
[BODY_RESOLVE] public set([BODY_RESOLVE] value: R|kotlin/Int|): R|kotlin/Unit|
}
public final [BODY_RESOLVE] fun test(): R|kotlin/Unit| {
[BODY_RESOLVE] lval bar: R|Bar| = R|/Bar.Bar|()
R|<local>/bar|.R|/Bar.id| = Int(1)
}
@@ -0,0 +1,14 @@
abstract class Foo {
abstract var id: Int
protected set
}
class Bar : Foo() {
override var id: Int = 1
<caret>public set
}
fun test() {
val bar = Bar()
bar.id = 1
}
@@ -0,0 +1,36 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.fir.low.level.api.resolve
import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.FirRenderer
import org.jetbrains.kotlin.fir.declarations.FirFile
import org.jetbrains.kotlin.fir.render
import org.jetbrains.kotlin.fir.visitors.FirVisitor
import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
import org.jetbrains.kotlin.idea.fir.low.level.api.api.getOrBuildFir
import org.jetbrains.kotlin.idea.fir.low.level.api.api.getOrBuildFirOfType
import org.jetbrains.kotlin.idea.fir.low.level.api.api.getResolveState
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.test.KotlinTestUtils
import java.io.File
abstract class AbstractInnerDeclarationsResolvePhaseTest : KotlinLightCodeInsightFixtureTestCase() {
override fun isFirPlugin(): Boolean = true
fun doTest(path: String) {
val testDataFile = File(path)
val ktFile = myFixture.configureByText(testDataFile.name, FileUtil.loadFile(testDataFile)) as KtFile
val resolveState = ktFile.getResolveState()
val firFile = ktFile.getOrBuildFirOfType<FirFile>(resolveState)
val actual = firFile.render(FirRenderer.RenderMode.WithResolvePhases)
val expectedFileName = testDataFile.name.replace(".kt", ".fir.txt")
KotlinTestUtils.assertEqualsToFile(testDataFile.parentFile.resolve(expectedFileName), actual)
}
}
@@ -0,0 +1,91 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.fir.low.level.api.resolve;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class InnerDeclarationsResolvePhaseTestGenerated extends AbstractInnerDeclarationsResolvePhaseTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInInnerDeclarationsResolve() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("annonymousClass.kt")
public void testAnnonymousClass() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/annonymousClass.kt");
}
@TestMetadata("class.kt")
public void testClass() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/class.kt");
}
@TestMetadata("constructorParameter.kt")
public void testConstructorParameter() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/constructorParameter.kt");
}
@TestMetadata("funWithoutTypes.kt")
public void testFunWithoutTypes() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/funWithoutTypes.kt");
}
@TestMetadata("functionValueParameter.kt")
public void testFunctionValueParameter() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/functionValueParameter.kt");
}
@TestMetadata("functionWithImplicitType.kt")
public void testFunctionWithImplicitType() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/functionWithImplicitType.kt");
}
@TestMetadata("lambdaInImplicitFunBody.kt")
public void testLambdaInImplicitFunBody() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdaInImplicitFunBody.kt");
}
@TestMetadata("lambdaInImplicitPropertyBody.kt")
public void testLambdaInImplicitPropertyBody() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdaInImplicitPropertyBody.kt");
}
@TestMetadata("lambdasInWithBodyFunction.kt")
public void testLambdasInWithBodyFunction() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/lambdasInWithBodyFunction.kt");
}
@TestMetadata("localClass.kt")
public void testLocalClass() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/localClass.kt");
}
@TestMetadata("propertyWithGetterAndSetter.kt")
public void testPropertyWithGetterAndSetter() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/propertyWithGetterAndSetter.kt");
}
@TestMetadata("propertyWithSetter.kt")
public void testPropertyWithSetter() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/propertyWithSetter.kt");
}
}