diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/handlers/FirNoImplicitTypesHandler.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/handlers/FirNoImplicitTypesHandler.kt new file mode 100644 index 00000000000..3d629f5cb7c --- /dev/null +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/handlers/FirNoImplicitTypesHandler.kt @@ -0,0 +1,53 @@ +/* + * 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.test.frontend.fir.handlers + +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.render +import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef +import org.jetbrains.kotlin.fir.visitors.FirDefaultVisitor +import org.jetbrains.kotlin.test.frontend.fir.FirOutputArtifact +import org.jetbrains.kotlin.test.model.TestModule +import org.jetbrains.kotlin.test.services.TestServices + +class FirNoImplicitTypesHandler(testServices: TestServices) : FirAnalysisHandler(testServices, failureDisablesNextSteps = true) { + override fun processModule(module: TestModule, info: FirOutputArtifact) { + val visitor = Visitor() + for (firFile in info.firFiles.values) { + firFile.acceptChildren(visitor, firFile) + } + if (visitor.detectedImplicitTypesParents.isNotEmpty()) { + assertions.fail { + buildString { + val count = visitor.detectedImplicitTypesParents.size + if (count == 1) { + appendLine("One implicit type was found:") + } else { + appendLine("$count implicit types were found:") + } + val types = visitor.detectedImplicitTypesParents.joinToString(separator = "\n") { + " - Type in ${it.render()}" + } + append(types) + } + } + } + } + + private inner class Visitor : FirDefaultVisitor() { + val detectedImplicitTypesParents = mutableListOf() + + override fun visitElement(element: FirElement, data: FirElement) { + element.acceptChildren(this, element) + } + + override fun visitImplicitTypeRef(implicitTypeRef: FirImplicitTypeRef, data: FirElement) { + detectedImplicitTypesParents += data + } + } + + override fun processAfterAllModules(someAssertionWasFailed: Boolean) {} +} diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractFirDiagnosticTest.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractFirDiagnosticTest.kt index 5782a932016..ad440c49124 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractFirDiagnosticTest.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/AbstractFirDiagnosticTest.kt @@ -51,6 +51,7 @@ abstract class AbstractFirDiagnosticTest : AbstractKotlinCompilerTest() { ::FirDumpHandler, ::FirCfgDumpHandler, ::FirCfgConsistencyHandler, + ::FirNoImplicitTypesHandler, ) useMetaInfoProcessors(::PsiLightTreeMetaInfoProcessor) diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractFirBlackBoxCodegenTest.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractFirBlackBoxCodegenTest.kt index b011c4445b9..474f14d7768 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractFirBlackBoxCodegenTest.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/codegen/AbstractFirBlackBoxCodegenTest.kt @@ -15,6 +15,7 @@ import org.jetbrains.kotlin.test.frontend.fir.FirFrontendFacade import org.jetbrains.kotlin.test.frontend.fir.FirOutputArtifact import org.jetbrains.kotlin.test.frontend.fir.handlers.FirCfgDumpHandler import org.jetbrains.kotlin.test.frontend.fir.handlers.FirDumpHandler +import org.jetbrains.kotlin.test.frontend.fir.handlers.FirNoImplicitTypesHandler import org.jetbrains.kotlin.test.frontend.fir.handlers.FirScopeDumpHandler import org.jetbrains.kotlin.test.model.* @@ -38,8 +39,12 @@ open class AbstractFirBlackBoxCodegenTest : AbstractJvmBlackBoxCodegenTestBase