Report error on pre-release top level members

This commit is contained in:
Alexander Udalov
2016-12-06 19:03:31 +03:00
parent 11f975fe89
commit 7de0cfde16
8 changed files with 70 additions and 14 deletions
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.SourceElement
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Errors.MISSING_DEPENDENCY_CLASS
import org.jetbrains.kotlin.diagnostics.Errors.PRE_RELEASE_CLASS
@@ -32,14 +33,19 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.serialization.deserialization.NotFoundClasses
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedMemberDescriptor
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.utils.newLinkedHashSetWithExpectedSize
object MissingDependencyClassChecker : CallChecker {
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
for (diagnostic in collectDiagnostics(reportOn, resolvedCall.resultingDescriptor)) {
val resultingDescriptor = resolvedCall.resultingDescriptor
for (diagnostic in collectDiagnostics(reportOn, resultingDescriptor)) {
context.trace.report(diagnostic)
}
val containerSource = (resultingDescriptor as? DeserializedMemberDescriptor)?.containerSource
incompatibilityDiagnosticFor(containerSource, reportOn)?.let(context.trace::report)
}
private fun diagnosticFor(descriptor: ClassifierDescriptor, reportOn: PsiElement): Diagnostic? {
@@ -47,10 +53,13 @@ object MissingDependencyClassChecker : CallChecker {
return MISSING_DEPENDENCY_CLASS.on(reportOn, descriptor.fqNameSafe)
}
val source = descriptor.source
return incompatibilityDiagnosticFor(descriptor.source, reportOn)
}
private fun incompatibilityDiagnosticFor(source: SourceElement?, reportOn: PsiElement): Diagnostic? {
if (source is DeserializedContainerSource && source.isPreReleaseInvisible) {
// TODO: if at least one PRE_RELEASE_CLASS is reported, display a hint to disable the diagnostic
return PRE_RELEASE_CLASS.on(reportOn, descriptor.fqNameSafe)
return PRE_RELEASE_CLASS.on(reportOn, source.presentableFqName)
}
return null
@@ -88,9 +97,10 @@ object MissingDependencyClassChecker : CallChecker {
element: PsiElement,
languageVersionSettings: LanguageVersionSettings
) {
diagnosticFor(targetDescriptor, element)?.let { diagnostic ->
trace.report(diagnostic)
}
diagnosticFor(targetDescriptor, element)?.let(trace::report)
val containerSource = (targetDescriptor as? DeserializedMemberDescriptor)?.containerSource
incompatibilityDiagnosticFor(containerSource, element)?.let(trace::report)
}
}
}
@@ -3,3 +3,7 @@ package a
open class A {
class Nested
}
fun foo() = ""
var bar = 42
typealias TA = String
@@ -1,9 +1,18 @@
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibrary/source.kt:5:16: error: class 'a.A' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
fun baz(param: A) {
fun baz(param: A, nested: A.Nested) {
^
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibrary/source.kt:5:27: error: class 'a.A' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
fun baz(param: A, nested: A.Nested) {
^
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibrary/source.kt:5:29: error: class 'a.A.Nested' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
fun baz(param: A, nested: A.Nested) {
^
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibrary/source.kt:6:23: error: class 'a.A' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
val constructor = A()
^
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibrary/source.kt:7:18: error: class 'a.A' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
val nested = A.Nested()
^
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibrary/source.kt:7:20: error: class 'a.A.Nested' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
val nested = A.Nested()
^
@@ -16,4 +25,16 @@ compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreRe
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibrary/source.kt:9:30: error: class 'a.A' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
val supertype = object : A() {}
^
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibrary/source.kt:11:13: error: class 'a.AKt' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
val x = foo()
^
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibrary/source.kt:12:13: error: class 'a.AKt' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
val y = bar
^
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibrary/source.kt:13:5: error: class 'a.AKt' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
bar = 239
^
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibrary/source.kt:14:12: error: class 'a.AKt' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
val z: TA = ""
^
COMPILATION_ERROR
@@ -7,4 +7,9 @@ fun baz(param: A, nested: A.Nested) {
val nested = A.Nested()
val methodCall = param.method()
val supertype = object : A() {}
val x = foo()
val y = bar
bar = 239
val z: TA = ""
}