[MERGE] KT: build-1.5.20-dev-372 KT/N: e734b52b0 OLD: d72e63334

This commit is contained in:
Vasily Levchenko
2021-02-09 09:00:56 +01:00
1995 changed files with 44173 additions and 26832 deletions
+3 -3
View File
@@ -109,13 +109,13 @@ Refer to [libraries/ReadMe.md](libraries/ReadMe.md) for details.
### Building for different versions of IntelliJ IDEA and Android Studio
Kotlin plugin is intended to work with several recent versions of IntelliJ IDEA and Android Studio. Each platform is allowed to have a different set of features and might provide a slightly different API. Instead of using several parallel Git branches, project stores everything in a single branch, but files may have counterparts with version extensions (\*.as32, \*.172, \*.181). The primary file is expected to be replaced with its counterpart when targeting non-default platform.
Kotlin plugin is intended to work with several recent versions of IntelliJ IDEA and Android Studio. Each platform is allowed to have a different set of features and might provide a slightly different API. Instead of using several parallel Git branches, the project stores everything in a single branch, but files may have counterparts with version extensions (\*.as32, \*.172, \*.181). The primary file is expected to be replaced with its counterpart when targeting a non-default platform.
More detailed description of this scheme can be found at https://github.com/JetBrains/bunches/blob/master/ReadMe.md.
A More detailed description of this scheme can be found at https://github.com/JetBrains/bunches/blob/master/ReadMe.md.
Usually, there's no need to care about multiple platforms as all features are enabled everywhere by default. Additional counterparts should be created if there's an expected difference in behavior or an incompatible API usage is required **and** there's no reasonable workaround to save source compatibility. Kotlin plugin contains a pre-commit check that shows a warning if a file has been updated without its counterparts.
Development for some particular platform is possible after 'switching' that can be done with [Bunch Tool](https://github.com/JetBrains/bunches/releases) from the command line.
Development for some particular platform is possible after 'switching' that can be done with the [Bunch Tool](https://github.com/JetBrains/bunches/releases) from the command line.
```sh
cd kotlin-project-dir
@@ -21,6 +21,7 @@ data class IncrementalModuleEntry(
class IncrementalModuleInfo(
val projectRoot: File,
val rootProjectBuildDir: File,
val dirToModule: Map<File, IncrementalModuleEntry>,
val nameToModules: Map<String, Set<IncrementalModuleEntry>>,
val jarToClassListFile: Map<File, File>,
@@ -28,6 +29,6 @@ class IncrementalModuleInfo(
val jarToModule: Map<File, IncrementalModuleEntry>
) : Serializable {
companion object {
private const val serialVersionUID = 0L
private const val serialVersionUID = 1L
}
}
+7 -6
View File
@@ -345,6 +345,7 @@ val coreLibProjects = listOfNotNull(
":kotlin-stdlib-js",
":kotlin-stdlib-jdk7",
":kotlin-stdlib-jdk8",
":kotlin-test",
":kotlin-test:kotlin-test-annotations-common",
":kotlin-test:kotlin-test-common",
":kotlin-test:kotlin-test-jvm",
@@ -471,7 +472,7 @@ allprojects {
}
}
if (!kotlinBuildProperties.isInJpsBuildIdeaSync && !kotlinBuildProperties.useFir) {
if (!kotlinBuildProperties.isInJpsBuildIdeaSync && !kotlinBuildProperties.useFir && !kotlinBuildProperties.disableWerror) {
// For compiler and stdlib, allWarningsAsErrors is configured in the corresponding "root" projects
// (compiler/build.gradle.kts and libraries/commonConfiguration.gradle).
val projectsWithWarningsAsErrors = listOf("core", "plugins").map { File(it).absoluteFile }
@@ -637,7 +638,10 @@ tasks {
listOf("clean", "assemble", "install").forEach { taskName ->
register("coreLibs${taskName.capitalize()}") {
coreLibProjects.forEach { projectName -> dependsOn("$projectName:$taskName") }
for (projectName in coreLibProjects) {
if (projectName.startsWith(":kotlin-test:") && taskName == "install") continue
dependsOn("$projectName:$taskName")
}
}
}
@@ -953,7 +957,6 @@ tasks {
dependsOn(
":prepare:ide-plugin-dependencies:android-extensions-compiler-plugin-for-ide:publish",
":prepare:ide-plugin-dependencies:allopen-compiler-plugin-for-ide:publish",
":prepare:ide-plugin-dependencies:allopen-compiler-plugin-tests-for-ide:publish",
":prepare:ide-plugin-dependencies:incremental-compilation-impl-tests-for-ide:publish",
":prepare:ide-plugin-dependencies:kotlin-build-common-tests-for-ide:publish",
":prepare:ide-plugin-dependencies:kotlin-compiler-for-ide:publish",
@@ -975,9 +978,7 @@ tasks {
":kotlin-stdlib-jdk7:publish",
":kotlin-stdlib-jdk8:publish",
":kotlin-reflect:publish",
":kotlin-main-kts:publish",
":kotlin-stdlib-js:publish",
":kotlin-test:kotlin-test-js:publish"
":kotlin-main-kts:publish"
)
}
}
@@ -18,3 +18,5 @@ val KotlinBuildProperties.proguard: Boolean get() = postProcessing && getBoolean
val KotlinBuildProperties.jarCompression: Boolean get() = getBoolean("kotlin.build.jar.compression", isTeamcityBuild)
val KotlinBuildProperties.ignoreTestFailures: Boolean get() = getBoolean("ignoreTestFailures", isTeamcityBuild)
val KotlinBuildProperties.disableWerror: Boolean get() = getBoolean("kotlin.build.disable.werror", false)
+47
View File
@@ -9,10 +9,13 @@
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.ExternalModuleDependency
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.FileCollection
import org.gradle.kotlin.dsl.accessors.runtime.addDependencyTo
import org.gradle.kotlin.dsl.extra
import org.gradle.kotlin.dsl.project
import java.io.File
@@ -112,6 +115,50 @@ fun DependencyHandler.projectTests(name: String): ProjectDependency = project(na
fun DependencyHandler.projectRuntimeJar(name: String): ProjectDependency = project(name, configuration = "runtimeJar")
fun DependencyHandler.projectArchives(name: String): ProjectDependency = project(name, configuration = "archives")
fun Project.testApiJUnit5(
vintageEngine: Boolean = false,
runner: Boolean = false,
suiteApi: Boolean = false
) {
with(dependencies) {
val platformVersion = commonVer("org.junit", "junit-bom")
testApi(platform("org.junit:junit-bom:$platformVersion"))
testApi("org.junit.jupiter:junit-jupiter")
if (vintageEngine) {
testApi("org.junit.vintage:junit-vintage-engine:$platformVersion")
}
val componentsVersion = commonVer("org.junit.platform", "")
val components = mutableListOf(
"org.junit.platform:junit-platform-commons",
"org.junit.platform:junit-platform-launcher"
)
if (runner) {
components += "org.junit.platform:junit-platform-runner"
}
if (suiteApi) {
components += "org.junit.platform:junit-platform-suite-api"
}
for (component in components) {
testApi("$component:$componentsVersion")
}
addDependencyTo<ExternalModuleDependency>(this, "testImplementation", intellijDep()) {
// This dependency is needed only for FileComparisonFailure
includeJars("idea_rt", rootProject = rootProject)
isTransitive = false
}
// This is needed only for using FileComparisonFailure, which relies on JUnit 3 classes
add("testRuntimeOnly", commonDep("junit:junit"))
}
}
private fun DependencyHandler.testApi(dependencyNotation: Any) {
add("testApi", dependencyNotation)
}
val Project.protobufVersion: String get() = findProperty("versions.protobuf") as String
val Project.protobufRepo: String
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.
*/
@@ -71,62 +71,11 @@ class KotlinBuildPublishingPlugin @Inject constructor(
create<MavenPublication>(PUBLICATION_NAME) {
from(kotlinLibraryComponent)
pom {
packaging = "jar"
name.set(humanReadableName(project))
description.set(project.description ?: humanReadableName(project))
url.set("https://kotlinlang.org/")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
scm {
url.set("https://github.com/JetBrains/kotlin")
connection.set("scm:git:https://github.com/JetBrains/kotlin.git")
developerConnection.set("scm:git:https://github.com/JetBrains/kotlin.git")
}
developers {
developer {
name.set("Kotlin Team")
organization.set("JetBrains")
organizationUrl.set("https://www.jetbrains.com")
}
}
}
}
}
repositories {
maven {
name = REPOSITORY_NAME
url = file("${project.rootDir}/build/repo").toURI()
configureKotlinPomAttributes(project)
}
}
}
val signingRequired = provider {
project.findProperty("signingRequired")?.toString()?.toBoolean()
?: project.property("isSonatypeRelease") as Boolean
}
configure<SigningExtension> {
setRequired(signingRequired)
sign(extensions.getByType<PublishingExtension>().publications[PUBLICATION_NAME])
useGpgCmd()
}
tasks.withType<Sign>().configureEach {
setOnlyIf { signingRequired.get() }
}
tasks.register("install") {
dependsOn(tasks.named("publishToMavenLocal"))
}
tasks.named<PublishToMavenRepository>("publish${PUBLICATION_NAME}PublicationTo${REPOSITORY_NAME}Repository")
.configureRepository()
configureDefaultPublishing()
}
companion object {
@@ -137,13 +86,84 @@ class KotlinBuildPublishingPlugin @Inject constructor(
const val COMPILE_CONFIGURATION = "publishedCompile"
const val RUNTIME_CONFIGURATION = "publishedRuntime"
@OptIn(ExperimentalStdlibApi::class)
fun humanReadableName(project: Project) =
project.name.split("-").joinToString(separator = " ") { it.capitalize(Locale.ROOT) }
}
}
fun TaskProvider<PublishToMavenRepository>.configureRepository() = configure {
@OptIn(ExperimentalStdlibApi::class)
private fun humanReadableName(name: String) =
name.split("-").joinToString(separator = " ") { it.capitalize(Locale.ROOT) }
fun MavenPublication.configureKotlinPomAttributes(project: Project, explicitDescription: String? = null) {
val publication = this
pom {
packaging = "jar"
name.set(humanReadableName(publication.artifactId))
description.set(explicitDescription ?: project.description ?: humanReadableName(publication.artifactId))
url.set("https://kotlinlang.org/")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
scm {
url.set("https://github.com/JetBrains/kotlin")
connection.set("scm:git:https://github.com/JetBrains/kotlin.git")
developerConnection.set("scm:git:https://github.com/JetBrains/kotlin.git")
}
developers {
developer {
name.set("Kotlin Team")
organization.set("JetBrains")
organizationUrl.set("https://www.jetbrains.com")
}
}
}
}
fun Project.configureDefaultPublishing() {
configure<PublishingExtension> {
repositories {
maven {
name = KotlinBuildPublishingPlugin.REPOSITORY_NAME
url = file("${project.rootDir}/build/repo").toURI()
}
}
}
configureSigning()
tasks.register("install") {
dependsOn(tasks.named("publishToMavenLocal"))
}
tasks.withType<PublishToMavenRepository>()
.matching { it.name.endsWith("PublicationTo${KotlinBuildPublishingPlugin.REPOSITORY_NAME}Repository") }
.all { configureRepository() }
}
private fun Project.configureSigning() {
val signingRequired = provider {
project.findProperty("signingRequired")?.toString()?.toBoolean()
?: project.property("isSonatypeRelease") as Boolean
}
configure<SigningExtension> {
setRequired(signingRequired)
sign(extensions.getByType<PublishingExtension>().publications) // all publications
useGpgCmd()
}
tasks.withType<Sign>().configureEach {
setOnlyIf { signingRequired.get() }
}
}
fun TaskProvider<PublishToMavenRepository>.configureRepository() =
configure { configureRepository() }
private fun PublishToMavenRepository.configureRepository() {
dependsOn(project.rootProject.tasks.named("preparePublication"))
doFirst {
val preparePublication = project.rootProject.tasks.named("preparePublication").get()
+3 -18
View File
@@ -1,17 +1,6 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 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.
*/
@@ -51,11 +40,7 @@ fun Task.dependsOnKotlinPluginInstall() {
":kotlin-gradle-plugin-model:install",
":kotlin-reflect:install",
":kotlin-annotation-processing-gradle:install",
":kotlin-test:kotlin-test-common:install",
":kotlin-test:kotlin-test-annotations-common:install",
":kotlin-test:kotlin-test-jvm:install",
":kotlin-test:kotlin-test-js:install",
":kotlin-test:kotlin-test-junit:install",
":kotlin-test:install",
":kotlin-gradle-subplugin-example:install",
":kotlin-stdlib-common:install",
":kotlin-stdlib:install",
@@ -80,14 +80,6 @@ android {
reflect0 {
dimension "box"
}
jvm80 {
dimension "box"
}
reflectjvm80 {
dimension "box"
}
}
}
@@ -44,10 +44,8 @@ class CodegenTestsOnAndroidGenerator private constructor(private val pathManager
//keep it globally to avoid test grouping on TC
private val generatedTestNames = hashSetOf<String>()
private val COMMON = FlavorConfig("common", 3);
private val REFLECT = FlavorConfig("reflect", 1);
private val JVM8 = FlavorConfig("jvm8", 1);
private val JVM8REFLECT = FlavorConfig("reflectjvm8", 1);
private val COMMON = FlavorConfig("common", 3)
private val REFLECT = FlavorConfig("reflect", 1)
class FlavorConfig(private val prefix: String, val limit: Int) {
@@ -100,7 +98,7 @@ class CodegenTestsOnAndroidGenerator private constructor(private val pathManager
it.setExecutable(true)
}
}
File("./gradlew.bat").copyTo(File(projectRoot, "gradlew.bat"));
File("./gradlew.bat").copyTo(File(projectRoot, "gradlew.bat"))
val file = File(target, "gradle-wrapper.properties")
file.readLines().map {
when {
@@ -156,8 +154,6 @@ class CodegenTestsOnAndroidGenerator private constructor(private val pathManager
COMMON.printStatistics()
REFLECT.printStatistics()
JVM8.printStatistics()
JVM8REFLECT.printStatistics()
}
internal inner class FilesWriter(
@@ -279,14 +275,16 @@ class CodegenTestsOnAndroidGenerator private constructor(private val pathManager
//TODO support JvmPackageName
if (fullFileText.contains("@file:JvmPackageName(")) continue
// TODO: Support jvm assertions
if (fullFileText.contains("// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm")) continue
if (fullFileText.contains("// ASSERTIONS_MODE: jvm")) continue
if (fullFileText.contains("// MODULE: ")) continue
val targets = InTextDirectivesUtils.findLinesWithPrefixesRemoved(fullFileText, "// JVM_TARGET:")
.also { it.remove(JvmTarget.JVM_1_6.description) }
val isJvm8Target =
if (targets.isEmpty()) false
else if (targets.contains(JvmTarget.JVM_1_8.description) && targets.size == 1) true
else continue //TODO: support other targets on Android
val isAtLeastJvm8Target = !targets.contains(JvmTarget.JVM_1_6.description)
if (isAtLeastJvm8Target && fullFileText.contains("@Target(AnnotationTarget.TYPE)")) {
//TODO: type annotations supported on sdk 26 emulator
continue
}
// TODO: support SKIP_JDK6 on new platforms
if (fullFileText.contains("// SKIP_JDK6")) continue
@@ -299,9 +297,7 @@ class CodegenTestsOnAndroidGenerator private constructor(private val pathManager
KotlinBaseTest.updateConfigurationByDirectivesInTestFiles(testFiles, keyConfiguration)
val key = ConfigurationKey(kind, jdkKind, keyConfiguration.toString())
val compiler = if (isJvm8Target) {
if (kind.withReflection) JVM8REFLECT else JVM8
} else if (kind.withReflection) REFLECT else COMMON
val compiler = if (kind.withReflection) REFLECT else COMMON
val filesHolder = holders.getOrPut(key) {
FilesWriter(compiler, KotlinTestUtils.newConfiguration(kind, jdkKind,
KtTestUtil.getAnnotationsJar()
@@ -14,7 +14,6 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
public class AsmTypes {
private static final Map<Class<?>, Type> TYPES_MAP = new HashMap<>();
@@ -58,7 +58,7 @@ class OriginCollectingClassBuilderFactory(private val builderMode: ClassBuilderM
}
override fun asBytes(builder: ClassBuilder): ByteArray {
val classWriter = ClassWriter(0)
val classWriter = ClassWriter(ClassWriter.COMPUTE_FRAMES or ClassWriter.COMPUTE_MAXS)
(builder as OriginCollectingClassBuilder).classNode.accept(classWriter)
return classWriter.toByteArray()
}
@@ -66,4 +66,4 @@ class OriginCollectingClassBuilderFactory(private val builderMode: ClassBuilderM
override fun asText(builder: ClassBuilder) = throw UnsupportedOperationException()
override fun close() {}
}
}
@@ -629,7 +629,11 @@ public abstract class StackValue {
}
public static void coerce(@NotNull Type fromType, @NotNull Type toType, @NotNull InstructionAdapter v) {
if (toType.equals(fromType)) return;
coerce(fromType, toType, v, false);
}
public static void coerce(@NotNull Type fromType, @NotNull Type toType, @NotNull InstructionAdapter v, boolean forceSelfCast) {
if (toType.equals(fromType) && !forceSelfCast) return;
if (toType.getSort() == Type.VOID) {
pop(v, fromType);
@@ -319,7 +319,7 @@ class AnonymousObjectTransformer(
), null
)
val result = inliner.doInline(deferringVisitor, LocalVarRemapper(parameters, 0), false, ReturnLabelOwner.NOT_APPLICABLE)
val result = inliner.doInline(deferringVisitor, LocalVarRemapper(parameters, 0), false, mapOf())
result.reifiedTypeParametersUsages.mergeAll(typeParametersToReify)
deferringVisitor.visitMaxs(-1, -1)
return result
@@ -243,12 +243,10 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
//hack to keep linenumber info, otherwise jdi will skip begin of linenumber chain
adapter.visitInsn(Opcodes.NOP)
val result = inliner.doInline(adapter, remapper, true, ReturnLabelOwner.SKIP_ALL)
val result = inliner.doInline(adapter, remapper, true, mapOf())
result.reifiedTypeParametersUsages.mergeAll(reificationResult)
val labels = sourceCompiler.getContextLabels()
val infos = MethodInliner.processReturns(adapter, ReturnLabelOwner { labels.contains(it) }, true, null)
val infos = MethodInliner.processReturns(adapter, sourceCompiler.getContextLabels(), null)
generateAndInsertFinallyBlocks(
adapter, infos, (remapper.remap(parameters.argsSizeOnStack + 1).value as StackValue.Local).index
)
@@ -319,7 +317,9 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
frameMap.enterTemp(Type.INT_TYPE)
}
sourceCompiler.generateFinallyBlocksIfNeeded(finallyCodegen, extension.returnType, extension.finallyIntervalEnd.label)
sourceCompiler.generateFinallyBlocksIfNeeded(
finallyCodegen, extension.returnType, extension.finallyIntervalEnd.label, extension.jumpTarget
)
//Exception table for external try/catch/finally blocks will be generated in original codegen after exiting this method
insertNodeBefore(finallyNode, intoNode, curInstr)
@@ -30,17 +30,14 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCallWithAssert
import org.jetbrains.kotlin.resolve.jvm.AsmTypes.*
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.util.OperatorNameConventions
import org.jetbrains.org.objectweb.asm.ClassReader
import org.jetbrains.org.objectweb.asm.ClassVisitor
import org.jetbrains.org.objectweb.asm.Opcodes
import org.jetbrains.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.*
import org.jetbrains.org.objectweb.asm.commons.Method
import org.jetbrains.org.objectweb.asm.tree.FieldInsnNode
import kotlin.properties.Delegates
interface FunctionalArgument
abstract class LambdaInfo(@JvmField val isCrossInline: Boolean) : FunctionalArgument, ReturnLabelOwner {
abstract class LambdaInfo(@JvmField val isCrossInline: Boolean) : FunctionalArgument {
abstract val isBoundCallableReference: Boolean
@@ -54,6 +51,9 @@ abstract class LambdaInfo(@JvmField val isCrossInline: Boolean) : FunctionalArgu
abstract val capturedVars: List<CapturedParamDesc>
open val returnLabels: Map<String, Label?>
get() = mapOf()
lateinit var node: SMAPAndMethodNode
abstract fun generateLambdaBody(sourceCompiler: SourceCompilerForInline, reifiedTypeInliner: ReifiedTypeInliner<*>)
@@ -129,8 +129,6 @@ abstract class DefaultLambda(
final override lateinit var capturedVars: List<CapturedParamDesc>
private set
override fun isReturnFromMe(labelName: String): Boolean = false
var originalBoundReceiverType: Type? = null
private set
@@ -247,7 +245,7 @@ class PsiExpressionLambda(
val functionWithBodyOrCallableReference: KtExpression = (expression as? KtLambdaExpression)?.functionLiteral ?: expression
private val labels: Set<String>
override val returnLabels: Map<String, Label?>
override val isSuspend: Boolean
@@ -284,7 +282,7 @@ class PsiExpressionLambda(
closure = it!!
}
labels = InlineCodegen.getDeclarationLabels(expression, invokeMethodDescriptor)
returnLabels = InlineCodegen.getDeclarationLabels(expression, invokeMethodDescriptor).associateWith { null }
invokeMethod = typeMapper.mapAsmMethod(invokeMethodDescriptor)
isSuspend = invokeMethodDescriptor.isSuspend
}
@@ -324,10 +322,6 @@ class PsiExpressionLambda(
}
}
override fun isReturnFromMe(labelName: String): Boolean {
return labels.contains(labelName)
}
val isPropertyReference: Boolean
get() = propertyReferenceInfo != null
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.codegen.optimization.common.isMeaningful
import org.jetbrains.kotlin.codegen.optimization.fixStack.peek
import org.jetbrains.kotlin.codegen.optimization.fixStack.top
import org.jetbrains.kotlin.codegen.optimization.nullCheck.isCheckParameterIsNotNull
import org.jetbrains.kotlin.codegen.pseudoInsns.PseudoInsn
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
@@ -72,9 +73,9 @@ class MethodInliner(
adapter: MethodVisitor,
remapper: LocalVarRemapper,
remapReturn: Boolean,
returnLabelOwner: ReturnLabelOwner
returnLabels: Map<String, Label?>
): InlineResult {
return doInline(adapter, remapper, remapReturn, returnLabelOwner, 0)
return doInline(adapter, remapper, remapReturn, returnLabels, 0)
}
private fun recordTransformation(info: TransformationInfo) {
@@ -91,11 +92,11 @@ class MethodInliner(
adapter: MethodVisitor,
remapper: LocalVarRemapper,
remapReturn: Boolean,
returnLabelOwner: ReturnLabelOwner,
returnLabels: Map<String, Label?>,
finallyDeepShift: Int
): InlineResult {
//analyze body
var transformedNode = markPlacesForInlineAndRemoveInlinable(node, returnLabelOwner, finallyDeepShift)
var transformedNode = markPlacesForInlineAndRemoveInlinable(node, returnLabels, finallyDeepShift)
if (inliningContext.isInliningLambda && isDefaultLambdaWithReification(inliningContext.lambdaInfo!!)) {
//TODO maybe move reification in one place
inliningContext.root.inlineMethodReifier.reifyInstructions(transformedNode)
@@ -139,7 +140,9 @@ class MethodInliner(
)
}
processReturns(resultNode, returnLabelOwner, remapReturn, end)
if (remapReturn) {
processReturns(resultNode, returnLabels, end)
}
//flush transformed node to output
resultNode.accept(SkipMaxAndEndVisitor(adapter))
return result
@@ -297,7 +300,7 @@ class MethodInliner(
val varRemapper = LocalVarRemapper(lambdaParameters, valueParamShift)
//TODO add skipped this and receiver
val lambdaResult = inliner.doInline(localVariablesSorter, varRemapper, true, info, invokeCall.finallyDepthShift)
val lambdaResult = inliner.doInline(localVariablesSorter, varRemapper, true, info.returnLabels, invokeCall.finallyDepthShift)
result.mergeWithNotChangeInfo(lambdaResult)
result.reifiedTypeParametersUsages.mergeAll(lambdaResult.reifiedTypeParametersUsages)
@@ -486,11 +489,11 @@ class MethodInliner(
}
private fun markPlacesForInlineAndRemoveInlinable(
node: MethodNode, returnLabelOwner: ReturnLabelOwner, finallyDeepShift: Int
node: MethodNode, returnLabels: Map<String, Label?>, finallyDeepShift: Int
): MethodNode {
val processingNode = prepareNode(node, finallyDeepShift)
preprocessNodeBeforeInline(processingNode, returnLabelOwner)
preprocessNodeBeforeInline(processingNode, returnLabels)
replaceContinuationAccessesWithFakeContinuationsIfNeeded(processingNode)
@@ -765,7 +768,7 @@ class MethodInliner(
}
}
private fun preprocessNodeBeforeInline(node: MethodNode, returnLabelOwner: ReturnLabelOwner) {
private fun preprocessNodeBeforeInline(node: MethodNode, returnLabels: Map<String, Label?>) {
try {
FixStackWithLabelNormalizationMethodTransformer().transform("fake", node)
} catch (e: Throwable) {
@@ -787,16 +790,13 @@ class MethodInliner(
if (!isReturnOpcode(insnNode.opcode)) continue
var insertBeforeInsn = insnNode
// TODO extract isLocalReturn / isNonLocalReturn, see processReturns
val labelName = getMarkedReturnLabelOrNull(insnNode)
if (labelName != null) {
if (!returnLabelOwner.isReturnFromMe(labelName)) continue
insertBeforeInsn = insnNode.previous
if (labelName == null) {
localReturnsNormalizer.addLocalReturnToTransform(insnNode, insnNode, frame)
} else if (labelName in returnLabels) {
localReturnsNormalizer.addLocalReturnToTransform(insnNode, insnNode.previous, frame)
}
localReturnsNormalizer.addLocalReturnToTransform(insnNode, insertBeforeInsn, frame)
}
localReturnsNormalizer.transform(node)
@@ -1001,7 +1001,8 @@ class MethodInliner(
class PointForExternalFinallyBlocks(
@JvmField val beforeIns: AbstractInsnNode,
@JvmField val returnType: Type,
@JvmField val finallyIntervalEnd: LabelNode
@JvmField val finallyIntervalEnd: LabelNode,
@JvmField val jumpTarget: Label?
)
companion object {
@@ -1115,55 +1116,44 @@ class MethodInliner(
//process local and global returns (local substituted with goto end-label global kept unchanged)
@JvmStatic
fun processReturns(
node: MethodNode, returnLabelOwner: ReturnLabelOwner, remapReturn: Boolean, endLabel: Label?
node: MethodNode, returnLabels: Map<String, Label?>, endLabel: Label?
): List<PointForExternalFinallyBlocks> {
if (!remapReturn) {
return emptyList()
}
val result = ArrayList<PointForExternalFinallyBlocks>()
val instructions = node.instructions
var insnNode: AbstractInsnNode? = instructions.first
while (insnNode != null) {
if (isReturnOpcode(insnNode.opcode)) {
var isLocalReturn = true
val labelName = getMarkedReturnLabelOrNull(insnNode)
val returnType = getReturnType(insnNode.opcode)
if (labelName != null) {
isLocalReturn = returnLabelOwner.isReturnFromMe(labelName)
//remove global return flag
if (isLocalReturn) {
instructions.remove(insnNode.previous)
}
val isLocalReturn = labelName == null || labelName in returnLabels
val jumpTarget = returnLabels[labelName] ?: endLabel
if (isLocalReturn && labelName != null) {
// remove non-local return flag
instructions.remove(insnNode.previous)
}
if (isLocalReturn && endLabel != null) {
val nop = InsnNode(Opcodes.NOP)
instructions.insert(insnNode, nop)
val labelNode = endLabel.info as LabelNode
val jumpInsnNode = JumpInsnNode(Opcodes.GOTO, labelNode)
instructions.insert(nop, jumpInsnNode)
if (isLocalReturn && jumpTarget != null) {
val jumpInsnNode = JumpInsnNode(Opcodes.GOTO, jumpTarget.info as LabelNode)
instructions.insertBefore(insnNode, InsnNode(Opcodes.NOP))
if (jumpTarget != endLabel) {
instructions.insertBefore(insnNode, PseudoInsn.FIX_STACK_BEFORE_JUMP.createInsnNode())
}
instructions.insertBefore(insnNode, jumpInsnNode)
instructions.remove(insnNode)
insnNode = jumpInsnNode
}
//generate finally block before nonLocalReturn flag/return/goto
val label = LabelNode()
instructions.insert(insnNode, label)
result.add(
PointForExternalFinallyBlocks(
getInstructionToInsertFinallyBefore(insnNode, isLocalReturn), getReturnType(insnNode.opcode), label
)
)
// generate finally blocks before the non-local return flag or the stack fixup pseudo instruction
val finallyInsertionPoint = if (isLocalReturn && jumpTarget == endLabel) insnNode else insnNode.previous
result.add(PointForExternalFinallyBlocks(finallyInsertionPoint, returnType, label, jumpTarget))
}
insnNode = insnNode.next
}
return result
}
private fun getInstructionToInsertFinallyBefore(nonLocalReturnOrJump: AbstractInsnNode, isLocal: Boolean): AbstractInsnNode {
return if (isLocal) nonLocalReturnOrJump else nonLocalReturnOrJump.previous
}
}
}
@@ -1,29 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.codegen.inline;
import org.jetbrains.annotations.NotNull;
public interface ReturnLabelOwner {
boolean isReturnFromMe(@NotNull String labelName);
ReturnLabelOwner SKIP_ALL = name -> false;
ReturnLabelOwner NOT_APPLICABLE = name -> {
throw new RuntimeException("This operation not applicable for current context");
};
}
@@ -64,7 +64,7 @@ interface SourceCompilerForInline {
curFinallyDepth: Int
): BaseExpressionCodegen
fun generateFinallyBlocksIfNeeded(finallyCodegen: BaseExpressionCodegen, returnType: Type, afterReturnLabel: Label)
fun generateFinallyBlocksIfNeeded(codegen: BaseExpressionCodegen, returnType: Type, afterReturnLabel: Label, target: Label?)
fun isCallInsideSameModuleAsDeclared(functionDescriptor: FunctionDescriptor): Boolean
@@ -74,7 +74,7 @@ interface SourceCompilerForInline {
val compilationContextFunctionDescriptor: FunctionDescriptor
fun getContextLabels(): Set<String>
fun getContextLabels(): Map<String, Label?>
fun reportSuspensionPointInsideMonitor(stackTraceElement: String)
}
@@ -311,9 +311,10 @@ class PsiSourceCompilerForInline(private val codegen: ExpressionCodegen, overrid
override fun hasFinallyBlocks() = codegen.hasFinallyBlocks()
override fun generateFinallyBlocksIfNeeded(finallyCodegen: BaseExpressionCodegen, returnType: Type, afterReturnLabel: Label) {
require(finallyCodegen is ExpressionCodegen)
finallyCodegen.generateFinallyBlocksIfNeeded(returnType, null, afterReturnLabel)
override fun generateFinallyBlocksIfNeeded(codegen: BaseExpressionCodegen, returnType: Type, afterReturnLabel: Label, target: Label?) {
// TODO use the target label for non-local break/continue
require(codegen is ExpressionCodegen)
codegen.generateFinallyBlocksIfNeeded(returnType, null, afterReturnLabel)
}
override fun createCodegenForExternalFinallyBlockGenerationOnNonLocalReturn(finallyNode: MethodNode, curFinallyDepth: Int) =
@@ -337,14 +338,15 @@ class PsiSourceCompilerForInline(private val codegen: ExpressionCodegen, overrid
override val compilationContextFunctionDescriptor
get() = codegen.getContext().functionDescriptor
override fun getContextLabels(): Set<String> {
override fun getContextLabels(): Map<String, Label?> {
val context = codegen.getContext()
val parentContext = context.parentContext
val descriptor = if (parentContext is ClosureContext && parentContext.originalSuspendLambdaDescriptor != null) {
parentContext.originalSuspendLambdaDescriptor!!
} else context.contextDescriptor
return InlineCodegen.getDeclarationLabels(DescriptorToSourceUtils.descriptorToDeclaration(descriptor), descriptor)
val labels = InlineCodegen.getDeclarationLabels(DescriptorToSourceUtils.descriptorToDeclaration(descriptor), descriptor)
return labels.associateWith { null } // TODO add break/continue labels
}
fun initializeInlineFunctionContext(functionDescriptor: FunctionDescriptor) {
@@ -84,9 +84,11 @@ private fun createSpecialEnumMethodBody(
Opcodes.INVOKESTATIC, ENUM_TYPE.internalName, "valueOf",
Type.getMethodDescriptor(ENUM_TYPE, JAVA_CLASS_TYPE, JAVA_STRING_TYPE), false
)
node.visitTypeInsn(Opcodes.CHECKCAST, ENUM_TYPE.internalName)
} else {
node.visitInsn(Opcodes.ICONST_0)
node.visitTypeInsn(Opcodes.ANEWARRAY, ENUM_TYPE.internalName)
node.visitTypeInsn(Opcodes.CHECKCAST, AsmUtil.getArrayType(ENUM_TYPE).internalName)
}
node.visitInsn(Opcodes.ARETURN)
node.visitMaxs(if (isValueOf) 3 else 2, if (isValueOf) 1 else 0)
@@ -37,17 +37,9 @@ class CapturedVarsOptimizationMethodTransformer : MethodTransformer() {
// Tracks proper usages of objects corresponding to captured variables.
//
// The 'kotlin.jvm.internal.Ref.*' instance can be replaced with a local variable,
// if all of the following conditions are satisfied:
// * It is created inside a current method.
// * The only permitted operations on it are:
// - store to a local variable
// - ALOAD, ASTORE
// - DUP, POP
// - GETFIELD <owner>.element, PUTFIELD <owner>.element
// * There's a corresponding local variable definition,
// and all ALOAD/ASTORE instructions operate on that particular local variable.
// * Its 'element' field is initialized at start of local variable visibility range.
// The 'kotlin.jvm.internal.Ref.*' instance can be replaced with a local variable, if
// * it is created inside a current method;
// * the only operations on it are ALOAD, ASTORE, DUP, POP, GETFIELD element, PUTFIELD element.
//
// Note that for code that doesn't create Ref objects explicitly these conditions are true,
// unless the Ref object escapes to a local class constructor (including local classes for lambdas).
@@ -58,18 +50,9 @@ class CapturedVarsOptimizationMethodTransformer : MethodTransformer() {
var initCallInsn: MethodInsnNode? = null
var localVar: LocalVariableNode? = null
var localVarIndex = -1
val astoreInsns: MutableCollection<VarInsnNode> = LinkedHashSet()
val aloadInsns: MutableCollection<VarInsnNode> = LinkedHashSet()
val stackInsns: MutableCollection<AbstractInsnNode> = LinkedHashSet()
val wrapperInsns: MutableCollection<AbstractInsnNode> = LinkedHashSet()
val getFieldInsns: MutableCollection<FieldInsnNode> = LinkedHashSet()
val putFieldInsns: MutableCollection<FieldInsnNode> = LinkedHashSet()
var cleanVarInstruction: VarInsnNode? = null
fun canRewrite(): Boolean =
!hazard &&
initCallInsn != null &&
localVar != null &&
localVarIndex >= 0
override fun onUseAsTainted() {
hazard = true
@@ -79,26 +62,29 @@ class CapturedVarsOptimizationMethodTransformer : MethodTransformer() {
private class Transformer(private val internalClassName: String, private val methodNode: MethodNode) {
private val refValues = ArrayList<CapturedVarDescriptor>()
private val refValuesByNewInsn = LinkedHashMap<TypeInsnNode, CapturedVarDescriptor>()
private val insns = methodNode.instructions.toArray()
private lateinit var frames: Array<out Frame<BasicValue>?>
val hasRewritableRefValues: Boolean
get() = refValues.isNotEmpty()
fun run() {
createRefValues()
if (!hasRewritableRefValues) return
if (refValues.isEmpty()) return
analyze()
if (!hasRewritableRefValues) return
val frames = analyze(internalClassName, methodNode, Interpreter())
trackPops(frames)
assignLocalVars(frames)
rewrite()
for (refValue in refValues) {
if (!refValue.hazard) {
rewriteRefValue(refValue)
}
}
methodNode.removeEmptyCatchBlocks()
methodNode.removeUnusedLocalVariables()
}
private fun AbstractInsnNode.getIndex() = methodNode.instructions.indexOf(this)
private fun createRefValues() {
for (insn in insns) {
for (insn in methodNode.instructions.asSequence()) {
if (insn.opcode == Opcodes.NEW && insn is TypeInsnNode) {
val type = Type.getObjectType(insn.desc)
if (AsmTypes.isSharedVarType(type)) {
@@ -113,19 +99,15 @@ class CapturedVarsOptimizationMethodTransformer : MethodTransformer() {
private inner class Interpreter : ReferenceTrackingInterpreter() {
override fun newOperation(insn: AbstractInsnNode): BasicValue =
refValuesByNewInsn[insn]?.let { descriptor ->
ProperTrackedReferenceValue(descriptor.refType, descriptor)
}
?: super.newOperation(insn)
refValuesByNewInsn[insn]?.let { ProperTrackedReferenceValue(it.refType, it) } ?: super.newOperation(insn)
override fun processRefValueUsage(value: TrackedReferenceValue, insn: AbstractInsnNode, position: Int) {
for (descriptor in value.descriptors) {
if (descriptor !is CapturedVarDescriptor) throw AssertionError("Unexpected descriptor: $descriptor")
when {
insn.opcode == Opcodes.ALOAD ->
descriptor.aloadInsns.add(insn as VarInsnNode)
insn.opcode == Opcodes.ASTORE ->
descriptor.astoreInsns.add(insn as VarInsnNode)
insn.opcode == Opcodes.DUP -> descriptor.wrapperInsns.add(insn)
insn.opcode == Opcodes.ALOAD -> descriptor.wrapperInsns.add(insn)
insn.opcode == Opcodes.ASTORE -> descriptor.wrapperInsns.add(insn)
insn.opcode == Opcodes.GETFIELD && insn is FieldInsnNode && insn.name == REF_ELEMENT_FIELD && position == 0 ->
descriptor.getFieldInsns.add(insn)
insn.opcode == Opcodes.PUTFIELD && insn is FieldInsnNode && insn.name == REF_ELEMENT_FIELD && position == 0 ->
@@ -135,32 +117,18 @@ class CapturedVarsOptimizationMethodTransformer : MethodTransformer() {
descriptor.hazard = true
else
descriptor.initCallInsn = insn
insn.opcode == Opcodes.DUP ->
descriptor.stackInsns.add(insn)
else ->
descriptor.hazard = true
else -> descriptor.hazard = true
}
}
}
}
private fun analyze() {
frames = MethodTransformer.analyze(internalClassName, methodNode, Interpreter())
trackPops()
assignLocalVars()
refValues.removeAll { !it.canRewrite() }
}
private fun trackPops() {
for (i in insns.indices) {
private fun trackPops(frames: Array<out Frame<BasicValue>?>) {
for ((i, insn) in methodNode.instructions.asSequence().withIndex()) {
val frame = frames[i] ?: continue
val insn = insns[i]
when (insn.opcode) {
Opcodes.POP -> {
frame.top()?.getCapturedVarOrNull()?.run { stackInsns.add(insn) }
frame.top()?.getCapturedVarOrNull()?.run { wrapperInsns.add(insn) }
}
Opcodes.POP2 -> {
val top = frame.top()
@@ -176,7 +144,7 @@ class CapturedVarsOptimizationMethodTransformer : MethodTransformer() {
private fun BasicValue.getCapturedVarOrNull() =
safeAs<ProperTrackedReferenceValue>()?.descriptor?.safeAs<CapturedVarDescriptor>()
private fun assignLocalVars() {
private fun assignLocalVars(frames: Array<out Frame<BasicValue>?>) {
for (localVar in methodNode.localVariables) {
val type = Type.getType(localVar.desc)
if (!AsmTypes.isSharedVarType(type)) continue
@@ -197,51 +165,20 @@ class CapturedVarsOptimizationMethodTransformer : MethodTransformer() {
for (refValue in refValues) {
if (refValue.hazard) continue
val localVar = refValue.localVar ?: continue
val oldVarIndex = localVar.index
if (refValue.valueType.size != 1) {
if (refValue.localVar == null || refValue.valueType.size != 1) {
refValue.localVarIndex = methodNode.maxLocals
methodNode.maxLocals += 2
localVar.index = refValue.localVarIndex
methodNode.maxLocals += refValue.valueType.size
} else {
refValue.localVarIndex = localVar.index
refValue.localVarIndex = refValue.localVar!!.index
}
val cleanInstructions = findCleanInstructions(refValue, oldVarIndex, methodNode.instructions)
if (cleanInstructions.size > 1) {
refValue.hazard = true
continue
}
refValue.cleanVarInstruction = cleanInstructions.firstOrNull()
}
}
private fun findCleanInstructions(refValue: CapturedVarDescriptor, oldVarIndex: Int, instructions: InsnList): List<VarInsnNode> {
return InsnSequence(instructions).filterIsInstance<VarInsnNode>().filter {
it.opcode == Opcodes.ASTORE && it.`var` == oldVarIndex
}.filter {
it.previous?.opcode == Opcodes.ACONST_NULL
}.filter {
val operationIndex = instructions.indexOf(it)
val localVariableNode = refValue.localVar!!
instructions.indexOf(localVariableNode.start) < operationIndex && operationIndex < instructions.indexOf(
localVariableNode.end
)
}.toList()
}
private fun rewrite() {
for (refValue in refValues) {
if (!refValue.canRewrite()) continue
rewriteRefValue(refValue)
private fun LocalVariableNode.findCleanInstructions() =
InsnSequence(methodNode.instructions).dropWhile { it != start }.takeWhile { it != end }.filter {
it is VarInsnNode && it.opcode == Opcodes.ASTORE && it.`var` == index && it.previous?.opcode == Opcodes.ACONST_NULL
}
methodNode.removeEmptyCatchBlocks()
methodNode.removeUnusedLocalVariables()
}
// Be careful to not remove instructions that are the only instruction for a line number. That will
// break debugging. If the previous instruction is a line number and the following instruction is
// a label followed by a line number, insert a nop instead of deleting the instruction.
@@ -255,34 +192,38 @@ class CapturedVarsOptimizationMethodTransformer : MethodTransformer() {
private fun rewriteRefValue(capturedVar: CapturedVarDescriptor) {
methodNode.instructions.run {
val localVar = capturedVar.localVar!!
localVar.signature = null
localVar.desc = capturedVar.valueType.descriptor
val loadOpcode = capturedVar.valueType.getOpcode(Opcodes.ILOAD)
val storeOpcode = capturedVar.valueType.getOpcode(Opcodes.ISTORE)
if (capturedVar.putFieldInsns.none { it.getIndex() < localVar.start.getIndex() }) {
// variable needs to be initialized before its live range can begin
insertBefore(capturedVar.newInsn, InsnNode(AsmUtil.defaultValueOpcode(capturedVar.valueType)))
insertBefore(capturedVar.newInsn, VarInsnNode(storeOpcode, capturedVar.localVarIndex))
val localVar = capturedVar.localVar
if (localVar != null) {
if (capturedVar.putFieldInsns.none { it.getIndex() < localVar.start.getIndex() }) {
// variable needs to be initialized before its live range can begin
insertBefore(capturedVar.newInsn, InsnNode(AsmUtil.defaultValueOpcode(capturedVar.valueType)))
insertBefore(capturedVar.newInsn, VarInsnNode(storeOpcode, capturedVar.localVarIndex))
}
for (insn in localVar.findCleanInstructions()) {
// after visiting block codegen tries to delete all allocated references:
// see ExpressionCodegen.addLeaveTaskToRemoveLocalVariableFromFrameMap
if (storeOpcode == Opcodes.ASTORE) {
set(insn.previous, InsnNode(AsmUtil.defaultValueOpcode(capturedVar.valueType)))
} else {
remove(insn.previous)
remove(insn)
}
}
localVar.index = capturedVar.localVarIndex
localVar.desc = capturedVar.valueType.descriptor
localVar.signature = null
}
remove(capturedVar.newInsn)
remove(capturedVar.initCallInsn!!)
capturedVar.stackInsns.forEach { removeOrReplaceByNop(it) }
capturedVar.aloadInsns.forEach { removeOrReplaceByNop(it) }
capturedVar.astoreInsns.forEach { removeOrReplaceByNop(it) }
capturedVar.wrapperInsns.forEach { removeOrReplaceByNop(it) }
capturedVar.getFieldInsns.forEach { set(it, VarInsnNode(loadOpcode, capturedVar.localVarIndex)) }
capturedVar.putFieldInsns.forEach { set(it, VarInsnNode(storeOpcode, capturedVar.localVarIndex)) }
//after visiting block codegen tries to delete all allocated references:
// see ExpressionCodegen.addLeaveTaskToRemoveLocalVariableFromFrameMap
capturedVar.cleanVarInstruction?.let {
remove(it.previous)
remove(it)
}
}
}
@@ -28,7 +28,8 @@ import org.jetbrains.org.objectweb.asm.tree.TypeInsnNode
class RedundantCheckCastEliminationMethodTransformer : MethodTransformer() {
override fun transform(internalClassName: String, methodNode: MethodNode) {
val insns = methodNode.instructions.toArray()
if (!insns.any { it.opcode == Opcodes.CHECKCAST }) return
if (!insns.any { it.opcode == Opcodes.CHECKCAST}) return
if (insns.any { ReifiedTypeInliner.isOperationReifiedMarker(it) }) return
val redundantCheckCasts = ArrayList<TypeInsnNode>()
@@ -36,7 +37,6 @@ class RedundantCheckCastEliminationMethodTransformer : MethodTransformer() {
for (i in insns.indices) {
val valueType = frames[i]?.top()?.type ?: continue
val insn = insns[i]
if (ReifiedTypeInliner.isOperationReifiedMarker(insn.previous)) continue
if (insn is TypeInsnNode) {
val insnType = Type.getObjectType(insn.desc)
@@ -208,11 +208,21 @@ class GenerationState private constructor(
else JvmStringConcat.INLINE
val samConversionsScheme = run {
val fromConfig = configuration.get(JVMConfigurationKeys.SAM_CONVERSIONS) ?: JvmSamConversions.DEFAULT
val fromConfig = configuration.get(JVMConfigurationKeys.SAM_CONVERSIONS)
?: JvmClosureGenerationScheme.DEFAULT
if (target >= fromConfig.minJvmTarget)
fromConfig
else
JvmSamConversions.DEFAULT
JvmClosureGenerationScheme.DEFAULT
}
val lambdasScheme = run {
val fromConfig = configuration.get(JVMConfigurationKeys.LAMBDAS)
?: JvmClosureGenerationScheme.DEFAULT
if (target >= fromConfig.minJvmTarget)
fromConfig
else
JvmClosureGenerationScheme.DEFAULT
}
val moduleName: String = moduleName ?: JvmCodegenUtil.getModuleName(module)
+1 -1
View File
@@ -86,7 +86,7 @@ if (kotlinBuildProperties.isInJpsBuildIdeaSync) {
idea {
this.module.generatedSourceDirs.add(generationRoot)
}
} else {
} else if (!kotlinBuildProperties.useFir && !kotlinBuildProperties.disableWerror) {
allprojects {
tasks.withType<KotlinCompile<*>> {
if (path !in tasksWithWarnings) {
-1
View File
@@ -30,7 +30,6 @@ dependencies {
compile(project(":compiler:fir:checkers"))
compile(project(":kotlin-util-klib"))
compile(project(":kotlin-util-io"))
compile(project(":compiler:ir.serialization.common"))
// TODO: as soon as cli-jvm is extracted out of this module, move this dependency there
compileOnly(project(":compiler:ir.tree.impl"))
@@ -351,6 +351,12 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
)
var inferenceCompatibility: Boolean by FreezableVar(false)
@Argument(
value = "-Xsuppress-version-warnings",
description = "Suppress warnings about outdated, inconsistent or experimental language or API versions"
)
var suppressVersionWarnings: Boolean by FreezableVar(false)
open fun configureAnalysisFlags(collector: MessageCollector): MutableMap<AnalysisFlag<*>, Any> {
return HashMap<AnalysisFlag<*>, Any>().apply {
put(AnalysisFlags.skipMetadataVersionCheck, skipMetadataVersionCheck)
@@ -496,9 +502,6 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
val apiVersion = parseVersion(collector, apiVersion, "API") ?: languageVersion
checkApiVersionIsNotGreaterThenLanguageVersion(languageVersion, apiVersion, collector)
checkLanguageVersionIsStable(languageVersion, collector)
checkOutdatedVersions(languageVersion, apiVersion, collector)
checkProgressiveMode(languageVersion, collector)
val languageVersionSettings = LanguageVersionSettingsImpl(
languageVersion,
@@ -507,7 +510,13 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
configureLanguageFeatures(collector)
)
checkIrSupport(languageVersionSettings, collector)
if (!suppressVersionWarnings) {
checkLanguageVersionIsStable(languageVersion, collector)
checkOutdatedVersions(languageVersion, apiVersion, collector)
checkProgressiveMode(languageVersion, collector)
checkIrSupport(languageVersionSettings, collector)
}
return languageVersionSettings
}
@@ -71,7 +71,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
@Argument(
value = "-jvm-target",
valueDescription = "<version>",
description = "Target version of the generated JVM bytecode (1.6, 1.8, 9, 10, 11, 12, 13, 14 or 15), default is 1.6"
description = "Target version of the generated JVM bytecode (1.6 (DEPRECATED), 1.8, 9, 10, 11, 12, 13, 14 or 15), default is 1.8"
)
var jvmTarget: String? by NullableStringFreezableVar(JvmTarget.DEFAULT.description)
@@ -355,10 +355,10 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
@Argument(
value = "-Xstring-concat",
valueDescription = "{indy-with-constants|indy|inline}",
description = """Switch a way in which string concatenation is performed.
-Xstring-concat=indy-with-constants Performs string concatenation via `invokedynamic` 'makeConcatWithConstants'. Works only with `-jvm-target 9` or greater
-Xstring-concat=indy Performs string concatenation via `invokedynamic` 'makeConcat'. Works only with `-jvm-target 9` or greater
-Xstring-concat=inline Performs string concatenation via `StringBuilder`"""
description = """Select code generation scheme for string concatenation.
-Xstring-concat=indy-with-constants Concatenate strings using `invokedynamic` `makeConcatWithConstants`. Requires `-jvm-target 9` or greater.
-Xstring-concat=indy Concatenate strings using `invokedynamic` `makeConcat`. Requires `-jvm-target 9` or greater.
-Xstring-concat=inline Concatenate strings using `StringBuilder`"""
)
var stringConcat: String? by NullableStringFreezableVar(JvmStringConcat.INLINE.description)
@@ -366,10 +366,20 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
value = "-Xsam-conversions",
valueDescription = "{class|indy}",
description = """Select code generation scheme for SAM conversions.
-Xsam-conversions=indy Generate SAM conversions using `invokedynamic` with `LambdaMetafactory.metafactory`. Requires `-jvm-target 8` or greater.
-Xsam-conversions=indy Generate SAM conversions using `invokedynamic` with `LambdaMetafactory.metafactory`. Requires `-jvm-target 1.8` or greater.
-Xsam-conversions=class Generate SAM conversions as explicit classes"""
)
var samConversions: String? by NullableStringFreezableVar(JvmSamConversions.CLASS.description)
var samConversions: String? by NullableStringFreezableVar(null)
@Argument(
value = "-Xlambdas",
valueDescription = "{class|indy}",
description = """Select code generation scheme for lambdas.
-Xlambdas=indy Generate lambdas using `invokedynamic` with `LambdaMetafactory.metafactory`. Requires `-jvm-target 1.8` or greater.
Lambda objects created using `LambdaMetafactory.metafactory` will have different `toString()`.
-Xlambdas=class Generate lambdas as explicit classes"""
)
var lambdas: String? by NullableStringFreezableVar(null)
@Argument(
value = "-Xklib",
@@ -438,6 +448,12 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
)
var enableJvmPreview: Boolean by FreezableVar(false)
@Argument(
value = "-Xsuppress-deprecated-jvm-target-warning",
description = "Suppress deprecation warning about deprecated JVM target versions"
)
var suppressDeprecatedJvmTargetWarning: Boolean by FreezableVar(false)
override fun configureAnalysisFlags(collector: MessageCollector): MutableMap<AnalysisFlag<*>, Any> {
val result = super.configureAnalysisFlags(collector)
result[JvmAnalysisFlags.strictMetadataVersionSemantics] = strictMetadataVersionSemantics
@@ -192,21 +192,17 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
require(outputFile.extension == KLIB_FILE_EXTENSION) { "Please set up .klib file as output" }
}
try {
generateKLib(
project = config.project,
files = sourcesFiles,
analyzer = AnalyzerWithCompilerReport(config.configuration),
configuration = config.configuration,
allDependencies = resolvedLibraries,
friendDependencies = friendDependencies,
irFactory = PersistentIrFactory,
outputKlibPath = outputFile.path,
nopack = arguments.irProduceKlibDir
)
} catch (e: JsIrCompilationError) {
return COMPILATION_ERROR
}
generateKLib(
project = config.project,
files = sourcesFiles,
analyzer = AnalyzerWithCompilerReport(config.configuration),
configuration = config.configuration,
allDependencies = resolvedLibraries,
friendDependencies = friendDependencies,
irFactory = PersistentIrFactory,
outputKlibPath = outputFile.path,
nopack = arguments.irProduceKlibDir
)
}
if (arguments.irProduceJs) {
@@ -252,26 +248,22 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
return OK
}
val compiledModule = try {
compile(
projectJs,
mainModule,
AnalyzerWithCompilerReport(config.configuration),
config.configuration,
phaseConfig,
allDependencies = resolvedLibraries,
friendDependencies = friendDependencies,
mainArguments = mainCallArguments,
generateFullJs = !arguments.irDce,
generateDceJs = arguments.irDce,
dceDriven = arguments.irDceDriven,
multiModule = arguments.irPerModule,
relativeRequirePath = true,
propertyLazyInitialization = arguments.irPropertyLazyInitialization,
)
} catch (e: JsIrCompilationError) {
return COMPILATION_ERROR
}
val compiledModule = compile(
projectJs,
mainModule,
AnalyzerWithCompilerReport(config.configuration),
config.configuration,
phaseConfig,
allDependencies = resolvedLibraries,
friendDependencies = friendDependencies,
mainArguments = mainCallArguments,
generateFullJs = !arguments.irDce,
generateDceJs = arguments.irDce,
dceDriven = arguments.irDceDriven,
multiModule = arguments.irPerModule,
relativeRequirePath = true,
propertyLazyInitialization = arguments.irPropertyLazyInitialization,
)
val jsCode = if (arguments.irDce && !arguments.irDceDriven) compiledModule.dceJsCode!! else compiledModule.jsCode!!
outputFile.writeText(jsCode.mainModule)
@@ -76,17 +76,23 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
messageCollector.report(severity, message)
}
val dceResult = DeadCodeElimination.run(files, includedDeclarations, logConsumer)
val dceResult = DeadCodeElimination.run(
files,
includedDeclarations,
arguments.printReachabilityInfo,
logConsumer
)
if (dceResult.status == DeadCodeEliminationStatus.FAILED) return ExitCode.COMPILATION_ERROR
val nodes = dceResult.reachableNodes.filterTo(mutableSetOf()) { it.reachable }
val reachabilitySeverity = if (arguments.printReachabilityInfo) CompilerMessageSeverity.INFO else CompilerMessageSeverity.LOGGING
messageCollector.report(reachabilitySeverity, "")
for (node in nodes.extractRoots()) {
printTree(
node, { messageCollector.report(reachabilitySeverity, it) },
printNestedMembers = false, showLocations = true
)
if (arguments.printReachabilityInfo) {
val reachabilitySeverity = CompilerMessageSeverity.INFO
messageCollector.report(reachabilitySeverity, "")
for (node in dceResult.reachableNodes.extractReachableRoots(dceResult.context!!)) {
printTree(
node, { messageCollector.report(reachabilitySeverity, it) },
printNestedMembers = false, showLocations = true
)
}
}
return ExitCode.OK
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.ir.util.IrMessageLogger
import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
import org.jetbrains.kotlin.progress.CompilationCanceledException
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
@@ -39,7 +40,7 @@ import org.jetbrains.kotlin.utils.KotlinPaths
import org.jetbrains.kotlin.utils.PathUtil
import java.io.File
import java.io.PrintStream
import java.util.ArrayList
import java.util.*
abstract class CLICompiler<A : CommonCompilerArguments> : CLITool<A>() {
@@ -69,6 +70,8 @@ abstract class CLICompiler<A : CommonCompilerArguments> : CLITool<A>() {
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, it)
}
configuration.put(IrMessageLogger.IR_MESSAGE_LOGGER, IrMessageCollector(collector))
configuration.put(CLIConfigurationKeys.PERF_MANAGER, performanceManager)
try {
setupCommonArguments(configuration, arguments)
@@ -0,0 +1,30 @@
/*
* 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.cli.common.messages
import org.jetbrains.kotlin.ir.util.IrMessageLogger
class IrMessageCollector(private val messageCollector: MessageCollector) : IrMessageLogger {
override fun report(severity: IrMessageLogger.Severity, message: String, location: IrMessageLogger.Location?) {
messageCollector.report(severityToCLISeverity(severity), message, locationToCLILocation(location))
}
companion object {
private fun severityToCLISeverity(severity: IrMessageLogger.Severity): CompilerMessageSeverity {
return when (severity) {
IrMessageLogger.Severity.INFO -> CompilerMessageSeverity.INFO
IrMessageLogger.Severity.WARNING -> CompilerMessageSeverity.WARNING
IrMessageLogger.Severity.ERROR -> CompilerMessageSeverity.ERROR
}
}
private fun locationToCLILocation(location: IrMessageLogger.Location?): CompilerMessageLocation? {
return location?.run {
CompilerMessageLocation.Companion.create(filePath, line, column, null)
}
}
}
}
@@ -12,10 +12,7 @@ import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.search.PsiSearchScopeUtil
import com.intellij.util.SmartList
import org.jetbrains.kotlin.asJava.KotlinAsJavaSupport
import org.jetbrains.kotlin.asJava.classes.KtLightClass
import org.jetbrains.kotlin.asJava.classes.KtLightClassForFacade
import org.jetbrains.kotlin.asJava.classes.KtLightClassForScript
import org.jetbrains.kotlin.asJava.classes.KtLightClassForSourceDeclaration
import org.jetbrains.kotlin.asJava.classes.*
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
import org.jetbrains.kotlin.fileClasses.javaFileFacadeFqName
import org.jetbrains.kotlin.load.java.components.FilesByFacadeFqNameIndexer
@@ -81,6 +78,8 @@ class CliKotlinAsJavaSupport(
}.orEmpty()
}
override fun getFakeLightClass(classOrObject: KtClassOrObject): KtFakeLightClass =
KtDescriptorBasedFakeLightClass(classOrObject)
override fun findClassOrObjectDeclarationsInPackage(
packageFqName: FqName, searchScope: GlobalSearchScope
@@ -23,11 +23,17 @@ import org.jetbrains.kotlin.asJava.builder.InvalidLightClassDataHolder
import org.jetbrains.kotlin.asJava.builder.LightClassConstructionContext
import org.jetbrains.kotlin.asJava.builder.LightClassDataHolder
import org.jetbrains.kotlin.asJava.builder.LightClassDataHolderImpl
import org.jetbrains.kotlin.asJava.classes.*
import org.jetbrains.kotlin.asJava.classes.KtUltraLightSupport
import org.jetbrains.kotlin.asJava.classes.cleanFromAnonymousTypes
import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.asJava.classes.tryGetPredefinedName
import org.jetbrains.kotlin.codegen.ClassBuilderMode
import org.jetbrains.kotlin.codegen.JvmCodegenUtil
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.config.JvmAnalysisFlags
import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.load.java.components.JavaDeprecationSettings
import org.jetbrains.kotlin.name.Name
@@ -57,7 +63,8 @@ class CliLightClassGenerationSupport(
private class CliLightClassSupport(
private val project: Project,
override val languageVersionSettings: LanguageVersionSettings
override val languageVersionSettings: LanguageVersionSettings,
private val jvmTarget: JvmTarget
) : KtUltraLightSupport {
// This is the way to untie CliLightClassSupport and CliLightClassGenerationSupport to prevent descriptors leak
@@ -88,7 +95,7 @@ class CliLightClassGenerationSupport(
moduleName,
languageVersionSettings,
useOldInlineClassesManglingScheme = false,
jvmTarget = JvmTarget.JVM_1_8,
jvmTarget = jvmTarget,
typePreprocessor = KotlinType::cleanFromAnonymousTypes,
namePreprocessor = ::tryGetPredefinedName
)
@@ -96,7 +103,7 @@ class CliLightClassGenerationSupport(
}
private val ultraLightSupport: KtUltraLightSupport by lazyPub {
CliLightClassSupport(project, traceHolder.languageVersionSettings)
CliLightClassSupport(project, traceHolder.languageVersionSettings, traceHolder.jvmTarget)
}
override fun getUltraLightClassSupport(element: KtElement): KtUltraLightSupport {
@@ -129,7 +136,9 @@ class CliLightClassGenerationSupport(
}
private fun getContext(): LightClassConstructionContext =
LightClassConstructionContext(traceHolder.bindingContext, traceHolder.module)
LightClassConstructionContext(
traceHolder.bindingContext, traceHolder.module, null /* TODO: traceHolder.languageVersionSettings? */, traceHolder.jvmTarget
)
override fun resolveToDescriptor(declaration: KtDeclaration): DeclarationDescriptor? {
return traceHolder.bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration)
@@ -140,4 +149,4 @@ class CliLightClassGenerationSupport(
override fun analyzeAnnotation(element: KtAnnotationEntry) = traceHolder.bindingContext.get(BindingContext.ANNOTATION, element)
override fun analyzeWithContent(element: KtClassOrObject) = traceHolder.bindingContext
}
}
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.cli.jvm.compiler
import org.jetbrains.annotations.TestOnly
import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.psi.KtDeclaration
@@ -13,30 +14,32 @@ import org.jetbrains.kotlin.psi.KtPsiUtil
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.BindingTraceContext
import org.jetbrains.kotlin.resolve.CodeAnalyzerInitializer
import org.jetbrains.kotlin.resolve.jvm.JvmCodeAnalyzerInitializer
import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer
import org.jetbrains.kotlin.util.slicedMap.ReadOnlySlice
import org.jetbrains.kotlin.util.slicedMap.WritableSlice
import kotlin.properties.Delegates
class CliTraceHolder : CodeAnalyzerInitializer {
var bindingContext: BindingContext by Delegates.notNull()
class CliTraceHolder : JvmCodeAnalyzerInitializer() {
lateinit var bindingContext: BindingContext
private set
var module: ModuleDescriptor by Delegates.notNull()
lateinit var module: ModuleDescriptor
private set
var languageVersionSettings: LanguageVersionSettings by Delegates.notNull()
lateinit var languageVersionSettings: LanguageVersionSettings
private set
lateinit var jvmTarget: JvmTarget
private set
override fun initialize(
trace: BindingTrace,
module: ModuleDescriptor,
codeAnalyzer: KotlinCodeAnalyzer,
languageVersionSettings: LanguageVersionSettings
languageVersionSettings: LanguageVersionSettings,
jvmTarget: JvmTarget
) {
this.bindingContext = trace.bindingContext
this.module = module
this.languageVersionSettings = languageVersionSettings
this.jvmTarget = jvmTarget
if (trace !is CliBindingTrace) {
throw IllegalArgumentException("Shared trace is expected to be subclass of ${CliBindingTrace::class.java.simpleName} class")
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
import org.jetbrains.kotlin.cli.common.modules.ModuleChunk;
import org.jetbrains.kotlin.cli.common.modules.ModuleXmlParser;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.serialization.deserialization.builtins.BuiltInSerializerProtocol;
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
import org.jetbrains.kotlin.utils.PathUtil;
@@ -60,6 +61,7 @@ public class CompileEnvironmentUtil {
OutputStream fos,
@Nullable FqName mainClass,
boolean includeRuntime,
boolean noReflect,
boolean resetJarTimestamps
) {
try {
@@ -89,6 +91,9 @@ public class CompileEnvironmentUtil {
}
if (includeRuntime) {
writeRuntimeToJar(stream, resetJarTimestamps);
if (!noReflect) {
writeReflectToJar(stream, resetJarTimestamps);
}
}
stream.finish();
}
@@ -98,12 +103,12 @@ public class CompileEnvironmentUtil {
}
public static void writeToJar(
File jarPath, boolean jarRuntime, boolean resetJarTimestamps, FqName mainClass, OutputFileCollection outputFiles
File jarPath, boolean jarRuntime, boolean noReflect, boolean resetJarTimestamps, FqName mainClass, OutputFileCollection outputFiles
) {
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream(jarPath);
doWriteToJar(outputFiles, outputStream, mainClass, jarRuntime, resetJarTimestamps);
doWriteToJar(outputFiles, outputStream, mainClass, jarRuntime, noReflect, resetJarTimestamps);
outputStream.close();
}
catch (FileNotFoundException e) {
@@ -125,13 +130,22 @@ public class CompileEnvironmentUtil {
copyJarImpl(stream, stdlibPath, resetJarTimestamps);
}
private static void writeReflectToJar(JarOutputStream stream, boolean resetJarTimestamps) throws IOException {
File reflectPath = PathUtil.getKotlinPathsForCompiler().getReflectPath();
if (!reflectPath.exists()) {
throw new CompileEnvironmentException("Couldn't find kotlin-reflect at " + reflectPath);
}
copyJarImpl(stream, reflectPath, resetJarTimestamps);
}
private static void copyJarImpl(JarOutputStream stream, File jarPath, boolean resetJarTimestamps) throws IOException {
try (JarInputStream jis = new JarInputStream(new FileInputStream(jarPath))) {
while (true) {
JarEntry e = jis.getNextJarEntry();
if (e == null) break;
if (!FileUtilRt.extensionEquals(e.getName(), "class") ||
if ((!FileUtilRt.extensionEquals(e.getName(), "class") &&
!FileUtilRt.extensionEquals(e.getName(), BuiltInSerializerProtocol.BUILTINS_FILE_EXTENSION)) ||
StringsKt.substringAfterLast(e.getName(), "/", e.getName()).equals("module-info.class")) {
continue;
}
@@ -19,10 +19,11 @@ package org.jetbrains.kotlin.cli.jvm.compiler
import com.intellij.core.JavaCoreProjectEnvironment
import com.intellij.openapi.Disposable
import com.intellij.psi.PsiManager
import org.jetbrains.kotlin.resolve.jvm.KotlinCliJavaFileManager
open class KotlinCoreProjectEnvironment(
disposable: Disposable,
applicationEnvironment: KotlinCoreApplicationEnvironment
) : JavaCoreProjectEnvironment(disposable, applicationEnvironment) {
override fun createCoreFileManager() = KotlinCliJavaFileManagerImpl(PsiManager.getInstance(project))
override fun createCoreFileManager(): KotlinCliJavaFileManager = KotlinCliJavaFileManagerImpl(PsiManager.getInstance(project))
}
@@ -86,8 +86,9 @@ object KotlinToJVMBytecodeCompiler {
val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
if (jarPath != null) {
val includeRuntime = configuration.get(JVMConfigurationKeys.INCLUDE_RUNTIME, false)
val noReflect = configuration.get(JVMConfigurationKeys.NO_REFLECT, false)
val resetJarTimestamps = !configuration.get(JVMConfigurationKeys.NO_RESET_JAR_TIMESTAMPS, false)
CompileEnvironmentUtil.writeToJar(jarPath, includeRuntime, resetJarTimestamps, mainClassFqName, outputFiles)
CompileEnvironmentUtil.writeToJar(jarPath, includeRuntime, noReflect, resetJarTimestamps, mainClassFqName, outputFiles)
if (reportOutputFiles) {
val message = OutputMessageUtil.formatOutputMessage(outputFiles.asList().flatMap { it.sourceFiles }.distinct(), jarPath)
messageCollector.report(OUTPUT, message)
@@ -21,6 +21,7 @@ import java.io.File
fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArguments) {
put(JVMConfigurationKeys.INCLUDE_RUNTIME, arguments.includeRuntime)
put(JVMConfigurationKeys.NO_REFLECT, arguments.noReflect)
putIfNotNull(JVMConfigurationKeys.FRIEND_PATHS, arguments.friendPaths?.asList())
@@ -28,6 +29,12 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu
val jvmTarget = JvmTarget.fromString(arguments.jvmTarget!!)
if (jvmTarget != null) {
put(JVMConfigurationKeys.JVM_TARGET, jvmTarget)
if (jvmTarget == JvmTarget.JVM_1_6 && !arguments.suppressDeprecatedJvmTargetWarning) {
messageCollector.report(
STRONG_WARNING,
"JVM target 1.6 is deprecated and will be removed in a future release. Please migrate to JVM target 1.8 or above"
)
}
} else {
messageCollector.report(
ERROR, "Unknown JVM target version: ${arguments.jvmTarget}\n" +
@@ -65,27 +72,37 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu
}
}
if (arguments.samConversions != null) {
val samConversions = JvmSamConversions.fromString(arguments.samConversions)
if (samConversions != null) {
put(JVMConfigurationKeys.SAM_CONVERSIONS, samConversions)
if (jvmTarget < samConversions.minJvmTarget) {
handleClosureGenerationSchemeArgument("-Xsam-conversions", arguments.samConversions, JVMConfigurationKeys.SAM_CONVERSIONS, jvmTarget)
handleClosureGenerationSchemeArgument("-Xlambdas", arguments.lambdas, JVMConfigurationKeys.LAMBDAS, jvmTarget)
addAll(JVMConfigurationKeys.ADDITIONAL_JAVA_MODULES, arguments.additionalJavaModules?.asList())
}
private fun CompilerConfiguration.handleClosureGenerationSchemeArgument(
flag: String,
value: String?,
key: CompilerConfigurationKey<JvmClosureGenerationScheme>,
jvmTarget: JvmTarget
) {
if (value != null) {
val parsedValue = JvmClosureGenerationScheme.fromString(value)
if (parsedValue != null) {
put(key, parsedValue)
if (jvmTarget < parsedValue.minJvmTarget) {
messageCollector.report(
WARNING,
"`-Xsam-conversions=${arguments.samConversions}` requires JVM target at least " +
"${samConversions.minJvmTarget.description} and is ignored."
"`$flag=$value` requires JVM target at least " +
"${parsedValue.minJvmTarget.description} and is ignored."
)
}
} else {
messageCollector.report(
ERROR,
"Unknown `-Xsam-conversions` argument: ${arguments.samConversions}\n" +
"Supported arguments: ${JvmSamConversions.values().joinToString { it.description }}"
"Unknown `$flag` argument: ${value}\n." +
"Supported arguments: ${JvmClosureGenerationScheme.values().joinToString { it.description }}"
)
}
}
addAll(JVMConfigurationKeys.ADDITIONAL_JAVA_MODULES, arguments.additionalJavaModules?.asList())
}
fun CompilerConfiguration.configureJdkHome(arguments: K2JVMCompilerArguments): Boolean {
@@ -114,9 +114,12 @@ public class JVMConfigurationKeys {
public static final CompilerConfigurationKey<JvmStringConcat> STRING_CONCAT =
CompilerConfigurationKey.create("Specifies string concatenation scheme");
public static final CompilerConfigurationKey<JvmSamConversions> SAM_CONVERSIONS =
public static final CompilerConfigurationKey<JvmClosureGenerationScheme> SAM_CONVERSIONS =
CompilerConfigurationKey.create("SAM conversions code generation scheme");
public static final CompilerConfigurationKey<JvmClosureGenerationScheme> LAMBDAS =
CompilerConfigurationKey.create("Lambdas code generation scheme");
public static final CompilerConfigurationKey<List<String>> KLIB_PATHS =
CompilerConfigurationKey.create("Paths to .klib libraries");
@@ -146,4 +149,7 @@ public class JVMConfigurationKeys {
public static final CompilerConfigurationKey<Boolean> ENABLE_JVM_PREVIEW =
CompilerConfigurationKey.create("Enable Java language preview features");
public static final CompilerConfigurationKey<Boolean> NO_REFLECT =
CompilerConfigurationKey.create("Don't automatically include kotlin-reflect.jar into the output if the output is a jar");
}
@@ -5,7 +5,7 @@
package org.jetbrains.kotlin.config
enum class JvmSamConversions(
enum class JvmClosureGenerationScheme(
val description: String,
val minJvmTarget: JvmTarget
) {
@@ -36,7 +36,7 @@ enum class JvmTarget(
companion object {
@JvmField
val DEFAULT = JVM_1_6
val DEFAULT = JVM_1_8
@JvmStatic
fun fromString(string: String) = values().find { it.description == string }
+1 -12
View File
@@ -24,10 +24,7 @@ dependencies {
testApi(project(":compiler:fir:entrypoint"))
testApi(project(":compiler:frontend"))
testApi(platform("org.junit:junit-bom:5.7.0"))
testApi("org.junit.jupiter:junit-jupiter")
testApi("org.junit.platform:junit-platform-commons:1.7.0")
testApi("org.junit.platform:junit-platform-launcher:1.7.0")
testApiJUnit5()
testCompileOnly(project(":kotlin-reflect-api"))
testRuntimeOnly(project(":kotlin-reflect"))
@@ -35,14 +32,6 @@ dependencies {
testRuntimeOnly(project(":compiler:fir:fir2ir:jvm-backend"))
testImplementation(intellijCoreDep()) { includeJars("intellij-core") }
testImplementation(intellijDep()) {
// This dependency is needed only for FileComparisonFailure
includeJars("idea_rt", rootProject = rootProject)
isTransitive = false
}
// This is needed only for using FileComparisonFailure, which relies on JUnit 3 classes
testRuntimeOnly(commonDep("junit:junit"))
testRuntimeOnly(intellijDep()) {
includeJars(
"jps-model",
@@ -54,6 +54,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
runTest("compiler/fir/analysis-tests/testData/resolve/cast.kt");
}
@TestMetadata("catchParameter.kt")
public void testCatchParameter() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/catchParameter.kt");
}
@TestMetadata("companion.kt")
public void testCompanion() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/companion.kt");
@@ -414,6 +419,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
runTest("compiler/fir/analysis-tests/testData/resolve/syntheticsVsNormalProperties.kt");
}
@TestMetadata("throwableSubclass.kt")
public void testThrowableSubclass() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/throwableSubclass.kt");
}
@TestMetadata("treeSet.kt")
public void testTreeSet() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/treeSet.kt");
@@ -3098,6 +3108,39 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
}
}
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/suppress")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Suppress extends AbstractLazyBodyIsNotTouchedTilContractsPhaseTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInSuppress() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/suppress"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
}
@TestMetadata("allWarnings.kt")
public void testAllWarnings() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/suppress/allWarnings.kt");
}
@TestMetadata("multipleWarnings.kt")
public void testMultipleWarnings() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/suppress/multipleWarnings.kt");
}
@TestMetadata("singleError.kt")
public void testSingleError() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/suppress/singleError.kt");
}
@TestMetadata("singleWarning.kt")
public void testSingleWarning() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/suppress/singleWarning.kt");
}
}
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/types")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -0,0 +1,41 @@
FILE: catchParameter.kt
public final typealias StringType = R|kotlin/String|
public final fun <T : R|kotlin/Throwable|> test(): R|kotlin/Unit| {
try {
}
catch (e: R|kotlin/NullPointerException| = R|java/lang/NullPointerException.NullPointerException|()) {
}
try {
}
catch (e: R|T|) {
}
try {
}
catch (e: R|() -> kotlin/Int|) {
}
try {
}
catch (e: R|StringType|) {
}
try {
}
catch (e: R|kotlin/Int| = Int(5)) {
}
try {
}
catch (e: R|kotlin/Throwable|) {
}
}
public final inline fun <reified T> anotherTest(): R|kotlin/Unit| {
try {
}
catch (e: R|T|) {
}
}
@@ -0,0 +1,23 @@
typealias StringType = String
fun <T : Throwable> test() {
try {
} catch (<!CATCH_PARAMETER_WITH_DEFAULT_VALUE!>e: NullPointerException = NullPointerException()<!>) {
}
try {} catch (<!TYPE_PARAMETER_IN_CATCH_CLAUSE!>e: T<!>) {}
try {} catch (<!TYPE_MISMATCH!>e: () -> Int<!>) {}
try {} catch (<!TYPE_MISMATCH!>e: StringType<!>) {}
try {} catch (<!CATCH_PARAMETER_WITH_DEFAULT_VALUE, TYPE_MISMATCH!>e: Int = 5<!>) {}
try {} catch (e: Throwable) {}
}
inline fun <reified T> anotherTest() {
try {} catch (<!REIFIED_TYPE_IN_CATCH_CLAUSE, TYPE_MISMATCH!>e: T<!>) {}
}
@@ -18,37 +18,37 @@ typealias A1<K> = None<K>
typealias A2<K> = None<in K>
typealias A3<K> = None<out K>
typealias A4<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>in K<!>> = None<K>
typealias A5<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>in K<!>> = None<in K>
typealias A6<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>in K<!>> = None<out K>
typealias A4<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>in<!> K> = None<K>
typealias A5<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>in<!> K> = None<in K>
typealias A6<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>in<!> K> = None<out K>
typealias A7<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>out K<!>> = None<K>
typealias A8<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>out K<!>> = None<in K>
typealias A9<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>out K<!>> = None<out K>
typealias A7<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>out<!> K> = None<K>
typealias A8<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>out<!> K> = None<in K>
typealias A9<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>out<!> K> = None<out K>
typealias A10<K> = In<K>
typealias A11<K> = In<in K>
typealias A12<K> = <!CONFLICTING_PROJECTION!>In<out K><!>
typealias A13<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>in K<!>> = In<K>
typealias A14<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>in K<!>> = In<in K>
typealias A15<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>in K<!>> = <!CONFLICTING_PROJECTION!>In<out K><!>
typealias A13<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>in<!> K> = In<K>
typealias A14<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>in<!> K> = In<in K>
typealias A15<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>in<!> K> = <!CONFLICTING_PROJECTION!>In<out K><!>
typealias A16<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>out K<!>> = In<K>
typealias A17<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>out K<!>> = In<in K>
typealias A18<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>out K<!>> = <!CONFLICTING_PROJECTION!>In<out K><!>
typealias A16<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>out<!> K> = In<K>
typealias A17<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>out<!> K> = In<in K>
typealias A18<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>out<!> K> = <!CONFLICTING_PROJECTION!>In<out K><!>
typealias A19<K> = Out<K>
typealias A20<K> = <!CONFLICTING_PROJECTION!>Out<in K><!>
typealias A21<K> = Out<out K>
typealias A22<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>in K<!>> = Out<K>
typealias A23<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>in K<!>> = <!CONFLICTING_PROJECTION!>Out<in K><!>
typealias A24<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>in K<!>> = Out<out K>
typealias A22<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>in<!> K> = Out<K>
typealias A23<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>in<!> K> = <!CONFLICTING_PROJECTION!>Out<in K><!>
typealias A24<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>in<!> K> = Out<out K>
typealias A25<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>out K<!>> = Out<K>
typealias A26<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>out K<!>> = <!CONFLICTING_PROJECTION!>Out<in K><!>
typealias A27<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>out K<!>> = Out<out K>
typealias A25<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>out<!> K> = Out<K>
typealias A26<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>out<!> K> = <!CONFLICTING_PROJECTION!>Out<in K><!>
typealias A27<<!VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED!>out<!> K> = Out<out K>
class Outer<T> {
inner class Intermediate<K> {
@@ -0,0 +1,10 @@
FILE: allWarnings.kt
@R|kotlin/Suppress|(vararg(String(warnings))) public final class A : R|kotlin/Any| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
public final fun foo(): R|kotlin/Unit| {
}
}
@@ -0,0 +1,6 @@
// WITH_EXTENDED_CHECKERS
@Suppress("warnings")
public class A {
final fun foo() {}
}
@@ -0,0 +1,10 @@
FILE: multipleWarnings.kt
@R|kotlin/Suppress|(vararg(String(REDUNDANT_VISIBILITY_MODIFIER))) public final class A : R|kotlin/Any| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
@R|kotlin/Suppress|(vararg(String(REDUNDANT_MODALITY_MODIFIER))) public final fun foo(): R|kotlin/Unit| {
}
}
@@ -0,0 +1,7 @@
// WITH_EXTENDED_CHECKERS
@Suppress("REDUNDANT_VISIBILITY_MODIFIER")
public class A {
@Suppress("REDUNDANT_MODALITY_MODIFIER")
public final fun foo() {}
}
@@ -0,0 +1,6 @@
FILE: singleError.kt
public final fun foo(x: R|kotlin/String|): R|kotlin/Unit| {
}
@R|kotlin/Suppress|(vararg(String(INAPPLICABLE_CANDIDATE))) public final fun bar(): R|kotlin/Unit| {
<Inapplicable(INAPPLICABLE): /foo>#(Int(10))
}
@@ -0,0 +1,6 @@
fun foo(x: String) {}
@Suppress("INAPPLICABLE_CANDIDATE")
fun bar() {
foo(10)
}
@@ -0,0 +1,3 @@
FILE: singleWarning.kt
@R|kotlin/Suppress|(vararg(String(REDUNDANT_VISIBILITY_MODIFIER))) public final fun foo(): R|kotlin/Unit| {
}
@@ -0,0 +1,4 @@
// WITH_EXTENDED_CHECKERS
@Suppress("REDUNDANT_VISIBILITY_MODIFIER")
public fun foo() {}
@@ -0,0 +1,67 @@
FILE: throwableSubclass.kt
public final class Test1<T, B> : R|kotlin/Exception| {
public constructor<T, B>(): R|Test1<T, B>| {
super<R|kotlin/Exception|>()
}
public final inner class Test2<S, T, B> : R|kotlin/Throwable| {
public constructor<S>(): R|Test1.Test2<S, T, B>| {
super<R|kotlin/Throwable|>()
}
}
public final class Test3 : R|kotlin/NullPointerException| {
public constructor(): R|Test1.Test3| {
super<R|kotlin/NullPointerException|>()
}
}
public final object Test4 : R|kotlin/Throwable| {
private constructor(): R|Test1.Test4| {
super<R|kotlin/Throwable|>()
}
}
}
public final class Test5<T, B> : R|kotlin/Any| {
public constructor<T, B>(): R|Test5<T, B>| {
super<R|kotlin/Any|>()
}
public final inner class Test6<T, B> : R|kotlin/Exception| {
public constructor(): R|Test5.Test6<T, B>| {
super<R|kotlin/Exception|>()
}
}
public final fun foo(): R|kotlin/Unit| {
local final class Test7 : R|kotlin/Throwable| {
public constructor(): R|Test5.Test7| {
super<R|kotlin/Throwable|>()
}
}
}
}
public final fun <Z> topLevelFun(): R|kotlin/Unit| {
local final class Test8 : R|kotlin/Error| {
public constructor(): R|Test8| {
super<R|kotlin/Error|>()
}
}
lval obj: R|<anonymous><Z>| = object : R|kotlin/Throwable| {
private constructor(): R|<anonymous><Z>| {
super<R|kotlin/Throwable|>()
}
}
}
@@ -0,0 +1,18 @@
class Test1<<!GENERIC_THROWABLE_SUBCLASS!>T<!>, B> : Exception() {
inner <!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>class Test2<!><<!GENERIC_THROWABLE_SUBCLASS!>S<!>> : Throwable()
class Test3 : NullPointerException()
object Test4 : Throwable() {}
}
class Test5<T, B> {
inner <!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>class Test6<!> : Exception()
fun foo() {
<!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>class Test7<!> : Throwable()
}
}
fun <Z> topLevelFun() {
<!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS!>class Test8<!> : Error()
val obj = <!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS{LT}!><!INNER_CLASS_OF_GENERIC_THROWABLE_SUBCLASS{PSI}!>object<!> : Throwable() {}<!>
}
@@ -0,0 +1,59 @@
FILE: valueOfOrNull.kt
public final enum class SomeEnum : R|kotlin/Enum<SomeEnum>| {
private constructor(): R|SomeEnum| {
super<R|kotlin/Enum<SomeEnum>|>()
}
public final static enum entry ENTRY: R|SomeEnum|
public final static fun values(): R|kotlin/Array<SomeEnum>| {
}
public final static fun valueOf(value: R|kotlin/String|): R|SomeEnum| {
}
}
public final fun foo(s: R|kotlin/String?|): R|kotlin/Unit| {
lval result: R|SomeEnum| = R|<local>/s|?.{ $subj$.R|kotlin/let|<R|kotlin/String|, R|SomeEnum?|>(<L> = let@fun <anonymous>(it: R|kotlin/String|): R|SomeEnum?| <kind=EXACTLY_ONCE> {
^ R|/valueOfOrNull|<R|SomeEnum|>(R|<local>/it|)
}
) } ?: Q|SomeEnum|.R|/SomeEnum.ENTRY|
lval result2: R|SomeEnum| = R|<local>/s|?.{ $subj$.R|kotlin/let|<R|kotlin/String|, R|SomeEnum?|>(<L> = let@fun <anonymous>(it: R|kotlin/String|): R|SomeEnum?| <kind=EXACTLY_ONCE> {
^ R|/valueOfOrNull|<R|SomeEnum|>(R|<local>/it|)
}
) } ?: Q|SomeEnum|.R|/SomeEnum.ENTRY|
lval result3: R|SomeEnum?| = when () {
==(R|<local>/s|, Null(null)) -> {
Q|SomeEnum|.R|/SomeEnum.ENTRY|
}
else -> {
R|/valueOfOrNull|<R|SomeEnum|>(R|<local>/s|)
}
}
lval result4: R|SomeEnum?| = when () {
==(R|<local>/s|, Null(null)) -> {
Q|SomeEnum|.R|/SomeEnum.ENTRY|
}
else -> {
R|<local>/s|.R|kotlin/let|<R|kotlin/String|, R|SomeEnum?|>(<L> = let@fun <anonymous>(it: R|kotlin/String|): R|SomeEnum?| <kind=EXACTLY_ONCE> {
^ R|/valueOfOrNull|<R|SomeEnum|>(R|<local>/it|)
}
)
}
}
}
public final inline fun <reified E : R|kotlin/Enum<E>|> valueOfOrNull(value: R|kotlin/String|): R|E?| {
lval <iterator>: R|kotlin/collections/Iterator<E>| = R|kotlin/enumValues|<R|E|>().R|SubstitutionOverride<kotlin/Array.iterator: R|kotlin/collections/Iterator<E>|>|()
while(R|<local>/<iterator>|.R|kotlin/collections/Iterator.hasNext|()) {
lval enumValue: R|E| = R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.next: R|E|>|()
when () {
==(R|<local>/enumValue|.R|kotlin/Enum.name|, R|<local>/value|) -> {
^valueOfOrNull R|<local>/enumValue|
}
}
}
^valueOfOrNull Null(null)
}
@@ -0,0 +1,19 @@
enum class SomeEnum {
ENTRY;
}
fun foo(s: String?) {
val result = s?.let { valueOfOrNull(it) } ?: SomeEnum.ENTRY
val result2 = s?.let { valueOfOrNull<SomeEnum>(it) } ?: SomeEnum.ENTRY
val result3 = if (s == null) SomeEnum.ENTRY else valueOfOrNull(s)
val result4 = if (s == null) SomeEnum.ENTRY else s.let { valueOfOrNull(it) }
}
inline fun <reified E : Enum<E>> valueOfOrNull(value: String): E? {
for (enumValue in enumValues<E>()) {
if (enumValue.name == value) {
return enumValue
}
}
return null
}
@@ -20,7 +20,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve")
@TestDataPath("$PROJECT_ROOT")
public class Resolve extends AbstractFirDiagnosticTest {
public class Resolve {
@Test
public void testAllFilesPresentInResolve() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -56,6 +56,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
runTest("compiler/fir/analysis-tests/testData/resolve/cast.kt");
}
@Test
@TestMetadata("catchParameter.kt")
public void testCatchParameter() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/catchParameter.kt");
}
@Test
@TestMetadata("companion.kt")
public void testCompanion() throws Exception {
@@ -488,6 +494,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
runTest("compiler/fir/analysis-tests/testData/resolve/syntheticsVsNormalProperties.kt");
}
@Test
@TestMetadata("throwableSubclass.kt")
public void testThrowableSubclass() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/throwableSubclass.kt");
}
@Test
@TestMetadata("treeSet.kt")
public void testTreeSet() throws Exception {
@@ -575,7 +587,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/arguments")
@TestDataPath("$PROJECT_ROOT")
public class Arguments extends AbstractFirDiagnosticTest {
public class Arguments {
@Test
public void testAllFilesPresentInArguments() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/arguments"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -759,7 +771,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/arrays")
@TestDataPath("$PROJECT_ROOT")
public class Arrays extends AbstractFirDiagnosticTest {
public class Arrays {
@Test
public void testAllFilesPresentInArrays() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/arrays"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -781,7 +793,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/builtins")
@TestDataPath("$PROJECT_ROOT")
public class Builtins extends AbstractFirDiagnosticTest {
public class Builtins {
@Test
public void testAllFilesPresentInBuiltins() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/builtins"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -797,7 +809,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/callResolution")
@TestDataPath("$PROJECT_ROOT")
public class CallResolution extends AbstractFirDiagnosticTest {
public class CallResolution {
@Test
public void testAllFilesPresentInCallResolution() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/callResolution"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -897,7 +909,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/cfg")
@TestDataPath("$PROJECT_ROOT")
public class Cfg extends AbstractFirDiagnosticTest {
public class Cfg {
@Test
public void testAllFilesPresentInCfg() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/cfg"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -1057,7 +1069,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/constructors")
@TestDataPath("$PROJECT_ROOT")
public class Constructors extends AbstractFirDiagnosticTest {
public class Constructors {
@Test
public void testAllFilesPresentInConstructors() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/constructors"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -1073,7 +1085,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/delegates")
@TestDataPath("$PROJECT_ROOT")
public class Delegates extends AbstractFirDiagnosticTest {
public class Delegates {
@Test
public void testAllFilesPresentInDelegates() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/delegates"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -1119,7 +1131,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/diagnostics")
@TestDataPath("$PROJECT_ROOT")
public class Diagnostics extends AbstractFirDiagnosticTest {
public class Diagnostics {
@Test
@TestMetadata("abstractSuperCall.kt")
public void testAbstractSuperCall() throws Exception {
@@ -1428,7 +1440,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/diagnostics/functionAsExpression")
@TestDataPath("$PROJECT_ROOT")
public class FunctionAsExpression extends AbstractFirDiagnosticTest {
public class FunctionAsExpression {
@Test
public void testAllFilesPresentInFunctionAsExpression() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/diagnostics/functionAsExpression"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -1445,7 +1457,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/expresssions")
@TestDataPath("$PROJECT_ROOT")
public class Expresssions extends AbstractFirDiagnosticTest {
public class Expresssions {
@Test
@TestMetadata("access.kt")
public void testAccess() throws Exception {
@@ -1820,7 +1832,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/expresssions/inference")
@TestDataPath("$PROJECT_ROOT")
public class Inference extends AbstractFirDiagnosticTest {
public class Inference {
@Test
public void testAllFilesPresentInInference() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/expresssions/inference"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -1848,7 +1860,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/expresssions/invoke")
@TestDataPath("$PROJECT_ROOT")
public class Invoke extends AbstractFirDiagnosticTest {
public class Invoke {
@Test
public void testAllFilesPresentInInvoke() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/expresssions/invoke"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -1948,7 +1960,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/expresssions/operators")
@TestDataPath("$PROJECT_ROOT")
public class Operators extends AbstractFirDiagnosticTest {
public class Operators {
@Test
public void testAllFilesPresentInOperators() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/expresssions/operators"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -1977,7 +1989,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/extendedCheckers")
@TestDataPath("$PROJECT_ROOT")
public class ExtendedCheckers extends AbstractFirDiagnosticTest {
public class ExtendedCheckers {
@Test
public void testAllFilesPresentInExtendedCheckers() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/extendedCheckers"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2034,7 +2046,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/canBeReplacedWithOperatorAssignment")
@TestDataPath("$PROJECT_ROOT")
public class CanBeReplacedWithOperatorAssignment extends AbstractFirDiagnosticTest {
public class CanBeReplacedWithOperatorAssignment {
@Test
public void testAllFilesPresentInCanBeReplacedWithOperatorAssignment() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/canBeReplacedWithOperatorAssignment"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2158,7 +2170,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/emptyRangeChecker")
@TestDataPath("$PROJECT_ROOT")
public class EmptyRangeChecker extends AbstractFirDiagnosticTest {
public class EmptyRangeChecker {
@Test
public void testAllFilesPresentInEmptyRangeChecker() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/emptyRangeChecker"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2180,7 +2192,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantCallOfConversionMethod")
@TestDataPath("$PROJECT_ROOT")
public class RedundantCallOfConversionMethod extends AbstractFirDiagnosticTest {
public class RedundantCallOfConversionMethod {
@Test
public void testAllFilesPresentInRedundantCallOfConversionMethod() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantCallOfConversionMethod"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2310,7 +2322,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/unused")
@TestDataPath("$PROJECT_ROOT")
public class Unused extends AbstractFirDiagnosticTest {
public class Unused {
@Test
public void testAllFilesPresentInUnused() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/unused"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2362,7 +2374,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/UselessCallOnNotNullChecker")
@TestDataPath("$PROJECT_ROOT")
public class UselessCallOnNotNullChecker extends AbstractFirDiagnosticTest {
public class UselessCallOnNotNullChecker {
@Test
public void testAllFilesPresentInUselessCallOnNotNullChecker() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/UselessCallOnNotNullChecker"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2439,7 +2451,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/fromBuilder")
@TestDataPath("$PROJECT_ROOT")
public class FromBuilder extends AbstractFirDiagnosticTest {
public class FromBuilder {
@Test
public void testAllFilesPresentInFromBuilder() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/fromBuilder"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2479,7 +2491,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/inference")
@TestDataPath("$PROJECT_ROOT")
public class Inference extends AbstractFirDiagnosticTest {
public class Inference {
@Test
public void testAllFilesPresentInInference() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/inference"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2609,7 +2621,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/innerClasses")
@TestDataPath("$PROJECT_ROOT")
public class InnerClasses extends AbstractFirDiagnosticTest {
public class InnerClasses {
@Test
public void testAllFilesPresentInInnerClasses() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/innerClasses"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2643,7 +2655,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/localClasses")
@TestDataPath("$PROJECT_ROOT")
public class LocalClasses extends AbstractFirDiagnosticTest {
public class LocalClasses {
@Test
public void testAllFilesPresentInLocalClasses() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/localClasses"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2671,7 +2683,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/multifile")
@TestDataPath("$PROJECT_ROOT")
public class Multifile extends AbstractFirDiagnosticTest {
public class Multifile {
@Test
public void testAllFilesPresentInMultifile() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/multifile"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2747,7 +2759,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/overrides")
@TestDataPath("$PROJECT_ROOT")
public class Overrides extends AbstractFirDiagnosticTest {
public class Overrides {
@Test
public void testAllFilesPresentInOverrides() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/overrides"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2805,7 +2817,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/problems")
@TestDataPath("$PROJECT_ROOT")
public class Problems extends AbstractFirDiagnosticTest {
public class Problems {
@Test
public void testAllFilesPresentInProblems() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/problems"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2905,7 +2917,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/properties")
@TestDataPath("$PROJECT_ROOT")
public class Properties extends AbstractFirDiagnosticTest {
public class Properties {
@Test
public void testAllFilesPresentInProperties() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/properties"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2951,7 +2963,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/references")
@TestDataPath("$PROJECT_ROOT")
public class References extends AbstractFirDiagnosticTest {
public class References {
@Test
public void testAllFilesPresentInReferences() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/references"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2985,7 +2997,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/samConstructors")
@TestDataPath("$PROJECT_ROOT")
public class SamConstructors extends AbstractFirDiagnosticTest {
public class SamConstructors {
@Test
public void testAllFilesPresentInSamConstructors() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/samConstructors"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3031,7 +3043,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/samConversions")
@TestDataPath("$PROJECT_ROOT")
public class SamConversions extends AbstractFirDiagnosticTest {
public class SamConversions {
@Test
public void testAllFilesPresentInSamConversions() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/samConversions"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3095,7 +3107,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts")
@TestDataPath("$PROJECT_ROOT")
public class Smartcasts extends AbstractFirDiagnosticTest {
public class Smartcasts {
@Test
public void testAllFilesPresentInSmartcasts() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3170,7 +3182,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/booleans")
@TestDataPath("$PROJECT_ROOT")
public class Booleans extends AbstractFirDiagnosticTest {
public class Booleans {
@Test
public void testAllFilesPresentInBooleans() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts/booleans"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3198,7 +3210,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts")
@TestDataPath("$PROJECT_ROOT")
public class BoundSmartcasts extends AbstractFirDiagnosticTest {
public class BoundSmartcasts {
@Test
public void testAllFilesPresentInBoundSmartcasts() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3226,7 +3238,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/controlStructures")
@TestDataPath("$PROJECT_ROOT")
public class ControlStructures extends AbstractFirDiagnosticTest {
public class ControlStructures {
@Test
public void testAllFilesPresentInControlStructures() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts/controlStructures"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3266,7 +3278,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/lambdas")
@TestDataPath("$PROJECT_ROOT")
public class Lambdas extends AbstractFirDiagnosticTest {
public class Lambdas {
@Test
public void testAllFilesPresentInLambdas() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts/lambdas"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3294,7 +3306,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/loops")
@TestDataPath("$PROJECT_ROOT")
public class Loops extends AbstractFirDiagnosticTest {
public class Loops {
@Test
public void testAllFilesPresentInLoops() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts/loops"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3316,7 +3328,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/problems")
@TestDataPath("$PROJECT_ROOT")
public class Problems extends AbstractFirDiagnosticTest {
public class Problems {
@Test
public void testAllFilesPresentInProblems() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts/problems"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3332,7 +3344,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/receivers")
@TestDataPath("$PROJECT_ROOT")
public class Receivers extends AbstractFirDiagnosticTest {
public class Receivers {
@Test
public void testAllFilesPresentInReceivers() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts/receivers"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3366,7 +3378,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/safeCalls")
@TestDataPath("$PROJECT_ROOT")
public class SafeCalls extends AbstractFirDiagnosticTest {
public class SafeCalls {
@Test
public void testAllFilesPresentInSafeCalls() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts/safeCalls"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3400,7 +3412,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/stability")
@TestDataPath("$PROJECT_ROOT")
public class Stability extends AbstractFirDiagnosticTest {
public class Stability {
@Test
public void testAllFilesPresentInStability() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts/stability"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3416,7 +3428,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/variables")
@TestDataPath("$PROJECT_ROOT")
public class Variables extends AbstractFirDiagnosticTest {
public class Variables {
@Test
public void testAllFilesPresentInVariables() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts/variables"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3439,7 +3451,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/stdlib")
@TestDataPath("$PROJECT_ROOT")
public class Stdlib extends AbstractFirDiagnosticTest {
public class Stdlib {
@Test
public void testAllFilesPresentInStdlib() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/stdlib"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3448,7 +3460,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/stdlib/j+k")
@TestDataPath("$PROJECT_ROOT")
public class J_k extends AbstractFirDiagnosticTest {
public class J_k {
@Test
public void testAllFilesPresentInJ_k() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/stdlib/j+k"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3468,10 +3480,44 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
}
}
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/suppress")
@TestDataPath("$PROJECT_ROOT")
public class Suppress {
@Test
public void testAllFilesPresentInSuppress() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/suppress"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
}
@Test
@TestMetadata("allWarnings.kt")
public void testAllWarnings() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/suppress/allWarnings.kt");
}
@Test
@TestMetadata("multipleWarnings.kt")
public void testMultipleWarnings() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/suppress/multipleWarnings.kt");
}
@Test
@TestMetadata("singleError.kt")
public void testSingleError() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/suppress/singleError.kt");
}
@Test
@TestMetadata("singleWarning.kt")
public void testSingleWarning() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/suppress/singleWarning.kt");
}
}
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/types")
@TestDataPath("$PROJECT_ROOT")
public class Types extends AbstractFirDiagnosticTest {
public class Types {
@Test
public void testAllFilesPresentInTypes() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/types"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3493,7 +3539,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/visibility")
@TestDataPath("$PROJECT_ROOT")
public class Visibility extends AbstractFirDiagnosticTest {
public class Visibility {
@Test
public void testAllFilesPresentInVisibility() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/visibility"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3570,7 +3616,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib")
@TestDataPath("$PROJECT_ROOT")
public class ResolveWithStdlib extends AbstractFirDiagnosticTest {
public class ResolveWithStdlib {
@Test
@TestMetadata("addAllOnJavaCollection.kt")
public void testAddAllOnJavaCollection() throws Exception {
@@ -3909,7 +3955,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences")
@TestDataPath("$PROJECT_ROOT")
public class CallableReferences extends AbstractFirDiagnosticTest {
public class CallableReferences {
@Test
public void testAllFilesPresentInCallableReferences() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4056,7 +4102,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/fromBasicDiagnosticTests")
@TestDataPath("$PROJECT_ROOT")
public class FromBasicDiagnosticTests extends AbstractFirDiagnosticTest {
public class FromBasicDiagnosticTests {
@Test
public void testAllFilesPresentInFromBasicDiagnosticTests() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/fromBasicDiagnosticTests"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4145,7 +4191,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts")
@TestDataPath("$PROJECT_ROOT")
public class Contracts extends AbstractFirDiagnosticTest {
public class Contracts {
@Test
public void testAllFilesPresentInContracts() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4154,7 +4200,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromLibrary")
@TestDataPath("$PROJECT_ROOT")
public class FromLibrary extends AbstractFirDiagnosticTest {
public class FromLibrary {
@Test
public void testAllFilesPresentInFromLibrary() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromLibrary"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4182,7 +4228,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource")
@TestDataPath("$PROJECT_ROOT")
public class FromSource extends AbstractFirDiagnosticTest {
public class FromSource {
@Test
public void testAllFilesPresentInFromSource() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4191,7 +4237,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad")
@TestDataPath("$PROJECT_ROOT")
public class Bad extends AbstractFirDiagnosticTest {
public class Bad {
@Test
public void testAllFilesPresentInBad() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4200,7 +4246,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace")
@TestDataPath("$PROJECT_ROOT")
public class CallsInPlace extends AbstractFirDiagnosticTest {
public class CallsInPlace {
@Test
public void testAllFilesPresentInCallsInPlace() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4234,7 +4280,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/returnsImplies")
@TestDataPath("$PROJECT_ROOT")
public class ReturnsImplies extends AbstractFirDiagnosticTest {
public class ReturnsImplies {
@Test
public void testAllFilesPresentInReturnsImplies() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/returnsImplies"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4257,7 +4303,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good")
@TestDataPath("$PROJECT_ROOT")
public class Good extends AbstractFirDiagnosticTest {
public class Good {
@Test
public void testAllFilesPresentInGood() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4266,7 +4312,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/callsInPlace")
@TestDataPath("$PROJECT_ROOT")
public class CallsInPlace extends AbstractFirDiagnosticTest {
public class CallsInPlace {
@Test
public void testAllFilesPresentInCallsInPlace() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/callsInPlace"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4324,7 +4370,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/returnsImplies")
@TestDataPath("$PROJECT_ROOT")
public class ReturnsImplies extends AbstractFirDiagnosticTest {
public class ReturnsImplies {
@Test
public void testAllFilesPresentInReturnsImplies() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/returnsImplies"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4400,7 +4446,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/variousContracts")
@TestDataPath("$PROJECT_ROOT")
public class VariousContracts extends AbstractFirDiagnosticTest {
public class VariousContracts {
@Test
public void testAllFilesPresentInVariousContracts() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/variousContracts"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4409,7 +4455,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/variousContracts/newSyntax")
@TestDataPath("$PROJECT_ROOT")
public class NewSyntax extends AbstractFirDiagnosticTest {
public class NewSyntax {
@Test
public void testAllFilesPresentInNewSyntax() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/variousContracts/newSyntax"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4429,7 +4475,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates")
@TestDataPath("$PROJECT_ROOT")
public class Delegates extends AbstractFirDiagnosticTest {
public class Delegates {
@Test
public void testAllFilesPresentInDelegates() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4475,7 +4521,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference")
@TestDataPath("$PROJECT_ROOT")
public class Inference extends AbstractFirDiagnosticTest {
public class Inference {
@Test
public void testAllFilesPresentInInference() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4527,7 +4573,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/initialization")
@TestDataPath("$PROJECT_ROOT")
public class Initialization extends AbstractFirDiagnosticTest {
public class Initialization {
@Test
public void testAllFilesPresentInInitialization() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/initialization"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4543,7 +4589,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k")
@TestDataPath("$PROJECT_ROOT")
public class J_k extends AbstractFirDiagnosticTest {
public class J_k {
@Test
public void testAllFilesPresentInJ_k() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4835,7 +4881,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/multiModule")
@TestDataPath("$PROJECT_ROOT")
public class MultiModule extends AbstractFirDiagnosticTest {
public class MultiModule {
@Test
public void testAllFilesPresentInMultiModule() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/multiModule"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4875,7 +4921,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/problems")
@TestDataPath("$PROJECT_ROOT")
public class Problems extends AbstractFirDiagnosticTest {
public class Problems {
@Test
public void testAllFilesPresentInProblems() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/problems"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4941,6 +4987,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/TypesEligibleForSimpleVisit.kt");
}
@Test
@TestMetadata("valueOfOrNull.kt")
public void testValueOfOrNull() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/valueOfOrNull.kt");
}
@Test
@TestMetadata("weakHashMap.kt")
public void testWeakHashMap() throws Exception {
@@ -4951,7 +5003,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/reinitializations")
@TestDataPath("$PROJECT_ROOT")
public class Reinitializations extends AbstractFirDiagnosticTest {
public class Reinitializations {
@Test
public void testAllFilesPresentInReinitializations() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/reinitializations"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4967,7 +5019,7 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/smartcasts")
@TestDataPath("$PROJECT_ROOT")
public class Smartcasts extends AbstractFirDiagnosticTest {
public class Smartcasts {
@Test
public void testAllFilesPresentInSmartcasts() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/smartcasts"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -10,8 +10,6 @@ import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import java.io.File;
import java.util.regex.Pattern;
@@ -23,7 +23,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Resolve extends AbstractFirDiagnosticsWithLightTreeTest {
public class Resolve {
@Test
public void testAllFilesPresentInResolve() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -59,6 +59,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
runTest("compiler/fir/analysis-tests/testData/resolve/cast.kt");
}
@Test
@TestMetadata("catchParameter.kt")
public void testCatchParameter() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/catchParameter.kt");
}
@Test
@TestMetadata("companion.kt")
public void testCompanion() throws Exception {
@@ -491,6 +497,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
runTest("compiler/fir/analysis-tests/testData/resolve/syntheticsVsNormalProperties.kt");
}
@Test
@TestMetadata("throwableSubclass.kt")
public void testThrowableSubclass() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/throwableSubclass.kt");
}
@Test
@TestMetadata("treeSet.kt")
public void testTreeSet() throws Exception {
@@ -579,7 +591,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/arguments")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Arguments extends AbstractFirDiagnosticsWithLightTreeTest {
public class Arguments {
@Test
public void testAllFilesPresentInArguments() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/arguments"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -764,7 +776,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/arrays")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Arrays extends AbstractFirDiagnosticsWithLightTreeTest {
public class Arrays {
@Test
public void testAllFilesPresentInArrays() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/arrays"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -787,7 +799,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/builtins")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Builtins extends AbstractFirDiagnosticsWithLightTreeTest {
public class Builtins {
@Test
public void testAllFilesPresentInBuiltins() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/builtins"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -804,7 +816,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/callResolution")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class CallResolution extends AbstractFirDiagnosticsWithLightTreeTest {
public class CallResolution {
@Test
public void testAllFilesPresentInCallResolution() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/callResolution"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -905,7 +917,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/cfg")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Cfg extends AbstractFirDiagnosticsWithLightTreeTest {
public class Cfg {
@Test
public void testAllFilesPresentInCfg() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/cfg"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -1066,7 +1078,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/constructors")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Constructors extends AbstractFirDiagnosticsWithLightTreeTest {
public class Constructors {
@Test
public void testAllFilesPresentInConstructors() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/constructors"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -1083,7 +1095,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/delegates")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Delegates extends AbstractFirDiagnosticsWithLightTreeTest {
public class Delegates {
@Test
public void testAllFilesPresentInDelegates() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/delegates"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -1130,7 +1142,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/diagnostics")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Diagnostics extends AbstractFirDiagnosticsWithLightTreeTest {
public class Diagnostics {
@Test
@TestMetadata("abstractSuperCall.kt")
public void testAbstractSuperCall() throws Exception {
@@ -1440,7 +1452,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/diagnostics/functionAsExpression")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class FunctionAsExpression extends AbstractFirDiagnosticsWithLightTreeTest {
public class FunctionAsExpression {
@Test
public void testAllFilesPresentInFunctionAsExpression() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/diagnostics/functionAsExpression"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -1458,7 +1470,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/expresssions")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Expresssions extends AbstractFirDiagnosticsWithLightTreeTest {
public class Expresssions {
@Test
@TestMetadata("access.kt")
public void testAccess() throws Exception {
@@ -1834,7 +1846,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/expresssions/inference")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Inference extends AbstractFirDiagnosticsWithLightTreeTest {
public class Inference {
@Test
public void testAllFilesPresentInInference() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/expresssions/inference"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -1863,7 +1875,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/expresssions/invoke")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Invoke extends AbstractFirDiagnosticsWithLightTreeTest {
public class Invoke {
@Test
public void testAllFilesPresentInInvoke() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/expresssions/invoke"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -1964,7 +1976,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/expresssions/operators")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Operators extends AbstractFirDiagnosticsWithLightTreeTest {
public class Operators {
@Test
public void testAllFilesPresentInOperators() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/expresssions/operators"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -1994,7 +2006,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/extendedCheckers")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class ExtendedCheckers extends AbstractFirDiagnosticsWithLightTreeTest {
public class ExtendedCheckers {
@Test
public void testAllFilesPresentInExtendedCheckers() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/extendedCheckers"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2052,7 +2064,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/canBeReplacedWithOperatorAssignment")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class CanBeReplacedWithOperatorAssignment extends AbstractFirDiagnosticsWithLightTreeTest {
public class CanBeReplacedWithOperatorAssignment {
@Test
public void testAllFilesPresentInCanBeReplacedWithOperatorAssignment() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/canBeReplacedWithOperatorAssignment"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2177,7 +2189,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/emptyRangeChecker")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class EmptyRangeChecker extends AbstractFirDiagnosticsWithLightTreeTest {
public class EmptyRangeChecker {
@Test
public void testAllFilesPresentInEmptyRangeChecker() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/emptyRangeChecker"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2200,7 +2212,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantCallOfConversionMethod")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class RedundantCallOfConversionMethod extends AbstractFirDiagnosticsWithLightTreeTest {
public class RedundantCallOfConversionMethod {
@Test
public void testAllFilesPresentInRedundantCallOfConversionMethod() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantCallOfConversionMethod"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2331,7 +2343,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/unused")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Unused extends AbstractFirDiagnosticsWithLightTreeTest {
public class Unused {
@Test
public void testAllFilesPresentInUnused() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/unused"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2384,7 +2396,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/UselessCallOnNotNullChecker")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class UselessCallOnNotNullChecker extends AbstractFirDiagnosticsWithLightTreeTest {
public class UselessCallOnNotNullChecker {
@Test
public void testAllFilesPresentInUselessCallOnNotNullChecker() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/extendedCheckers/UselessCallOnNotNullChecker"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2462,7 +2474,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/fromBuilder")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class FromBuilder extends AbstractFirDiagnosticsWithLightTreeTest {
public class FromBuilder {
@Test
public void testAllFilesPresentInFromBuilder() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/fromBuilder"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2503,7 +2515,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/inference")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Inference extends AbstractFirDiagnosticsWithLightTreeTest {
public class Inference {
@Test
public void testAllFilesPresentInInference() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/inference"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2634,7 +2646,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/innerClasses")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class InnerClasses extends AbstractFirDiagnosticsWithLightTreeTest {
public class InnerClasses {
@Test
public void testAllFilesPresentInInnerClasses() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/innerClasses"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2669,7 +2681,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/localClasses")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class LocalClasses extends AbstractFirDiagnosticsWithLightTreeTest {
public class LocalClasses {
@Test
public void testAllFilesPresentInLocalClasses() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/localClasses"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2698,7 +2710,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/multifile")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Multifile extends AbstractFirDiagnosticsWithLightTreeTest {
public class Multifile {
@Test
public void testAllFilesPresentInMultifile() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/multifile"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2775,7 +2787,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/overrides")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Overrides extends AbstractFirDiagnosticsWithLightTreeTest {
public class Overrides {
@Test
public void testAllFilesPresentInOverrides() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/overrides"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2834,7 +2846,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/problems")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Problems extends AbstractFirDiagnosticsWithLightTreeTest {
public class Problems {
@Test
public void testAllFilesPresentInProblems() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/problems"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2935,7 +2947,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/properties")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Properties extends AbstractFirDiagnosticsWithLightTreeTest {
public class Properties {
@Test
public void testAllFilesPresentInProperties() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/properties"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -2982,7 +2994,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/references")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class References extends AbstractFirDiagnosticsWithLightTreeTest {
public class References {
@Test
public void testAllFilesPresentInReferences() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/references"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3017,7 +3029,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/samConstructors")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class SamConstructors extends AbstractFirDiagnosticsWithLightTreeTest {
public class SamConstructors {
@Test
public void testAllFilesPresentInSamConstructors() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/samConstructors"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3064,7 +3076,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/samConversions")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class SamConversions extends AbstractFirDiagnosticsWithLightTreeTest {
public class SamConversions {
@Test
public void testAllFilesPresentInSamConversions() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/samConversions"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3129,7 +3141,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Smartcasts extends AbstractFirDiagnosticsWithLightTreeTest {
public class Smartcasts {
@Test
public void testAllFilesPresentInSmartcasts() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3205,7 +3217,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/booleans")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Booleans extends AbstractFirDiagnosticsWithLightTreeTest {
public class Booleans {
@Test
public void testAllFilesPresentInBooleans() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts/booleans"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3234,7 +3246,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class BoundSmartcasts extends AbstractFirDiagnosticsWithLightTreeTest {
public class BoundSmartcasts {
@Test
public void testAllFilesPresentInBoundSmartcasts() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3263,7 +3275,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/controlStructures")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class ControlStructures extends AbstractFirDiagnosticsWithLightTreeTest {
public class ControlStructures {
@Test
public void testAllFilesPresentInControlStructures() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts/controlStructures"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3304,7 +3316,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/lambdas")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Lambdas extends AbstractFirDiagnosticsWithLightTreeTest {
public class Lambdas {
@Test
public void testAllFilesPresentInLambdas() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts/lambdas"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3333,7 +3345,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/loops")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Loops extends AbstractFirDiagnosticsWithLightTreeTest {
public class Loops {
@Test
public void testAllFilesPresentInLoops() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts/loops"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3356,7 +3368,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/problems")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Problems extends AbstractFirDiagnosticsWithLightTreeTest {
public class Problems {
@Test
public void testAllFilesPresentInProblems() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts/problems"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3373,7 +3385,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/receivers")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Receivers extends AbstractFirDiagnosticsWithLightTreeTest {
public class Receivers {
@Test
public void testAllFilesPresentInReceivers() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts/receivers"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3408,7 +3420,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/safeCalls")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class SafeCalls extends AbstractFirDiagnosticsWithLightTreeTest {
public class SafeCalls {
@Test
public void testAllFilesPresentInSafeCalls() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts/safeCalls"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3443,7 +3455,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/stability")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Stability extends AbstractFirDiagnosticsWithLightTreeTest {
public class Stability {
@Test
public void testAllFilesPresentInStability() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts/stability"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3460,7 +3472,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/variables")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Variables extends AbstractFirDiagnosticsWithLightTreeTest {
public class Variables {
@Test
public void testAllFilesPresentInVariables() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/smartcasts/variables"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3484,7 +3496,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/stdlib")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Stdlib extends AbstractFirDiagnosticsWithLightTreeTest {
public class Stdlib {
@Test
public void testAllFilesPresentInStdlib() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/stdlib"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3494,7 +3506,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/stdlib/j+k")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class J_k extends AbstractFirDiagnosticsWithLightTreeTest {
public class J_k {
@Test
public void testAllFilesPresentInJ_k() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/stdlib/j+k"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3514,11 +3526,46 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
}
}
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/suppress")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Suppress {
@Test
public void testAllFilesPresentInSuppress() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/suppress"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
}
@Test
@TestMetadata("allWarnings.kt")
public void testAllWarnings() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/suppress/allWarnings.kt");
}
@Test
@TestMetadata("multipleWarnings.kt")
public void testMultipleWarnings() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/suppress/multipleWarnings.kt");
}
@Test
@TestMetadata("singleError.kt")
public void testSingleError() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/suppress/singleError.kt");
}
@Test
@TestMetadata("singleWarning.kt")
public void testSingleWarning() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/suppress/singleWarning.kt");
}
}
@Nested
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/types")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Types extends AbstractFirDiagnosticsWithLightTreeTest {
public class Types {
@Test
public void testAllFilesPresentInTypes() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/types"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3541,7 +3588,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/visibility")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Visibility extends AbstractFirDiagnosticsWithLightTreeTest {
public class Visibility {
@Test
public void testAllFilesPresentInVisibility() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/visibility"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -3619,7 +3666,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class ResolveWithStdlib extends AbstractFirDiagnosticsWithLightTreeTest {
public class ResolveWithStdlib {
@Test
@TestMetadata("addAllOnJavaCollection.kt")
public void testAddAllOnJavaCollection() throws Exception {
@@ -3959,7 +4006,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class CallableReferences extends AbstractFirDiagnosticsWithLightTreeTest {
public class CallableReferences {
@Test
public void testAllFilesPresentInCallableReferences() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4107,7 +4154,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/fromBasicDiagnosticTests")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class FromBasicDiagnosticTests extends AbstractFirDiagnosticsWithLightTreeTest {
public class FromBasicDiagnosticTests {
@Test
public void testAllFilesPresentInFromBasicDiagnosticTests() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/fromBasicDiagnosticTests"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4197,7 +4244,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Contracts extends AbstractFirDiagnosticsWithLightTreeTest {
public class Contracts {
@Test
public void testAllFilesPresentInContracts() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4207,7 +4254,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromLibrary")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class FromLibrary extends AbstractFirDiagnosticsWithLightTreeTest {
public class FromLibrary {
@Test
public void testAllFilesPresentInFromLibrary() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromLibrary"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4236,7 +4283,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class FromSource extends AbstractFirDiagnosticsWithLightTreeTest {
public class FromSource {
@Test
public void testAllFilesPresentInFromSource() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4246,7 +4293,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Bad extends AbstractFirDiagnosticsWithLightTreeTest {
public class Bad {
@Test
public void testAllFilesPresentInBad() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4256,7 +4303,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class CallsInPlace extends AbstractFirDiagnosticsWithLightTreeTest {
public class CallsInPlace {
@Test
public void testAllFilesPresentInCallsInPlace() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4291,7 +4338,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/returnsImplies")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class ReturnsImplies extends AbstractFirDiagnosticsWithLightTreeTest {
public class ReturnsImplies {
@Test
public void testAllFilesPresentInReturnsImplies() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/returnsImplies"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4315,7 +4362,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Good extends AbstractFirDiagnosticsWithLightTreeTest {
public class Good {
@Test
public void testAllFilesPresentInGood() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4325,7 +4372,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/callsInPlace")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class CallsInPlace extends AbstractFirDiagnosticsWithLightTreeTest {
public class CallsInPlace {
@Test
public void testAllFilesPresentInCallsInPlace() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/callsInPlace"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4384,7 +4431,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/returnsImplies")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class ReturnsImplies extends AbstractFirDiagnosticsWithLightTreeTest {
public class ReturnsImplies {
@Test
public void testAllFilesPresentInReturnsImplies() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/returnsImplies"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4461,7 +4508,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/variousContracts")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class VariousContracts extends AbstractFirDiagnosticsWithLightTreeTest {
public class VariousContracts {
@Test
public void testAllFilesPresentInVariousContracts() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/variousContracts"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4471,7 +4518,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/variousContracts/newSyntax")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class NewSyntax extends AbstractFirDiagnosticsWithLightTreeTest {
public class NewSyntax {
@Test
public void testAllFilesPresentInNewSyntax() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/variousContracts/newSyntax"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4492,7 +4539,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Delegates extends AbstractFirDiagnosticsWithLightTreeTest {
public class Delegates {
@Test
public void testAllFilesPresentInDelegates() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4539,7 +4586,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Inference extends AbstractFirDiagnosticsWithLightTreeTest {
public class Inference {
@Test
public void testAllFilesPresentInInference() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4592,7 +4639,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/initialization")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Initialization extends AbstractFirDiagnosticsWithLightTreeTest {
public class Initialization {
@Test
public void testAllFilesPresentInInitialization() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/initialization"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4609,7 +4656,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class J_k extends AbstractFirDiagnosticsWithLightTreeTest {
public class J_k {
@Test
public void testAllFilesPresentInJ_k() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4902,7 +4949,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/multiModule")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class MultiModule extends AbstractFirDiagnosticsWithLightTreeTest {
public class MultiModule {
@Test
public void testAllFilesPresentInMultiModule() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/multiModule"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -4943,7 +4990,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/problems")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Problems extends AbstractFirDiagnosticsWithLightTreeTest {
public class Problems {
@Test
public void testAllFilesPresentInProblems() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/problems"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -5009,6 +5056,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/TypesEligibleForSimpleVisit.kt");
}
@Test
@TestMetadata("valueOfOrNull.kt")
public void testValueOfOrNull() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/valueOfOrNull.kt");
}
@Test
@TestMetadata("weakHashMap.kt")
public void testWeakHashMap() throws Exception {
@@ -5020,7 +5073,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/reinitializations")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Reinitializations extends AbstractFirDiagnosticsWithLightTreeTest {
public class Reinitializations {
@Test
public void testAllFilesPresentInReinitializations() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/reinitializations"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -5037,7 +5090,7 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/smartcasts")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Smartcasts extends AbstractFirDiagnosticsWithLightTreeTest {
public class Smartcasts {
@Test
public void testAllFilesPresentInSmartcasts() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/smartcasts"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.expressions.FirFunctionCall
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
import org.jetbrains.kotlin.fir.expressions.FirStatement
import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment
import org.jetbrains.kotlin.fir.expressions.FirTryExpression
import java.io.File
fun main(args: Array<String>) {
@@ -21,6 +22,7 @@ fun main(args: Array<String>) {
alias<FirQualifiedAccessExpression>("QualifiedAccessChecker")
alias<FirFunctionCall>("FunctionCallChecker")
alias<FirVariableAssignment>("VariableAssignmentChecker")
alias<FirTryExpression>("TryExpressionChecker")
}
val declarationPackage = "org.jetbrains.kotlin.fir.analysis.checkers.declaration"
@@ -29,6 +31,7 @@ fun main(args: Array<String>) {
alias<FirMemberDeclaration>("MemberDeclarationChecker")
alias<FirFunction<*>>("FunctionChecker")
alias<FirProperty>("PropertyChecker")
alias<FirClass<*>>("ClassChecker")
alias<FirRegularClass>("RegularClassChecker")
alias<FirConstructor>("ConstructorChecker")
alias<FirFile>("FileChecker")
@@ -23,6 +23,8 @@ internal class ComposedDeclarationCheckers : DeclarationCheckers() {
get() = _functionCheckers
override val propertyCheckers: Set<FirPropertyChecker>
get() = _propertyCheckers
override val classCheckers: Set<FirClassChecker>
get() = _classCheckers
override val regularClassCheckers: Set<FirRegularClassChecker>
get() = _regularClassCheckers
override val constructorCheckers: Set<FirConstructorChecker>
@@ -38,6 +40,7 @@ internal class ComposedDeclarationCheckers : DeclarationCheckers() {
private val _memberDeclarationCheckers: MutableSet<FirMemberDeclarationChecker> = mutableSetOf()
private val _functionCheckers: MutableSet<FirFunctionChecker> = mutableSetOf()
private val _propertyCheckers: MutableSet<FirPropertyChecker> = mutableSetOf()
private val _classCheckers: MutableSet<FirClassChecker> = mutableSetOf()
private val _regularClassCheckers: MutableSet<FirRegularClassChecker> = mutableSetOf()
private val _constructorCheckers: MutableSet<FirConstructorChecker> = mutableSetOf()
private val _fileCheckers: MutableSet<FirFileChecker> = mutableSetOf()
@@ -50,6 +53,7 @@ internal class ComposedDeclarationCheckers : DeclarationCheckers() {
_memberDeclarationCheckers += checkers.allMemberDeclarationCheckers
_functionCheckers += checkers.allFunctionCheckers
_propertyCheckers += checkers.allPropertyCheckers
_classCheckers += checkers.allClassCheckers
_regularClassCheckers += checkers.allRegularClassCheckers
_constructorCheckers += checkers.allConstructorCheckers
_fileCheckers += checkers.allFileCheckers
@@ -23,6 +23,7 @@ abstract class DeclarationCheckers {
open val memberDeclarationCheckers: Set<FirMemberDeclarationChecker> = emptySet()
open val functionCheckers: Set<FirFunctionChecker> = emptySet()
open val propertyCheckers: Set<FirPropertyChecker> = emptySet()
open val classCheckers: Set<FirClassChecker> = emptySet()
open val regularClassCheckers: Set<FirRegularClassChecker> = emptySet()
open val constructorCheckers: Set<FirConstructorChecker> = emptySet()
open val fileCheckers: Set<FirFileChecker> = emptySet()
@@ -34,7 +35,8 @@ abstract class DeclarationCheckers {
@CheckersComponentInternal internal val allMemberDeclarationCheckers: Set<FirMemberDeclarationChecker> get() = memberDeclarationCheckers + allBasicDeclarationCheckers
@CheckersComponentInternal internal val allFunctionCheckers: Set<FirFunctionChecker> get() = functionCheckers + allBasicDeclarationCheckers
@CheckersComponentInternal internal val allPropertyCheckers: Set<FirPropertyChecker> get() = propertyCheckers + allMemberDeclarationCheckers
@CheckersComponentInternal internal val allRegularClassCheckers: Set<FirRegularClassChecker> get() = regularClassCheckers + allMemberDeclarationCheckers
@CheckersComponentInternal internal val allClassCheckers: Set<FirClassChecker> get() = classCheckers + allBasicDeclarationCheckers
@CheckersComponentInternal internal val allRegularClassCheckers: Set<FirRegularClassChecker> get() = regularClassCheckers + allMemberDeclarationCheckers + allClassCheckers
@CheckersComponentInternal internal val allConstructorCheckers: Set<FirConstructorChecker> get() = constructorCheckers + allFunctionCheckers
@CheckersComponentInternal internal val allFileCheckers: Set<FirFileChecker> get() = fileCheckers + allBasicDeclarationCheckers
}
@@ -10,6 +10,7 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration
* DO NOT MODIFY IT MANUALLY
*/
import org.jetbrains.kotlin.fir.declarations.FirClass
import org.jetbrains.kotlin.fir.declarations.FirConstructor
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
import org.jetbrains.kotlin.fir.declarations.FirFile
@@ -22,6 +23,7 @@ typealias FirBasicDeclarationChecker = FirDeclarationChecker<FirDeclaration>
typealias FirMemberDeclarationChecker = FirDeclarationChecker<FirMemberDeclaration>
typealias FirFunctionChecker = FirDeclarationChecker<FirFunction<*>>
typealias FirPropertyChecker = FirDeclarationChecker<FirProperty>
typealias FirClassChecker = FirDeclarationChecker<FirClass<*>>
typealias FirRegularClassChecker = FirDeclarationChecker<FirRegularClass>
typealias FirConstructorChecker = FirDeclarationChecker<FirConstructor>
typealias FirFileChecker = FirDeclarationChecker<FirFile>
@@ -21,11 +21,14 @@ internal class ComposedExpressionCheckers : ExpressionCheckers() {
get() = _functionCallCheckers
override val variableAssignmentCheckers: Set<FirVariableAssignmentChecker>
get() = _variableAssignmentCheckers
override val tryExpressionCheckers: Set<FirTryExpressionChecker>
get() = _tryExpressionCheckers
private val _basicExpressionCheckers: MutableSet<FirBasicExpressionChecker> = mutableSetOf()
private val _qualifiedAccessCheckers: MutableSet<FirQualifiedAccessChecker> = mutableSetOf()
private val _functionCallCheckers: MutableSet<FirFunctionCallChecker> = mutableSetOf()
private val _variableAssignmentCheckers: MutableSet<FirVariableAssignmentChecker> = mutableSetOf()
private val _tryExpressionCheckers: MutableSet<FirTryExpressionChecker> = mutableSetOf()
@CheckersComponentInternal
internal fun register(checkers: ExpressionCheckers) {
@@ -33,5 +36,6 @@ internal class ComposedExpressionCheckers : ExpressionCheckers() {
_qualifiedAccessCheckers += checkers.allQualifiedAccessCheckers
_functionCallCheckers += checkers.allFunctionCallCheckers
_variableAssignmentCheckers += checkers.allVariableAssignmentCheckers
_tryExpressionCheckers += checkers.allTryExpressionCheckers
}
}
@@ -21,9 +21,11 @@ abstract class ExpressionCheckers {
open val qualifiedAccessCheckers: Set<FirQualifiedAccessChecker> = emptySet()
open val functionCallCheckers: Set<FirFunctionCallChecker> = emptySet()
open val variableAssignmentCheckers: Set<FirVariableAssignmentChecker> = emptySet()
open val tryExpressionCheckers: Set<FirTryExpressionChecker> = emptySet()
@CheckersComponentInternal internal val allBasicExpressionCheckers: Set<FirBasicExpressionChecker> get() = basicExpressionCheckers
@CheckersComponentInternal internal val allQualifiedAccessCheckers: Set<FirQualifiedAccessChecker> get() = qualifiedAccessCheckers + allBasicExpressionCheckers
@CheckersComponentInternal internal val allFunctionCallCheckers: Set<FirFunctionCallChecker> get() = functionCallCheckers + allQualifiedAccessCheckers
@CheckersComponentInternal internal val allVariableAssignmentCheckers: Set<FirVariableAssignmentChecker> get() = variableAssignmentCheckers + allBasicExpressionCheckers
@CheckersComponentInternal internal val allTryExpressionCheckers: Set<FirTryExpressionChecker> get() = tryExpressionCheckers + allBasicExpressionCheckers
}
@@ -13,9 +13,11 @@ package org.jetbrains.kotlin.fir.analysis.checkers.expression
import org.jetbrains.kotlin.fir.expressions.FirFunctionCall
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
import org.jetbrains.kotlin.fir.expressions.FirStatement
import org.jetbrains.kotlin.fir.expressions.FirTryExpression
import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment
typealias FirBasicExpressionChecker = FirExpressionChecker<FirStatement>
typealias FirQualifiedAccessChecker = FirExpressionChecker<FirQualifiedAccessExpression>
typealias FirFunctionCallChecker = FirExpressionChecker<FirFunctionCall>
typealias FirVariableAssignmentChecker = FirExpressionChecker<FirVariableAssignment>
typealias FirTryExpressionChecker = FirExpressionChecker<FirTryExpression>
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.fir.analysis.cfa
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.CFGNode
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.ControlFlowGraph
@@ -15,6 +16,7 @@ abstract class AbstractFirPropertyInitializationChecker {
graph: ControlFlowGraph,
reporter: DiagnosticReporter,
data: Map<CFGNode<*>, PathAwarePropertyInitializationInfo>,
properties: Set<FirPropertySymbol>
properties: Set<FirPropertySymbol>,
context: CheckerContext
)
}
}
@@ -43,7 +43,7 @@ import kotlin.contracts.contract
object FirCallsEffectAnalyzer : FirControlFlowChecker() {
override fun analyze(graph: ControlFlowGraph, reporter: DiagnosticReporter, checkerContext: CheckerContext) {
override fun analyze(graph: ControlFlowGraph, reporter: DiagnosticReporter, context: CheckerContext) {
val function = (graph.declaration as? FirFunction<*>) ?: return
if (function !is FirContractDescriptionOwner) return
if (function.contractDescription.coneEffects?.any { it is ConeCallsEffectDeclaration } != true) return
@@ -73,10 +73,10 @@ object FirCallsEffectAnalyzer : FirControlFlowChecker() {
for ((symbol, leakedPlaces) in leakedSymbols) {
function.contractDescription.source?.let {
reporter.report(FirErrors.LEAKED_IN_PLACE_LAMBDA.on(it, symbol))
reporter.report(FirErrors.LEAKED_IN_PLACE_LAMBDA.on(it, symbol), context)
}
leakedPlaces.forEach {
reporter.report(FirErrors.LEAKED_IN_PLACE_LAMBDA.on(it, symbol))
reporter.report(FirErrors.LEAKED_IN_PLACE_LAMBDA.on(it, symbol), context)
}
}
@@ -91,7 +91,7 @@ object FirCallsEffectAnalyzer : FirControlFlowChecker() {
val requiredRange = effectDeclaration.kind
val pathAwareInfo = invocationData.getValue(node)
for (info in pathAwareInfo.values) {
if (investigate(info, symbol, requiredRange, function, reporter)) {
if (investigate(info, symbol, requiredRange, function, reporter, context)) {
// To avoid duplicate reports, stop investigating remaining paths once reported.
break
}
@@ -105,12 +105,13 @@ object FirCallsEffectAnalyzer : FirControlFlowChecker() {
symbol: AbstractFirBasedSymbol<*>,
requiredRange: EventOccurrencesRange,
function: FirContractDescriptionOwner,
reporter: DiagnosticReporter
reporter: DiagnosticReporter,
context: CheckerContext
): Boolean {
val foundRange = info[symbol] ?: EventOccurrencesRange.ZERO
if (foundRange !in requiredRange) {
function.contractDescription.source?.let {
reporter.report(FirErrors.WRONG_INVOCATION_KIND.on(it, symbol, requiredRange, foundRange))
reporter.report(FirErrors.WRONG_INVOCATION_KIND.on(it, symbol, requiredRange, foundRange), context)
return true
}
}
@@ -29,27 +29,32 @@ class FirControlFlowAnalyzer(session: FirSession) {
cfaCheckers.forEach { it.analyze(graph, reporter, context) }
if (context.containingDeclarations.any { it is FirProperty || it is FirFunction<*> }) return
runAssignmentCfaCheckers(graph, reporter)
runAssignmentCfaCheckers(graph, reporter, context)
}
fun analyzePropertyInitializer(property: FirProperty, graph: ControlFlowGraph, context: CheckerContext, reporter: DiagnosticReporter) {
if (graph.owner != null) return
cfaCheckers.forEach { it.analyze(graph, reporter, context) }
runAssignmentCfaCheckers(graph, reporter)
runAssignmentCfaCheckers(graph, reporter, context)
}
fun analyzePropertyAccessor(accessor: FirPropertyAccessor, graph: ControlFlowGraph, context: CheckerContext, reporter: DiagnosticReporter) {
fun analyzePropertyAccessor(
accessor: FirPropertyAccessor,
graph: ControlFlowGraph,
context: CheckerContext,
reporter: DiagnosticReporter
) {
if (graph.owner != null) return
cfaCheckers.forEach { it.analyze(graph, reporter, context) }
runAssignmentCfaCheckers(graph, reporter)
runAssignmentCfaCheckers(graph, reporter, context)
}
private fun runAssignmentCfaCheckers(graph: ControlFlowGraph, reporter: DiagnosticReporter) {
private fun runAssignmentCfaCheckers(graph: ControlFlowGraph, reporter: DiagnosticReporter, context: CheckerContext) {
val properties = LocalPropertyCollector.collect(graph)
if (properties.isEmpty()) return
val data = PropertyInitializationInfoCollector(properties).getData(graph)
variableAssignmentCheckers.forEach { it.analyze(graph, reporter, data, properties) }
variableAssignmentCheckers.forEach { it.analyze(graph, reporter, data, properties, context) }
}
}
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.analysis.cfa
import org.jetbrains.kotlin.contracts.description.EventOccurrencesRange
import org.jetbrains.kotlin.contracts.description.isDefinitelyVisited
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.declarations.isLateInit
@@ -23,7 +24,8 @@ object FirPropertyInitializationAnalyzer : AbstractFirPropertyInitializationChec
graph: ControlFlowGraph,
reporter: DiagnosticReporter,
data: Map<CFGNode<*>, PathAwarePropertyInitializationInfo>,
properties: Set<FirPropertySymbol>
properties: Set<FirPropertySymbol>,
context: CheckerContext
) {
val localData = data.filter {
val symbolFir = (it.key.fir as? FirVariableSymbol<*>)?.fir
@@ -32,14 +34,15 @@ object FirPropertyInitializationAnalyzer : AbstractFirPropertyInitializationChec
val localProperties = properties.filter { it.fir.initializer == null && it.fir.delegate == null }.toSet()
val reporterVisitor = UninitializedPropertyReporter(localData, localProperties, reporter)
val reporterVisitor = UninitializedPropertyReporter(localData, localProperties, reporter, context)
graph.traverse(TraverseDirection.Forward, reporterVisitor)
}
private class UninitializedPropertyReporter(
val data: Map<CFGNode<*>, PathAwarePropertyInitializationInfo>,
val localProperties: Set<FirPropertySymbol>,
val reporter: DiagnosticReporter
val reporter: DiagnosticReporter,
val context: CheckerContext
) : ControlFlowGraphVisitorVoid() {
override fun visitNode(node: CFGNode<*>) {}
@@ -61,7 +64,7 @@ object FirPropertyInitializationAnalyzer : AbstractFirPropertyInitializationChec
val kind = info[symbol] ?: EventOccurrencesRange.ZERO
if (!kind.isDefinitelyVisited()) {
node.fir.source?.let {
reporter.report(FirErrors.UNINITIALIZED_VARIABLE.on(it, symbol))
reporter.report(FirErrors.UNINITIALIZED_VARIABLE.on(it, symbol), context)
return true
}
}
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.utils.addIfNotNull
object FirReturnsImpliesAnalyzer : FirControlFlowChecker() {
override fun analyze(graph: ControlFlowGraph, reporter: DiagnosticReporter, checkerContext: CheckerContext) {
override fun analyze(graph: ControlFlowGraph, reporter: DiagnosticReporter, context: CheckerContext) {
val function = graph.declaration as? FirFunction<*> ?: return
val graphRef = function.controlFlowGraphReference as FirControlFlowGraphReferenceImpl
val dataFlowInfo = graphRef.dataFlowInfo
@@ -62,7 +62,7 @@ object FirReturnsImpliesAnalyzer : FirControlFlowChecker() {
if (wrongCondition) {
function.contractDescription.source?.let {
reporter.report(FirErrors.WRONG_IMPLIES_CONDITION.on(it))
reporter.report(FirErrors.WRONG_IMPLIES_CONDITION.on(it), context)
}
}
}
@@ -215,4 +215,4 @@ object FirReturnsImpliesAnalyzer : FirControlFlowChecker() {
private fun FirFunction<*>.getParameterSymbol(index: Int): AbstractFirBasedSymbol<*> {
return if (index == -1) this.symbol else this.valueParameters[index].symbol
}
}
}
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.FirSymbolOwner
import org.jetbrains.kotlin.fir.analysis.cfa.FirReturnsImpliesAnalyzer.isSupertypeOf
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.modalityModifier
import org.jetbrains.kotlin.fir.analysis.diagnostics.overrideModifier
@@ -22,21 +23,22 @@ import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
import org.jetbrains.kotlin.fir.expressions.impl.FirEmptyExpressionBlock
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
import org.jetbrains.kotlin.fir.resolve.firSymbolProvider
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import org.jetbrains.kotlin.fir.resolve.toSymbol
import org.jetbrains.kotlin.fir.resolve.transformers.firClassLike
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
import org.jetbrains.kotlin.fir.scopes.processOverriddenFunctions
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.typeCheckerContext
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtModifierList
import org.jetbrains.kotlin.psi.KtObjectLiteralExpression
import org.jetbrains.kotlin.psi.psiUtil.visibilityModifierType
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
@@ -317,3 +319,8 @@ fun Modality.toToken(): KtModifierKeywordToken = when (this) {
val FirFunctionCall.isIterator
get() = this.calleeReference.name.asString() == "<iterator>"
internal fun throwableClassLikeType(session: FirSession) = session.builtinTypes.throwableType.type
fun ConeKotlinType.isSubtypeOfThrowable(session: FirSession) =
throwableClassLikeType(session).isSupertypeOf(session.typeCheckerContext, this.fullyExpandedType(session))
@@ -10,5 +10,5 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.ControlFlowGraph
abstract class FirControlFlowChecker {
abstract fun analyze(graph: ControlFlowGraph, reporter: DiagnosticReporter, checkerContext: CheckerContext)
}
abstract fun analyze(graph: ControlFlowGraph, reporter: DiagnosticReporter, context: CheckerContext)
}
@@ -6,13 +6,16 @@
package org.jetbrains.kotlin.fir.analysis.checkers.context
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.PersistentSet
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.persistentSetOf
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
import org.jetbrains.kotlin.fir.resolve.ImplicitReceiverStack
import org.jetbrains.kotlin.fir.resolve.PersistentImplicitReceiverStack
import org.jetbrains.kotlin.fir.resolve.SessionHolder
import org.jetbrains.kotlin.fir.resolve.calls.ImplicitReceiverValue
import org.jetbrains.kotlin.fir.resolve.calls.InapplicableArgumentDiagnostic
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator
import org.jetbrains.kotlin.name.Name
@@ -21,6 +24,10 @@ abstract class CheckerContext {
abstract val containingDeclarations: List<FirDeclaration>
abstract val sessionHolder: SessionHolder
abstract val returnTypeCalculator: ReturnTypeCalculator
abstract val suppressedDiagnostics: Set<String>
abstract val allInfosSuppressed: Boolean
abstract val allWarningsSuppressed: Boolean
abstract val allErrorsSuppressed: Boolean
val session: FirSession
get() = sessionHolder.session
@@ -38,17 +45,25 @@ abstract class CheckerContext {
}
}
class PersistentCheckerContext(
override val implicitReceiverStack: PersistentImplicitReceiverStack = PersistentImplicitReceiverStack(),
override val containingDeclarations: PersistentList<FirDeclaration> = persistentListOf(),
class PersistentCheckerContext private constructor(
override val implicitReceiverStack: PersistentImplicitReceiverStack,
override val containingDeclarations: PersistentList<FirDeclaration>,
override val sessionHolder: SessionHolder,
override val returnTypeCalculator: ReturnTypeCalculator,
override val suppressedDiagnostics: PersistentSet<String>,
override val allInfosSuppressed: Boolean,
override val allWarningsSuppressed: Boolean,
override val allErrorsSuppressed: Boolean
) : CheckerContext() {
constructor(sessionHolder: SessionHolder, returnTypeCalculator: ReturnTypeCalculator) : this(
PersistentImplicitReceiverStack(),
persistentListOf(),
sessionHolder,
returnTypeCalculator
returnTypeCalculator,
persistentSetOf(),
allInfosSuppressed = false,
allWarningsSuppressed = false,
allErrorsSuppressed = false
)
fun addImplicitReceiver(name: Name?, value: ImplicitReceiverValue<*>): PersistentCheckerContext {
@@ -56,7 +71,11 @@ class PersistentCheckerContext(
implicitReceiverStack.add(name, value),
containingDeclarations,
sessionHolder,
returnTypeCalculator
returnTypeCalculator,
suppressedDiagnostics,
allInfosSuppressed,
allWarningsSuppressed,
allErrorsSuppressed
)
}
@@ -65,7 +84,30 @@ class PersistentCheckerContext(
implicitReceiverStack,
containingDeclarations.add(declaration),
sessionHolder,
returnTypeCalculator
returnTypeCalculator,
suppressedDiagnostics,
allInfosSuppressed,
allWarningsSuppressed,
allErrorsSuppressed
)
}
fun addSuppressedDiagnostics(
diagnosticNames: Collection<String>,
allInfosSuppressed: Boolean,
allWarningsSuppressed: Boolean,
allErrorsSuppressed: Boolean
): PersistentCheckerContext {
if (diagnosticNames.isEmpty()) return this
return PersistentCheckerContext(
implicitReceiverStack,
containingDeclarations,
sessionHolder,
returnTypeCalculator,
suppressedDiagnostics.addAll(diagnosticNames),
this.allInfosSuppressed || allInfosSuppressed,
this.allWarningsSuppressed || allWarningsSuppressed,
this.allErrorsSuppressed || allErrorsSuppressed
)
}
}
@@ -5,21 +5,24 @@
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.fir.FirAnnotationContainer
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.FirSymbolOwner
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticFactory0
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
import org.jetbrains.kotlin.fir.resolve.toSymbol
import org.jetbrains.kotlin.fir.scopes.impl.FirIntegerOperatorCall
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.name.Name
@@ -36,8 +39,8 @@ object FirAnnotationArgumentChecker : FirBasicDeclarationChecker() {
for ((arg, _) in declarationOfAnnotation.argumentMapping ?: continue) {
val expression = (arg as? FirNamedArgumentExpression)?.expression ?: arg
checkAnnotationArgumentWithSubElements(expression, context.session, reporter)
?.let { reporter.report(expression.source, it) }
checkAnnotationArgumentWithSubElements(expression, context.session, reporter, context)
?.let { reporter.reportOn(expression.source, it, context) }
}
}
}
@@ -45,7 +48,8 @@ object FirAnnotationArgumentChecker : FirBasicDeclarationChecker() {
private fun checkAnnotationArgumentWithSubElements(
expression: FirExpression,
session: FirSession,
reporter: DiagnosticReporter
reporter: DiagnosticReporter,
context: CheckerContext
): FirDiagnosticFactory0<FirSourceElement, KtExpression>? {
when (expression) {
is FirArrayOfCall -> {
@@ -54,13 +58,13 @@ object FirAnnotationArgumentChecker : FirBasicDeclarationChecker() {
for (arg in expression.argumentList.arguments) {
val sourceForReport = arg.source
when (val err = checkAnnotationArgumentWithSubElements(arg, session, reporter)) {
when (val err = checkAnnotationArgumentWithSubElements(arg, session, reporter, context)) {
null -> {
//DO NOTHING
}
else -> {
if (err != FirErrors.ANNOTATION_ARGUMENT_MUST_BE_KCLASS_LITERAL) usedNonConst = true
reporter.report(sourceForReport, err)
reporter.reportOn(sourceForReport, err, context)
}
}
}
@@ -69,8 +73,8 @@ object FirAnnotationArgumentChecker : FirBasicDeclarationChecker() {
}
is FirVarargArgumentsExpression -> {
for (arg in expression.arguments)
checkAnnotationArgumentWithSubElements(arg, session, reporter)
?.let { reporter.report(arg.source, it) }
checkAnnotationArgumentWithSubElements(arg, session, reporter, context)
?.let { reporter.reportOn(arg.source, it, context) }
}
else ->
return checkAnnotationArgument(expression, session)
@@ -224,14 +228,7 @@ object FirAnnotationArgumentChecker : FirBasicDeclarationChecker() {
?.toSymbol(session)
?.fir
private inline fun <reified T : FirSourceElement, P : PsiElement> DiagnosticReporter.report(
source: T?,
factory: FirDiagnosticFactory0<T, P>
) {
source?.let { report(factory.on(it)) }
}
private val CONVERSION_NAMES = listOf(
"toInt", "toLong", "toShort", "toByte", "toFloat", "toDouble", "toChar", "toBoolean"
).mapTo(hashSetOf()) { Name.identifier(it) }
}
}
@@ -5,28 +5,26 @@
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.KtNodeTypes.FUN
import org.jetbrains.kotlin.KtNodeTypes.VALUE_PARAMETER
import org.jetbrains.kotlin.descriptors.ClassKind.ANNOTATION_CLASS
import org.jetbrains.kotlin.descriptors.ClassKind.ENUM_CLASS
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.*
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.resolve.toSymbol
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
import org.jetbrains.kotlin.fir.symbols.StandardClassIds.primitiveArrayTypeByElementType
import org.jetbrains.kotlin.fir.symbols.StandardClassIds.primitiveTypes
import org.jetbrains.kotlin.fir.symbols.StandardClassIds.unsignedTypes
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.KtNodeTypes.FUN
import org.jetbrains.kotlin.KtNodeTypes.VALUE_PARAMETER
import org.jetbrains.kotlin.fir.analysis.diagnostics.*
import org.jetbrains.kotlin.name.ClassId
object FirAnnotationClassDeclarationChecker : FirRegularClassChecker() {
override fun check(declaration: FirRegularClass, context: CheckerContext, reporter: DiagnosticReporter) {
if (declaration.classKind != ANNOTATION_CLASS) return
if (declaration.isLocal) reporter.report(declaration.source, FirErrors.LOCAL_ANNOTATION_CLASS_ERROR)
if (declaration.isLocal) reporter.reportOn(declaration.source, FirErrors.LOCAL_ANNOTATION_CLASS_ERROR, context)
for (it in declaration.declarations) {
when {
@@ -34,9 +32,9 @@ object FirAnnotationClassDeclarationChecker : FirRegularClassChecker() {
for (parameter in it.valueParameters) {
val source = parameter.source ?: continue
if (!source.hasValOrVar()) {
reporter.report(source, FirErrors.MISSING_VAL_ON_ANNOTATION_PARAMETER)
reporter.reportOn(source, FirErrors.MISSING_VAL_ON_ANNOTATION_PARAMETER, context)
} else if (source.hasVar()) {
reporter.report(source, FirErrors.VAR_ANNOTATION_PARAMETER)
reporter.reportOn(source, FirErrors.VAR_ANNOTATION_PARAMETER, context)
}
val typeRef = parameter.returnTypeRef
@@ -48,7 +46,7 @@ object FirAnnotationClassDeclarationChecker : FirRegularClassChecker() {
// TODO: replace with UNRESOLVED_REFERENCE check
}
coneType.isNullable -> {
reporter.report(typeRef.source, FirErrors.NULLABLE_TYPE_OF_ANNOTATION_MEMBER)
reporter.reportOn(typeRef.source, FirErrors.NULLABLE_TYPE_OF_ANNOTATION_MEMBER, context)
}
classId in primitiveTypes -> {
// DO NOTHING: primitives are allowed as annotation class parameter
@@ -67,13 +65,13 @@ object FirAnnotationClassDeclarationChecker : FirRegularClassChecker() {
}
classId == StandardClassIds.Array -> {
if (!isAllowedArray(typeRef, context.session))
reporter.report(typeRef.source, FirErrors.INVALID_TYPE_OF_ANNOTATION_MEMBER)
reporter.reportOn(typeRef.source, FirErrors.INVALID_TYPE_OF_ANNOTATION_MEMBER, context)
}
isAllowedClassKind(coneType, context.session) -> {
// DO NOTHING: annotation or enum classes are allowed
}
else -> {
reporter.report(typeRef.source, FirErrors.INVALID_TYPE_OF_ANNOTATION_MEMBER)
reporter.reportOn(typeRef.source, FirErrors.INVALID_TYPE_OF_ANNOTATION_MEMBER, context)
}
}
}
@@ -89,7 +87,7 @@ object FirAnnotationClassDeclarationChecker : FirRegularClassChecker() {
// TODO: replace with origin check
}
else -> {
reporter.report(it.source, FirErrors.ANNOTATION_CLASS_MEMBER)
reporter.reportOn(it.source, FirErrors.ANNOTATION_CLASS_MEMBER, context)
}
}
}
@@ -134,11 +132,4 @@ object FirAnnotationClassDeclarationChecker : FirRegularClassChecker() {
return false
}
private inline fun <reified T : FirSourceElement, P : PsiElement> DiagnosticReporter.report(
source: T?,
factory: FirDiagnosticFactory0<T, P>
) {
source?.let { report(factory.on(it)) }
}
}
@@ -6,10 +6,10 @@
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.FirConstructor
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
@@ -47,9 +47,9 @@ object FirCommonConstructorDelegationIssuesChecker : FirRegularClassChecker() {
for (it in otherConstructors) {
if (it.delegatedConstructor?.isThis != true) {
if (it.delegatedConstructor?.source != null) {
reporter.reportPrimaryConstructorDelegationCallExpected(it.delegatedConstructor?.source)
reporter.reportOn(it.delegatedConstructor?.source, FirErrors.PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED, context)
} else {
reporter.reportPrimaryConstructorDelegationCallExpected(it.source)
reporter.reportOn(it.source, FirErrors.PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED, context)
}
}
}
@@ -62,13 +62,13 @@ object FirCommonConstructorDelegationIssuesChecker : FirRegularClassChecker() {
callee is FirErrorNamedReference && callee.diagnostic is ConeAmbiguityError &&
it.delegatedConstructor?.source?.kind is FirFakeSourceElementKind
) {
reporter.reportExplicitDelegationCallRequired(it.source)
reporter.reportOn(it.source, FirErrors.EXPLICIT_DELEGATION_CALL_REQUIRED, context)
}
}
}
cyclicConstructors.forEach {
reporter.reportCyclicConstructorDelegationCall(it.delegatedConstructor?.source)
reporter.reportOn(it.delegatedConstructor?.source, FirErrors.CYCLIC_CONSTRUCTOR_DELEGATION_CALL, context)
}
}
@@ -95,16 +95,4 @@ object FirCommonConstructorDelegationIssuesChecker : FirRegularClassChecker() {
?.calleeReference.safeAs<FirResolvedNamedReference>()
?.resolvedSymbol
?.fir.safeAs()
private fun DiagnosticReporter.reportCyclicConstructorDelegationCall(source: FirSourceElement?) {
source?.let { report(FirErrors.CYCLIC_CONSTRUCTOR_DELEGATION_CALL.on(it)) }
}
private fun DiagnosticReporter.reportPrimaryConstructorDelegationCallExpected(source: FirSourceElement?) {
source?.let { report(FirErrors.PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED.on(it)) }
}
private fun DiagnosticReporter.reportExplicitDelegationCallRequired(source: FirSourceElement?) {
source?.let { report(FirErrors.EXPLICIT_DELEGATION_CALL_REQUIRED.on(it)) }
}
}
}
@@ -5,10 +5,10 @@
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.resolve.toSymbol
import org.jetbrains.kotlin.fir.types.*
@@ -35,7 +35,7 @@ object FirConflictingProjectionChecker : FirBasicDeclarationChecker() {
is FirTypeAlias -> {
for (it in declaration.typeParameters) {
if (it.variance != Variance.INVARIANT) {
reporter.reportVarianceNotAllowed(it.source)
reporter.reportOn(it.source, FirErrors.VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED, context)
}
}
checkTypeRef(declaration.expandedTypeRef, context, reporter)
@@ -70,17 +70,9 @@ object FirConflictingProjectionChecker : FirBasicDeclarationChecker() {
actual is ConeKotlinTypeProjectionIn && protoVariance == Variance.OUT_VARIANCE ||
actual is ConeKotlinTypeProjectionOut && protoVariance == Variance.IN_VARIANCE
) {
reporter.reportConflictingProjections(typeRef.source, typeRef.coneType.toString())
reporter.reportOn(typeRef.source, FirErrors.CONFLICTING_PROJECTION, typeRef.coneType.toString(), context)
return
}
}
}
private fun DiagnosticReporter.reportConflictingProjections(source: FirSourceElement?, desiredProjection: String) {
source?.let { report(FirErrors.CONFLICTING_PROJECTION.on(it, desiredProjection)) }
}
private fun DiagnosticReporter.reportVarianceNotAllowed(source: FirSourceElement?) {
source?.let { report(FirErrors.VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED.on(it)) }
}
}
}
@@ -5,11 +5,11 @@
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.analysis.checkers.FirDeclarationInspector
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
import org.jetbrains.kotlin.fir.declarations.FirFile
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
@@ -25,11 +25,11 @@ object FirConflictsChecker : FirBasicDeclarationChecker() {
}
inspector.functionDeclarations.forEachNonSingle { it, hint ->
reporter.reportConflictingOverloads(it.source, hint)
reporter.reportOn(it.source, FirErrors.CONFLICTING_OVERLOADS, hint, context)
}
inspector.otherDeclarations.forEachNonSingle { it, hint ->
reporter.reportConflictingDeclarations(it.source, hint)
reporter.reportOn(it.source, FirErrors.REDECLARATION, hint, context)
}
}
@@ -56,12 +56,4 @@ object FirConflictsChecker : FirBasicDeclarationChecker() {
inspector.collect(it)
}
}
private fun DiagnosticReporter.reportConflictingOverloads(source: FirSourceElement?, declarations: String) {
source?.let { report(FirErrors.CONFLICTING_OVERLOADS.on(it, declarations)) }
}
private fun DiagnosticReporter.reportConflictingDeclarations(source: FirSourceElement?, declarations: String) {
source?.let { report(FirErrors.REDECLARATION.on(it, declarations)) }
}
}
@@ -5,16 +5,14 @@
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticFactory0
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.*
object FirConstructorAllowedChecker : FirConstructorChecker() {
@@ -26,27 +24,20 @@ object FirConstructorAllowedChecker : FirConstructorChecker() {
return
}
when (containingClass.classKind) {
ClassKind.OBJECT -> reporter.report(source, FirErrors.CONSTRUCTOR_IN_OBJECT)
ClassKind.INTERFACE -> reporter.report(source, FirErrors.CONSTRUCTOR_IN_INTERFACE)
ClassKind.ENUM_ENTRY -> reporter.report(source, FirErrors.CONSTRUCTOR_IN_OBJECT)
ClassKind.OBJECT -> reporter.reportOn(source, FirErrors.CONSTRUCTOR_IN_OBJECT, context)
ClassKind.INTERFACE -> reporter.reportOn(source, FirErrors.CONSTRUCTOR_IN_INTERFACE, context)
ClassKind.ENUM_ENTRY -> reporter.reportOn(source, FirErrors.CONSTRUCTOR_IN_OBJECT, context)
ClassKind.ENUM_CLASS -> if (declaration.visibility != Visibilities.Private) {
reporter.report(source, FirErrors.NON_PRIVATE_CONSTRUCTOR_IN_ENUM)
reporter.reportOn(source, FirErrors.NON_PRIVATE_CONSTRUCTOR_IN_ENUM, context)
}
ClassKind.CLASS -> if (containingClass is FirRegularClass && containingClass.modality == Modality.SEALED &&
declaration.visibility != Visibilities.Private
) {
reporter.report(source, FirErrors.NON_PRIVATE_CONSTRUCTOR_IN_SEALED)
reporter.reportOn(source, FirErrors.NON_PRIVATE_CONSTRUCTOR_IN_SEALED, context)
}
ClassKind.ANNOTATION_CLASS -> {
// DO NOTHING
}
}
}
private inline fun <reified T : FirSourceElement, P : PsiElement> DiagnosticReporter.report(
source: T?,
factory: FirDiagnosticFactory0<T, P>
) {
source?.let { report(factory.on(it)) }
}
}
@@ -5,11 +5,11 @@
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.hasPrimaryConstructor
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.declarations.isInterface
@@ -20,11 +20,7 @@ object FirConstructorInInterfaceChecker : FirRegularClassChecker() {
}
if (declaration.source?.hasPrimaryConstructor() == true) {
reporter.report(declaration.source)
reporter.reportOn(declaration.source, FirErrors.CONSTRUCTOR_IN_INTERFACE, context)
}
}
private fun DiagnosticReporter.report(source: FirSourceElement?) {
source?.let { report(FirErrors.CONSTRUCTOR_IN_INTERFACE.on(it)) }
}
}
}
@@ -8,9 +8,9 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.extended.report
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor
import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef
@@ -25,14 +25,15 @@ internal fun checkExpectDeclarationVisibilityAndBody(
declaration: FirMemberDeclaration,
source: FirSourceElement,
modifierList: FirModifierList?,
reporter: DiagnosticReporter
reporter: DiagnosticReporter,
context: CheckerContext
) {
if (declaration.isExpect || modifierList?.modifiers?.any { it.token == KtTokens.EXPECT_KEYWORD } == true) {
if (Visibilities.isPrivate(declaration.visibility)) {
reporter.report(source, FirErrors.EXPECTED_PRIVATE_DECLARATION)
reporter.reportOn(source, FirErrors.EXPECTED_PRIVATE_DECLARATION, context)
}
if (declaration is FirSimpleFunction && declaration.hasBody) {
reporter.report(source, FirErrors.EXPECTED_DECLARATION_WITH_BODY)
reporter.reportOn(source, FirErrors.EXPECTED_DECLARATION_WITH_BODY, context)
}
}
}
@@ -40,7 +41,8 @@ internal fun checkExpectDeclarationVisibilityAndBody(
internal fun checkPropertyInitializer(
containingClass: FirRegularClass?,
property: FirProperty,
reporter: DiagnosticReporter
reporter: DiagnosticReporter,
context: CheckerContext
) {
val inInterface = containingClass?.isInterface == true
// If multiple (potentially conflicting) modality modifiers are specified, not all modifiers are recorded at `status`.
@@ -51,7 +53,7 @@ internal fun checkPropertyInitializer(
if (isAbstract) {
if (property.initializer == null && property.delegate == null && property.returnTypeRef is FirImplicitTypeRef) {
property.source?.let {
reporter.report(it, FirErrors.PROPERTY_WITH_NO_TYPE_NO_INITIALIZER)
reporter.reportOn(it, FirErrors.PROPERTY_WITH_NO_TYPE_NO_INITIALIZER, context)
}
}
return
@@ -61,7 +63,7 @@ internal fun checkPropertyInitializer(
val backingFieldRequired = property.hasBackingField
if (inInterface && backingFieldRequired && property.hasAccessorImplementation) {
property.source?.let {
// reporter.report(it, FirErrors.BACKING_FIELD_IN_INTERFACE)
// reporter.reportOn(it, FirErrors.BACKING_FIELD_IN_INTERFACE, context)
}
}
@@ -72,16 +74,16 @@ internal fun checkPropertyInitializer(
property.initializer?.source?.let {
when {
inInterface -> {
reporter.report(it, FirErrors.PROPERTY_INITIALIZER_IN_INTERFACE)
reporter.reportOn(it, FirErrors.PROPERTY_INITIALIZER_IN_INTERFACE, context)
}
isExpect -> {
reporter.report(it, FirErrors.EXPECTED_PROPERTY_INITIALIZER)
reporter.reportOn(it, FirErrors.EXPECTED_PROPERTY_INITIALIZER, context)
}
!backingFieldRequired -> {
// reporter.report(it, FirErrors.PROPERTY_INITIALIZER_NO_BACKING_FIELD)
// reporter.reportOn(it, FirErrors.PROPERTY_INITIALIZER_NO_BACKING_FIELD, context)
}
property.receiverTypeRef != null -> {
// reporter.report(it, FirErrors.EXTENSION_PROPERTY_WITH_BACKING_FIELD)
// reporter.reportOn(it, FirErrors.EXTENSION_PROPERTY_WITH_BACKING_FIELD, context)
}
}
}
@@ -90,10 +92,10 @@ internal fun checkPropertyInitializer(
property.delegate?.source?.let {
when {
inInterface -> {
reporter.report(it, FirErrors.DELEGATED_PROPERTY_IN_INTERFACE)
reporter.reportOn(it, FirErrors.DELEGATED_PROPERTY_IN_INTERFACE, context)
}
isExpect -> {
reporter.report(it, FirErrors.EXPECTED_DELEGATED_PROPERTY)
reporter.reportOn(it, FirErrors.EXPECTED_DELEGATED_PROPERTY, context)
}
}
}
@@ -105,12 +107,12 @@ internal fun checkPropertyInitializer(
if (backingFieldRequired && !inInterface && !property.isLateInit && !isExpect && isUninitialized && !isExternal) {
property.source?.let {
if (property.receiverTypeRef != null && !property.hasAccessorImplementation) {
// reporter.report(it, FirErrors.EXTENSION_PROPERTY_MUST_HAVE_ACCESSORS_OR_BE_ABSTRACT)
// reporter.reportOn(it, FirErrors.EXTENSION_PROPERTY_MUST_HAVE_ACCESSORS_OR_BE_ABSTRACT, context)
} else {
if (containingClass != null || property.hasAccessorImplementation) {
// reporter.report(it, FirErrors.MUST_BE_INITIALIZED)
// reporter.reportOn(it, FirErrors.MUST_BE_INITIALIZED, context)
} else {
// reporter.report(it, FirErrors.MUST_BE_INITIALIZED_OR_BE_ABSTRACT)
// reporter.reportOn(it, FirErrors.MUST_BE_INITIALIZED_OR_BE_ABSTRACT, context)
}
}
}
@@ -6,10 +6,10 @@
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.declarations.isInterface
@@ -22,12 +22,8 @@ object FirDelegationInInterfaceChecker : FirRegularClassChecker() {
for (superTypeRef in declaration.superTypeRefs) {
val source = superTypeRef.source ?: continue
if (source.treeStructure.getParent(source.lighterASTNode)?.tokenType == KtNodeTypes.DELEGATED_SUPER_TYPE_ENTRY) {
reporter.report(source)
reporter.reportOn(source, FirErrors.DELEGATION_IN_INTERFACE, context)
}
}
}
private fun DiagnosticReporter.report(source: FirSourceElement?) {
source?.let { report(FirErrors.DELEGATION_IN_INTERFACE.on(it)) }
}
}
}
@@ -6,10 +6,10 @@
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.FirConstructor
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.declarations.isEnumClass
@@ -26,12 +26,8 @@ object FirDelegationSuperCallInEnumConstructorChecker : FirRegularClassChecker()
it.delegatedConstructor?.isThis == false &&
it.delegatedConstructor?.source?.kind !is FirFakeSourceElementKind
) {
reporter.report(it.delegatedConstructor?.source)
reporter.reportOn(it.delegatedConstructor?.source, FirErrors.DELEGATION_SUPER_CALL_IN_ENUM_CONSTRUCTOR, context)
}
}
}
private fun DiagnosticReporter.report(source: FirSourceElement?) {
source?.let { report(FirErrors.DELEGATION_SUPER_CALL_IN_ENUM_CONSTRUCTOR.on(it)) }
}
}
}
@@ -8,9 +8,9 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.extended.report
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.FirProperty
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
@@ -36,7 +36,7 @@ object FirDestructuringDeclarationChecker : FirPropertyChecker() {
assert(declaration.name.isSpecial && declaration.name.asString() == "<destruct>") {
"Unexpected name: ${declaration.name.asString()} for destructuring declaration"
}
checkInitializer(source, declaration.initializer, reporter)
checkInitializer(source, declaration.initializer, reporter, context)
return
}
@@ -82,7 +82,8 @@ object FirDestructuringDeclarationChecker : FirPropertyChecker() {
originalDestructuringDeclarationOrInitializerSource,
diagnostic.name,
originalDestructuringDeclarationType
)
),
context
)
}
is ConeAmbiguityError -> {
@@ -91,7 +92,8 @@ object FirDestructuringDeclarationChecker : FirPropertyChecker() {
originalDestructuringDeclarationOrInitializerSource,
diagnostic.name,
diagnostic.candidates
)
),
context
)
}
is ConeInapplicableCandidateError -> {
@@ -100,7 +102,8 @@ object FirDestructuringDeclarationChecker : FirPropertyChecker() {
FirErrors.COMPONENT_FUNCTION_ON_NULLABLE.on(
originalDestructuringDeclarationOrInitializerSource,
(diagnostic.candidateSymbol.fir as FirSimpleFunction).name
)
),
context
)
}
}
@@ -108,7 +111,12 @@ object FirDestructuringDeclarationChecker : FirPropertyChecker() {
}
}
private fun checkInitializer(source: FirSourceElement, initializer: FirExpression?, reporter: DiagnosticReporter) {
private fun checkInitializer(
source: FirSourceElement,
initializer: FirExpression?,
reporter: DiagnosticReporter,
context: CheckerContext
) {
val needToReport =
when (initializer) {
null -> true
@@ -116,7 +124,7 @@ object FirDestructuringDeclarationChecker : FirPropertyChecker() {
else -> false
}
if (needToReport) {
reporter.report(source, FirErrors.INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION)
reporter.reportOn(source, FirErrors.INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION, context)
}
}
@@ -5,11 +5,11 @@
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.findNonInterfaceSupertype
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.declarations.isEnumClass
@@ -20,19 +20,11 @@ object FirEnumClassSimpleChecker : FirRegularClassChecker() {
}
declaration.findNonInterfaceSupertype(context)?.let {
reporter.reportClassInSupertypeForEnum(it.source)
reporter.reportOn(it.source, FirErrors.CLASS_IN_SUPERTYPE_FOR_ENUM, context)
}
if (declaration.typeParameters.isNotEmpty()) {
reporter.reportTypeParametersInEnum(declaration.typeParameters.firstOrNull()?.source)
reporter.reportOn(declaration.typeParameters.firstOrNull()?.source, FirErrors.TYPE_PARAMETERS_IN_ENUM, context)
}
}
private fun DiagnosticReporter.reportClassInSupertypeForEnum(source: FirSourceElement?) {
source?.let { report(FirErrors.CLASS_IN_SUPERTYPE_FOR_ENUM.on(it)) }
}
private fun DiagnosticReporter.reportTypeParametersInEnum(source: FirSourceElement?) {
source?.let { report(FirErrors.TYPE_PARAMETERS_IN_ENUM.on(it)) }
}
}
}
@@ -5,15 +5,16 @@
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.FirEffectiveVisibility
import org.jetbrains.kotlin.fir.FirEffectiveVisibilityImpl
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.toRegularClass
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticFactory3
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.getEffectiveVisibility
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import org.jetbrains.kotlin.fir.resolve.toSymbol
import org.jetbrains.kotlin.fir.resolve.transformers.ensureResolved
@@ -51,12 +52,13 @@ object FirExposedVisibilityDeclarationChecker : FirMemberDeclarationChecker() {
}
val restricting = supertype.findVisibilityExposure(context, classVisibility)
if (restricting != null) {
reporter.reportExposure(
reporter.reportOn(
supertypeRef.source ?: declaration.source,
if (isInterface) FirErrors.EXPOSED_SUPER_INTERFACE else FirErrors.EXPOSED_SUPER_CLASS,
restricting,
classVisibility,
restricting,
restricting.getEffectiveVisibility(context),
supertypeRef.source ?: declaration.source
context
)
}
}
@@ -70,12 +72,13 @@ object FirExposedVisibilityDeclarationChecker : FirMemberDeclarationChecker() {
for (bound in parameter.symbol.fir.bounds) {
val restricting = bound.coneType.findVisibilityExposure(context, classVisibility)
if (restricting != null) {
reporter.reportExposure(
reporter.reportOn(
bound.source,
FirErrors.EXPOSED_TYPE_PARAMETER_BOUND,
restricting,
classVisibility,
restricting,
restricting.getEffectiveVisibility(context),
bound.source
context
)
}
}
@@ -89,12 +92,13 @@ object FirExposedVisibilityDeclarationChecker : FirMemberDeclarationChecker() {
if (typeAliasVisibility == FirEffectiveVisibilityImpl.Local) return
val restricting = expandedType?.findVisibilityExposure(context, typeAliasVisibility)
if (restricting != null) {
reporter.reportExposure(
reporter.reportOn(
declaration.source,
FirErrors.EXPOSED_TYPEALIAS_EXPANDED_TYPE,
restricting,
typeAliasVisibility,
restricting,
restricting.getEffectiveVisibility(context),
declaration.source
context
)
}
}
@@ -107,12 +111,13 @@ object FirExposedVisibilityDeclarationChecker : FirMemberDeclarationChecker() {
val restricting = declaration.returnTypeRef.coneTypeSafe<ConeKotlinType>()
?.findVisibilityExposure(context, functionVisibility)
if (restricting != null) {
reporter.reportExposure(
reporter.reportOn(
declaration.source,
FirErrors.EXPOSED_FUNCTION_RETURN_TYPE,
restricting,
functionVisibility,
restricting,
restricting.getEffectiveVisibility(context),
declaration.source
context
)
}
}
@@ -122,12 +127,13 @@ object FirExposedVisibilityDeclarationChecker : FirMemberDeclarationChecker() {
valueParameter.returnTypeRef.coneTypeSafe<ConeKotlinType>()
?.findVisibilityExposure(context, functionVisibility)
if (restricting != null) {
reporter.reportExposure(
reporter.reportOn(
valueParameter.source,
FirErrors.EXPOSED_PARAMETER_TYPE,
restricting,
functionVisibility,
restricting,
restricting.getEffectiveVisibility(context),
valueParameter.source
context
)
}
}
@@ -143,12 +149,13 @@ object FirExposedVisibilityDeclarationChecker : FirMemberDeclarationChecker() {
declaration.returnTypeRef.coneTypeSafe<ConeKotlinType>()
?.findVisibilityExposure(context, propertyVisibility)
if (restricting != null) {
reporter.reportExposure(
reporter.reportOn(
declaration.source,
FirErrors.EXPOSED_PROPERTY_TYPE,
restricting,
propertyVisibility,
restricting,
restricting.getEffectiveVisibility(context),
declaration.source
context
)
}
checkMemberReceiver(declaration.receiverTypeRef, declaration, reporter, context)
@@ -167,12 +174,13 @@ object FirExposedVisibilityDeclarationChecker : FirMemberDeclarationChecker() {
if (memberVisibility == FirEffectiveVisibilityImpl.Local) return
val restricting = receiverParameterType.findVisibilityExposure(context, memberVisibility)
if (restricting != null) {
reporter.reportExposure(
reporter.reportOn(
typeRef.source,
FirErrors.EXPOSED_RECEIVER_TYPE,
restricting,
memberVisibility,
restricting,
restricting.getEffectiveVisibility(context),
typeRef.source
context
)
}
}
@@ -207,25 +215,6 @@ object FirExposedVisibilityDeclarationChecker : FirMemberDeclarationChecker() {
return null
}
private inline fun <reified E : FirSourceElement, P : PsiElement> DiagnosticReporter.reportExposure(
error: FirDiagnosticFactory3<E, P, FirEffectiveVisibility, FirMemberDeclaration, FirEffectiveVisibility>,
restrictingDeclaration: FirMemberDeclaration,
elementVisibility: FirEffectiveVisibility,
restrictingVisibility: FirEffectiveVisibility,
source: FirSourceElement?
) {
source?.let {
report(
error.on(
it as E,
elementVisibility,
restrictingDeclaration,
restrictingVisibility
)
)
}
}
private fun FirMemberDeclaration.getEffectiveVisibility(context: CheckerContext) =
getEffectiveVisibility(context.session, context.containingDeclarations, context.sessionHolder.scopeSession)
}
@@ -7,9 +7,9 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.extended.report
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.FirClass
import org.jetbrains.kotlin.fir.declarations.FirFile
import org.jetbrains.kotlin.fir.declarations.FirFunction
@@ -23,7 +23,7 @@ object FirFunctionNameChecker : FirFunctionChecker() {
val containingDeclaration = context.containingDeclarations.lastOrNull()
val isNonLocal = containingDeclaration is FirFile || containingDeclaration is FirClass<*>
if (declaration is FirSimpleFunction && declaration.name == SpecialNames.NO_NAME_PROVIDED && isNonLocal) {
reporter.report(source, FirErrors.FUNCTION_DECLARATION_WITH_NO_NAME)
reporter.reportOn(source, FirErrors.FUNCTION_DECLARATION_WITH_NO_NAME, context)
}
}
}
@@ -10,7 +10,8 @@ import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.FirProperty
import org.jetbrains.kotlin.fir.declarations.isLateInit
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.ConeTypeParameterType
import org.jetbrains.kotlin.fir.types.coneType
@@ -40,28 +41,28 @@ object FirInapplicableLateinitChecker : FirPropertyChecker() {
when {
declaration.isVal ->
reporter.report(declaration.source, "is allowed only on mutable properties")
reporter.reportOn(declaration.source, "is allowed only on mutable properties", context)
declaration.initializer != null -> if (declaration.isLocal) {
reporter.report(declaration.source, "is not allowed on local variables with initializer")
reporter.reportOn(declaration.source, "is not allowed on local variables with initializer", context)
} else {
reporter.report(declaration.source, "is not allowed on properties with initializer")
reporter.reportOn(declaration.source, "is not allowed on properties with initializer", context)
}
declaration.delegate != null ->
reporter.report(declaration.source, "is not allowed on delegated properties")
reporter.reportOn(declaration.source, "is not allowed on delegated properties", context)
declaration.isNullable() ->
reporter.report(declaration.source, "is not allowed on properties of a type with nullable upper bound")
reporter.reportOn(declaration.source, "is not allowed on properties of a type with nullable upper bound", context)
declaration.returnTypeRef.coneType in getPrimitiveTypes(context) -> if (declaration.isLocal) {
reporter.report(declaration.source, "is not allowed on local variables of primitive types")
reporter.reportOn(declaration.source, "is not allowed on local variables of primitive types", context)
} else {
reporter.report(declaration.source, "is not allowed on properties of primitive types")
reporter.reportOn(declaration.source, "is not allowed on properties of primitive types", context)
}
declaration.hasGetter() || declaration.hasSetter() ->
reporter.report(declaration.source, "is not allowed on properties with a custom getter or setter")
reporter.reportOn(declaration.source, "is not allowed on properties with a custom getter or setter", context)
}
}
@@ -73,7 +74,7 @@ object FirInapplicableLateinitChecker : FirPropertyChecker() {
private fun FirProperty.hasGetter() = getter != null && getter?.source != null && getter?.source?.kind !is FirFakeSourceElementKind
private fun FirProperty.hasSetter() = setter != null && setter?.source != null && setter?.source?.kind !is FirFakeSourceElementKind
private fun DiagnosticReporter.report(source: FirSourceElement?, target: String) {
source?.let { report(FirErrors.INAPPLICABLE_LATEINIT_MODIFIER.on(it, target)) }
private fun DiagnosticReporter.reportOn(source: FirSourceElement?, target: String, context: CheckerContext) {
source?.let { report(FirErrors.INAPPLICABLE_LATEINIT_MODIFIER.on(it, target), context) }
}
}
}
@@ -5,10 +5,10 @@
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.FirClass
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
@@ -18,12 +18,12 @@ object FirInfixFunctionDeclarationChecker : FirMemberDeclarationChecker() {
override fun check(declaration: FirMemberDeclaration, context: CheckerContext, reporter: DiagnosticReporter) {
if (declaration is FirSimpleFunction && declaration.isInfix) {
if (declaration.valueParameters.size != 1 || !hasExtensionOrDispatchReceiver(declaration, context)) {
reporter.report(declaration.source)
reporter.reportOn(declaration.source, FirErrors.INAPPLICABLE_INFIX_MODIFIER, context)
}
return
}
if (declaration.isInfix) {
reporter.report(declaration.source)
reporter.reportOn(declaration.source, FirErrors.INAPPLICABLE_INFIX_MODIFIER, context)
}
}
@@ -34,8 +34,4 @@ object FirInfixFunctionDeclarationChecker : FirMemberDeclarationChecker() {
if (function.receiverTypeRef != null) return true
return context.containingDeclarations.lastOrNull() is FirClass<*>
}
private fun DiagnosticReporter.report(source: FirSourceElement?) {
source?.let { report(FirErrors.INAPPLICABLE_INFIX_MODIFIER.on(it, "Inapplicable infix modifier")) }
}
}
@@ -5,11 +5,11 @@
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.findNonInterfaceSupertype
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.declarations.isInterface
@@ -20,11 +20,7 @@ object FirInterfaceWithSuperclassChecker : FirRegularClassChecker() {
}
declaration.findNonInterfaceSupertype(context)?.let {
reporter.report(it.source)
reporter.reportOn(it.source, FirErrors.INTERFACE_WITH_SUPERCLASS, context)
}
}
private fun DiagnosticReporter.report(source: FirSourceElement?) {
source?.let { report(FirErrors.INTERFACE_WITH_SUPERCLASS.on(it)) }
}
}
}
@@ -6,15 +6,14 @@
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.declarations.isCompanion
import org.jetbrains.kotlin.fir.declarations.visibility
import org.jetbrains.kotlin.name.Name
object FirLocalEntityNotAllowedChecker : FirRegularClassChecker() {
override fun check(declaration: FirRegularClass, context: CheckerContext, reporter: DiagnosticReporter) {
@@ -24,19 +23,11 @@ object FirLocalEntityNotAllowedChecker : FirRegularClassChecker() {
when {
declaration.classKind == ClassKind.OBJECT && !declaration.isCompanion ->
reporter.reportLocalObjectNotAllowed(declaration.source, declaration.name)
reporter.reportOn(declaration.source, FirErrors.LOCAL_OBJECT_NOT_ALLOWED, declaration.name, context)
declaration.classKind == ClassKind.INTERFACE ->
reporter.reportLocalInterfaceNotAllowed(declaration.source, declaration.name)
reporter.reportOn(declaration.source, FirErrors.LOCAL_INTERFACE_NOT_ALLOWED, declaration.name, context)
else -> {
}
}
}
private fun DiagnosticReporter.reportLocalObjectNotAllowed(source: FirSourceElement?, name: Name) {
source?.let { report(FirErrors.LOCAL_OBJECT_NOT_ALLOWED.on(it, name)) }
}
private fun DiagnosticReporter.reportLocalInterfaceNotAllowed(source: FirSourceElement?, name: Name) {
source?.let { report(FirErrors.LOCAL_INTERFACE_NOT_ALLOWED.on(it, name)) }
}
}
@@ -5,10 +5,10 @@
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.declarations.isCompanion
@@ -19,14 +19,10 @@ object FirManyCompanionObjectsChecker : FirRegularClassChecker() {
for (it in declaration.declarations) {
if (it is FirRegularClass && it.isCompanion) {
if (hasCompanion) {
reporter.report(it.source)
reporter.reportOn(it.source, FirErrors.MANY_COMPANION_OBJECTS, context)
}
hasCompanion = true
}
}
}
private fun DiagnosticReporter.report(source: FirSourceElement?) {
source?.let { report(FirErrors.MANY_COMPANION_OBJECTS.on(it)) }
}
}
}
@@ -8,9 +8,9 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.extended.report
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.lexer.KtTokens
@@ -39,10 +39,13 @@ object FirMemberFunctionChecker : FirRegularClassChecker() {
val isAbstract = function.isAbstract || hasAbstractModifier
if (isAbstract) {
if (!containingDeclaration.canHaveAbstractDeclaration) {
reporter.report(FirErrors.ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS.on(source, function, containingDeclaration))
reporter.report(
FirErrors.ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS.on(source, function, containingDeclaration),
context
)
}
if (function.hasBody) {
reporter.report(FirErrors.ABSTRACT_FUNCTION_WITH_BODY.on(source, function))
reporter.report(FirErrors.ABSTRACT_FUNCTION_WITH_BODY.on(source, function), context)
}
}
val isInsideExpectClass = isInsideExpectClass(containingDeclaration, context)
@@ -51,17 +54,16 @@ object FirMemberFunctionChecker : FirRegularClassChecker() {
if (!function.hasBody) {
if (containingDeclaration.isInterface) {
if (Visibilities.isPrivate(function.visibility)) {
reporter.report(FirErrors.PRIVATE_FUNCTION_WITH_NO_BODY.on(source, function))
reporter.reportOn(source, FirErrors.PRIVATE_FUNCTION_WITH_NO_BODY, function, context)
}
if (!isInsideExpectClass && !hasAbstractModifier && hasOpenModifier) {
reporter.report(source, FirErrors.REDUNDANT_OPEN_IN_INTERFACE)
reporter.reportOn(source, FirErrors.REDUNDANT_OPEN_IN_INTERFACE, context)
}
} else if (!isInsideExpectClass && !hasAbstractModifier && !isExternal) {
reporter.report(FirErrors.NON_ABSTRACT_FUNCTION_WITH_NO_BODY.on(source, function))
reporter.reportOn(source, FirErrors.NON_ABSTRACT_FUNCTION_WITH_NO_BODY, function, context)
}
}
checkExpectDeclarationVisibilityAndBody(function, source, modifierList, reporter)
checkExpectDeclarationVisibilityAndBody(function, source, modifierList, reporter, context)
}
}
@@ -9,9 +9,9 @@ import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.extended.report
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor
import org.jetbrains.kotlin.fir.expressions.FirExpression
@@ -47,37 +47,43 @@ object FirMemberPropertyChecker : FirRegularClassChecker() {
(property.getter == null || property.getter is FirDefaultPropertyAccessor)
) {
property.source?.let {
reporter.report(it, FirErrors.PRIVATE_PROPERTY_IN_INTERFACE)
reporter.reportOn(it, FirErrors.PRIVATE_PROPERTY_IN_INTERFACE, context)
}
}
if (isAbstract) {
if (!containingDeclaration.canHaveAbstractDeclaration) {
property.source?.let {
reporter.report(FirErrors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS.on(it, property, containingDeclaration))
reporter.reportOn(
it,
FirErrors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS,
property,
containingDeclaration,
context
)
return
}
}
property.initializer?.source?.let {
reporter.report(it, FirErrors.ABSTRACT_PROPERTY_WITH_INITIALIZER)
reporter.reportOn(it, FirErrors.ABSTRACT_PROPERTY_WITH_INITIALIZER, context)
}
property.delegate?.source?.let {
reporter.report(it, FirErrors.ABSTRACT_DELEGATED_PROPERTY)
reporter.reportOn(it, FirErrors.ABSTRACT_DELEGATED_PROPERTY, context)
}
checkAccessor(property.getter, property.delegate) { src, _ ->
reporter.report(src, FirErrors.ABSTRACT_PROPERTY_WITH_GETTER)
reporter.reportOn(src, FirErrors.ABSTRACT_PROPERTY_WITH_GETTER, context)
}
checkAccessor(property.setter, property.delegate) { src, symbol ->
if (symbol.fir.visibility == Visibilities.Private && property.visibility != Visibilities.Private) {
reporter.report(src, FirErrors.PRIVATE_SETTER_FOR_ABSTRACT_PROPERTY)
reporter.reportOn(src, FirErrors.PRIVATE_SETTER_FOR_ABSTRACT_PROPERTY, context)
} else {
reporter.report(src, FirErrors.ABSTRACT_PROPERTY_WITH_SETTER)
reporter.reportOn(src, FirErrors.ABSTRACT_PROPERTY_WITH_SETTER, context)
}
}
}
checkPropertyInitializer(containingDeclaration, property, reporter)
checkPropertyInitializer(containingDeclaration, property, reporter, context)
val hasOpenModifier = modifierList?.modifiers?.any { it.token == KtTokens.OPEN_KEYWORD } == true
if (hasOpenModifier &&
@@ -87,19 +93,19 @@ object FirMemberPropertyChecker : FirRegularClassChecker() {
!isInsideExpectClass(containingDeclaration, context)
) {
property.source?.let {
reporter.report(it, FirErrors.REDUNDANT_OPEN_IN_INTERFACE)
reporter.reportOn(it, FirErrors.REDUNDANT_OPEN_IN_INTERFACE, context)
}
}
val isOpen = property.isOpen || hasOpenModifier
if (isOpen) {
checkAccessor(property.setter, property.delegate) { src, symbol ->
if (symbol.fir.visibility == Visibilities.Private && property.visibility != Visibilities.Private) {
reporter.report(src, FirErrors.PRIVATE_SETTER_FOR_OPEN_PROPERTY)
reporter.reportOn(src, FirErrors.PRIVATE_SETTER_FOR_OPEN_PROPERTY, context)
}
}
}
checkExpectDeclarationVisibilityAndBody(property, source, modifierList, reporter)
checkExpectDeclarationVisibilityAndBody(property, source, modifierList, reporter, context)
}
private fun checkAccessor(
@@ -5,12 +5,12 @@
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.analysis.checkers.FirDeclarationInspector
import org.jetbrains.kotlin.fir.analysis.checkers.FirDeclarationPresenter
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.resolve.firSymbolProvider
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
@@ -64,12 +64,8 @@ object FirMethodOfAnyImplementedInInterfaceChecker : FirRegularClassChecker(), F
val inspector = getInspector(context)
if (it is FirSimpleFunction && inspector.contains(it) && it.body != null && it.isOverride) {
reporter.report(it.source)
reporter.reportOn(it.source, FirErrors.ANY_METHOD_IMPLEMENTED_IN_INTERFACE, context)
}
}
}
private fun DiagnosticReporter.report(source: FirSourceElement?) {
source?.let { report(FirErrors.ANY_METHOD_IMPLEMENTED_IN_INTERFACE.on(it)) }
}
}
}
@@ -6,7 +6,7 @@
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
@@ -103,7 +103,8 @@ object FirModifierChecker : FirBasicDeclarationChecker() {
secondModifier: FirModifier<*>,
reporter: DiagnosticReporter,
reportedNodes: MutableSet<FirModifier<*>>,
owner: FirDeclaration?
owner: FirDeclaration?,
context: CheckerContext
) {
val firstToken = firstModifier.token
val secondToken = secondModifier.token
@@ -111,21 +112,21 @@ object FirModifierChecker : FirBasicDeclarationChecker() {
CompatibilityType.COMPATIBLE -> {
}
CompatibilityType.REPEATED ->
if (reportedNodes.add(secondModifier)) reporter.reportRepeatedModifier(secondModifier, secondToken)
if (reportedNodes.add(secondModifier)) reporter.reportRepeatedModifier(secondModifier, secondToken, context)
CompatibilityType.REDUNDANT_2_TO_1 ->
reporter.reportRedundantModifier(secondModifier, secondToken, firstToken)
reporter.reportRedundantModifier(secondModifier, secondToken, firstToken, context)
CompatibilityType.REDUNDANT_1_TO_2 ->
reporter.reportRedundantModifier(firstModifier, firstToken, secondToken)
reporter.reportRedundantModifier(firstModifier, firstToken, secondToken, context)
CompatibilityType.DEPRECATED -> {
reporter.reportDeprecatedModifierPair(firstModifier, firstToken, secondToken)
reporter.reportDeprecatedModifierPair(secondModifier, secondToken, firstToken)
reporter.reportDeprecatedModifierPair(firstModifier, firstToken, secondToken, context)
reporter.reportDeprecatedModifierPair(secondModifier, secondToken, firstToken, context)
}
CompatibilityType.INCOMPATIBLE, CompatibilityType.COMPATIBLE_FOR_CLASSES -> {
if (compatibilityType == CompatibilityType.COMPATIBLE_FOR_CLASSES && owner is FirClass<*>) {
return
}
if (reportedNodes.add(firstModifier)) reporter.reportIncompatibleModifiers(firstModifier, firstToken, secondToken)
if (reportedNodes.add(secondModifier)) reporter.reportIncompatibleModifiers(secondModifier, secondToken, firstToken)
if (reportedNodes.add(firstModifier)) reporter.reportIncompatibleModifiers(firstModifier, firstToken, secondToken, context)
if (reportedNodes.add(secondModifier)) reporter.reportIncompatibleModifiers(secondModifier, secondToken, firstToken, context)
}
}
}
@@ -133,7 +134,8 @@ object FirModifierChecker : FirBasicDeclarationChecker() {
private fun checkModifiers(
list: FirModifierList,
owner: FirDeclaration,
reporter: DiagnosticReporter
reporter: DiagnosticReporter,
context: CheckerContext
) {
// general strategy: report no more than one error and any number of warnings
// therefore, a track of nodes with already reported errors should be kept
@@ -145,7 +147,7 @@ object FirModifierChecker : FirBasicDeclarationChecker() {
if (firstModifier == secondModifier) {
break
}
checkCompatibilityType(firstModifier, secondModifier, reporter, reportedNodes, owner)
checkCompatibilityType(firstModifier, secondModifier, reporter, reportedNodes, owner, context)
}
}
}
@@ -168,30 +170,30 @@ object FirModifierChecker : FirBasicDeclarationChecker() {
if (context.containingDeclarations.last() is FirDefaultPropertyAccessor) return
val modifierList = with(FirModifierList) { source.getModifierList() }
modifierList?.let { checkModifiers(it, declaration, reporter) }
modifierList?.let { checkModifiers(it, declaration, reporter, context) }
}
private fun DiagnosticReporter.reportRepeatedModifier(
modifier: FirModifier<*>, keyword: KtModifierKeywordToken
modifier: FirModifier<*>, keyword: KtModifierKeywordToken, context: CheckerContext
) {
report(FirErrors.REPEATED_MODIFIER.on(modifier.source, keyword))
report(FirErrors.REPEATED_MODIFIER.on(modifier.source, keyword), context)
}
private fun DiagnosticReporter.reportRedundantModifier(
modifier: FirModifier<*>, firstKeyword: KtModifierKeywordToken, secondKeyword: KtModifierKeywordToken
modifier: FirModifier<*>, firstKeyword: KtModifierKeywordToken, secondKeyword: KtModifierKeywordToken, context: CheckerContext
) {
report(FirErrors.REDUNDANT_MODIFIER.on(modifier.source, firstKeyword, secondKeyword))
report(FirErrors.REDUNDANT_MODIFIER.on(modifier.source, firstKeyword, secondKeyword), context)
}
private fun DiagnosticReporter.reportDeprecatedModifierPair(
modifier: FirModifier<*>, firstKeyword: KtModifierKeywordToken, secondKeyword: KtModifierKeywordToken
modifier: FirModifier<*>, firstKeyword: KtModifierKeywordToken, secondKeyword: KtModifierKeywordToken, context: CheckerContext
) {
report(FirErrors.DEPRECATED_MODIFIER_PAIR.on(modifier.source, firstKeyword, secondKeyword))
report(FirErrors.DEPRECATED_MODIFIER_PAIR.on(modifier.source, firstKeyword, secondKeyword), context)
}
private fun DiagnosticReporter.reportIncompatibleModifiers(
modifier: FirModifier<*>, firstKeyword: KtModifierKeywordToken, secondKeyword: KtModifierKeywordToken
modifier: FirModifier<*>, firstKeyword: KtModifierKeywordToken, secondKeyword: KtModifierKeywordToken, context: CheckerContext
) {
report(FirErrors.INCOMPATIBLE_MODIFIERS.on(modifier.source, firstKeyword, secondKeyword))
report(FirErrors.INCOMPATIBLE_MODIFIERS.on(modifier.source, firstKeyword, secondKeyword), context)
}
}
@@ -0,0 +1,318 @@
/*
* Copyright 2010-2020 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.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
import org.jetbrains.kotlin.fir.containingClass
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap
import org.jetbrains.kotlin.fir.scopes.FirTypeScope
import org.jetbrains.kotlin.fir.scopes.getDirectOverriddenFunctions
import org.jetbrains.kotlin.fir.scopes.getDirectOverriddenProperties
import org.jetbrains.kotlin.fir.scopes.impl.toConeType
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.fir.typeContext
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.types.AbstractTypeChecker
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
import org.jetbrains.kotlin.utils.addToStdlib.min
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
object FirOverrideChecker : FirRegularClassChecker() {
override fun check(declaration: FirRegularClass, context: CheckerContext, reporter: DiagnosticReporter) {
val typeCheckerContext = context.session.typeContext.newBaseTypeCheckerContext(
errorTypesEqualToAnything = false,
stubTypesEqualToAnything = false
)
val firTypeScope = declaration.unsubstitutedScope(
context.sessionHolder.session,
context.sessionHolder.scopeSession,
withForcedTypeCalculator = true
)
for (it in declaration.declarations) {
when (it) {
is FirSimpleFunction -> checkFunction(it, reporter, typeCheckerContext, firTypeScope, context)
is FirProperty -> checkProperty(it, reporter, typeCheckerContext, firTypeScope, context)
}
}
}
private fun FirTypeScope.retrieveDirectOverriddenOf(function: FirSimpleFunction): List<FirFunctionSymbol<*>> {
processFunctionsByName(function.name) {}
return getDirectOverriddenFunctions(function.symbol)
}
private fun FirTypeScope.retrieveDirectOverriddenOf(property: FirProperty): List<FirPropertySymbol> {
processPropertiesByName(property.name) {}
return getDirectOverriddenProperties(property.symbol)
}
private fun ConeKotlinType.substituteAllTypeParameters(
overrideDeclaration: FirCallableMemberDeclaration<*>,
baseDeclarationSymbol: FirCallableSymbol<*>,
): ConeKotlinType {
if (overrideDeclaration.typeParameters.isEmpty()) {
return this
}
val parametersOwner = baseDeclarationSymbol.fir.safeAs<FirTypeParametersOwner>()
?: return this
val map = mutableMapOf<FirTypeParameterSymbol, ConeKotlinType>()
val size = min(overrideDeclaration.typeParameters.size, parametersOwner.typeParameters.size)
for (it in 0 until size) {
val to = overrideDeclaration.typeParameters[it]
val from = parametersOwner.typeParameters[it]
map[from.symbol] = to.toConeType()
}
return substitutorByMap(map).substituteOrSelf(this)
}
private fun checkModality(
overriddenSymbols: List<FirCallableSymbol<*>>,
): FirCallableDeclaration<*>? {
for (overridden in overriddenSymbols) {
if (overridden.fir !is FirMemberDeclaration) continue
val modality = (overridden.fir as FirMemberDeclaration).status.modality
val isEffectivelyFinal = modality == null || modality == Modality.FINAL
if (isEffectivelyFinal) {
return overridden.fir
}
}
return null
}
private fun FirProperty.checkMutability(
overriddenSymbols: List<FirCallableSymbol<*>>,
): FirMemberDeclaration? {
if (isVar) return null
return overriddenSymbols.find { (it.fir as? FirProperty)?.isVar == true }?.fir?.safeAs()
}
private fun FirCallableMemberDeclaration<*>.checkVisibility(
reporter: DiagnosticReporter,
overriddenSymbols: List<FirCallableSymbol<*>>,
context: CheckerContext
) {
val visibilities = overriddenSymbols.mapNotNull {
if (it.fir !is FirMemberDeclaration) return@mapNotNull null
it to (it.fir as FirMemberDeclaration).visibility
}.sortedBy { pair ->
// Regard `null` compare as Int.MIN so that we can report CANNOT_CHANGE_... first deterministically
visibility.compareTo(pair.second) ?: Int.MIN_VALUE
}
for ((overridden, overriddenVisibility) in visibilities) {
val compare = visibility.compareTo(overriddenVisibility)
if (compare == null) {
// TODO: not ready yet (even after determinism massage), e.g., a Kotlin class that extends a Java class
// reporter.reportCannotChangeAccessPrivilege(this, overridden.fir)
return
} else if (compare < 0) {
reporter.reportCannotWeakenAccessPrivilege(this, overridden.fir, context)
return
}
}
}
private fun FirCallableMemberDeclaration<*>.checkReturnType(
overriddenSymbols: List<FirCallableSymbol<*>>,
typeCheckerContext: AbstractTypeCheckerContext,
context: CheckerContext,
): FirMemberDeclaration? {
val returnType = returnTypeRef.safeAs<FirResolvedTypeRef>()?.type
?: return null
// Don't report *_ON_OVERRIDE diagnostics according to an error return type. That should be reported separately.
if (returnType is ConeKotlinErrorType) {
return null
}
val bounds = overriddenSymbols.map { context.returnTypeCalculator.tryCalculateReturnType(it.fir).coneType.upperBoundIfFlexible() }
for (it in bounds.indices) {
val restriction = bounds[it]
.substituteAllTypeParameters(this, overriddenSymbols[it])
if (!AbstractTypeChecker.isSubtypeOf(typeCheckerContext, returnType, restriction)) {
return overriddenSymbols[it].fir.safeAs()
}
}
return null
}
private fun checkFunction(
function: FirSimpleFunction,
reporter: DiagnosticReporter,
typeCheckerContext: AbstractTypeCheckerContext,
firTypeScope: FirTypeScope,
context: CheckerContext,
) {
if (!function.isOverride) {
return
}
val overriddenFunctionSymbols = firTypeScope.retrieveDirectOverriddenOf(function)
if (overriddenFunctionSymbols.isEmpty()) {
reporter.reportNothingToOverride(function, context)
return
}
checkModality(overriddenFunctionSymbols)?.let {
reporter.reportOverridingFinalMember(function, it, context)
}
function.checkVisibility(reporter, overriddenFunctionSymbols, context)
val restriction = function.checkReturnType(
overriddenSymbols = overriddenFunctionSymbols,
typeCheckerContext = typeCheckerContext,
context = context,
)
restriction?.let {
reporter.reportReturnTypeMismatchOnFunction(function, it, context)
}
}
private fun checkProperty(
property: FirProperty,
reporter: DiagnosticReporter,
typeCheckerContext: AbstractTypeCheckerContext,
firTypeScope: FirTypeScope,
context: CheckerContext,
) {
if (!property.isOverride) {
return
}
val overriddenPropertySymbols = firTypeScope.retrieveDirectOverriddenOf(property)
if (overriddenPropertySymbols.isEmpty()) {
reporter.reportNothingToOverride(property, context)
return
}
checkModality(overriddenPropertySymbols)?.let {
reporter.reportOverridingFinalMember(property, it, context)
}
property.checkMutability(overriddenPropertySymbols)?.let {
reporter.reportVarOverriddenByVal(property, it, context)
}
property.checkVisibility(reporter, overriddenPropertySymbols, context)
val restriction = property.checkReturnType(
overriddenSymbols = overriddenPropertySymbols,
typeCheckerContext = typeCheckerContext,
context = context,
)
restriction?.let {
if (property.isVar) {
reporter.reportTypeMismatchOnVariable(property, it, context)
} else {
reporter.reportTypeMismatchOnProperty(property, it, context)
}
}
}
private fun DiagnosticReporter.reportNothingToOverride(declaration: FirMemberDeclaration, context: CheckerContext) {
// TODO: not ready yet, e.g., Collections
// reportOn(declaration.source, FirErrors.NOTHING_TO_OVERRIDE, declaration, context)
}
private fun DiagnosticReporter.reportOverridingFinalMember(
overriding: FirMemberDeclaration,
overridden: FirCallableDeclaration<*>,
context: CheckerContext
) {
overriding.source?.let { source ->
overridden.containingClass()?.let { containingClass ->
report(FirErrors.OVERRIDING_FINAL_MEMBER.on(source, overridden, containingClass.name), context)
}
}
}
private fun DiagnosticReporter.reportVarOverriddenByVal(
overriding: FirMemberDeclaration,
overridden: FirMemberDeclaration,
context: CheckerContext
) {
overriding.source?.let { report(FirErrors.VAR_OVERRIDDEN_BY_VAL.on(it, overriding, overridden), context) }
}
private fun DiagnosticReporter.reportCannotWeakenAccessPrivilege(
overriding: FirMemberDeclaration,
overridden: FirCallableDeclaration<*>,
context: CheckerContext
) {
val containingClass = overridden.containingClass() ?: return
reportOn(
overriding.source,
FirErrors.CANNOT_WEAKEN_ACCESS_PRIVILEGE,
overriding.visibility,
overridden,
containingClass.name,
context
)
}
private fun DiagnosticReporter.reportCannotChangeAccessPrivilege(
overriding: FirMemberDeclaration,
overridden: FirCallableDeclaration<*>,
context: CheckerContext
) {
val containingClass = overridden.containingClass() ?: return
reportOn(
overriding.source,
FirErrors.CANNOT_CHANGE_ACCESS_PRIVILEGE,
overriding.visibility,
overridden,
containingClass.name,
context
)
}
private fun DiagnosticReporter.reportReturnTypeMismatchOnFunction(
overriding: FirMemberDeclaration,
overridden: FirMemberDeclaration,
context: CheckerContext
) {
reportOn(overriding.source, FirErrors.RETURN_TYPE_MISMATCH_ON_OVERRIDE, overriding, overridden, context)
}
private fun DiagnosticReporter.reportTypeMismatchOnProperty(
overriding: FirMemberDeclaration,
overridden: FirMemberDeclaration,
context: CheckerContext
) {
reportOn(overriding.source, FirErrors.PROPERTY_TYPE_MISMATCH_ON_OVERRIDE, overriding, overridden, context)
}
private fun DiagnosticReporter.reportTypeMismatchOnVariable(
overriding: FirMemberDeclaration,
overridden: FirMemberDeclaration,
context: CheckerContext
) {
reportOn(overriding.source, FirErrors.VAR_TYPE_MISMATCH_ON_OVERRIDE, overriding, overridden, context)
}
}

Some files were not shown because too many files have changed in this diff Show More