Suggest to use "-Xskip-metadata-version-check" on incompatible classes in classpath
This commit is contained in:
+23
-8
@@ -24,11 +24,8 @@ import com.intellij.psi.PsiModifierListOwner
|
||||
import com.intellij.psi.util.PsiFormatUtil
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult
|
||||
import org.jetbrains.kotlin.codegen.state.IncompatibleClassTrackerImpl
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory0
|
||||
import org.jetbrains.kotlin.diagnostics.*
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils.sortedDiagnostics
|
||||
import org.jetbrains.kotlin.diagnostics.Severity
|
||||
import org.jetbrains.kotlin.diagnostics.SimpleDiagnostic
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
|
||||
import org.jetbrains.kotlin.load.java.JvmBytecodeBinaryVersion
|
||||
import org.jetbrains.kotlin.load.java.components.TraceBasedErrorReporter
|
||||
@@ -143,16 +140,34 @@ class AnalyzerWithCompilerReport(private val messageCollector: MessageCollector)
|
||||
return diagnostic.severity == Severity.ERROR
|
||||
}
|
||||
|
||||
fun reportDiagnostics(diagnostics: Diagnostics, reporter: DiagnosticMessageReporter): Boolean {
|
||||
data class ReportDiagnosticsResult(val hasErrors: Boolean, val hasIncompatibleClassErrors: Boolean)
|
||||
|
||||
fun reportDiagnostics(unsortedDiagnostics: Diagnostics, reporter: DiagnosticMessageReporter): ReportDiagnosticsResult {
|
||||
var hasErrors = false
|
||||
for (diagnostic in sortedDiagnostics(diagnostics.all())) {
|
||||
var hasIncompatibleClassErrors = false
|
||||
val diagnostics = sortedDiagnostics(unsortedDiagnostics.all())
|
||||
for (diagnostic in diagnostics) {
|
||||
hasErrors = hasErrors or reportDiagnostic(diagnostic, reporter)
|
||||
hasIncompatibleClassErrors = hasIncompatibleClassErrors or
|
||||
(diagnostic.factory == Errors.INCOMPATIBLE_CLASS || diagnostic.factory == Errors.PRE_RELEASE_CLASS)
|
||||
}
|
||||
return hasErrors
|
||||
|
||||
return ReportDiagnosticsResult(hasErrors, hasIncompatibleClassErrors)
|
||||
}
|
||||
|
||||
fun reportDiagnostics(diagnostics: Diagnostics, messageCollector: MessageCollector): Boolean {
|
||||
return reportDiagnostics(diagnostics, DefaultDiagnosticReporter(messageCollector))
|
||||
val (hasErrors, hasIncompatibleClassErrors) = reportDiagnostics(diagnostics, DefaultDiagnosticReporter(messageCollector))
|
||||
|
||||
if (hasIncompatibleClassErrors) {
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.ERROR,
|
||||
"Incompatible classes were found in dependencies. " +
|
||||
"Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors",
|
||||
CompilerMessageLocation.NO_LOCATION
|
||||
)
|
||||
}
|
||||
|
||||
return hasErrors
|
||||
}
|
||||
|
||||
fun reportSyntaxErrors(
|
||||
|
||||
-1
@@ -62,7 +62,6 @@ object MissingDependencyClassChecker : CallChecker {
|
||||
return INCOMPATIBLE_CLASS.on(reportOn, source.presentableFqName, incompatibility)
|
||||
}
|
||||
if (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, source.presentableFqName)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
error: incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors
|
||||
compiler/testData/cli/jvm/wrongAbiVersion.kt:3:12: error: class 'ClassWithWrongAbiVersion' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 0.30.0, expected version is $ABI_VERSION$.
|
||||
The class is loaded from $TESTDATA_DIR$/wrongAbiVersionLib/bin/ClassWithWrongAbiVersion.class
|
||||
fun foo(x: ClassWithWrongAbiVersion) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
error: incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors
|
||||
compiler/testData/cli/jvm/wrongAbiVersionNoErrors.kt:3:14: error: class 'wrong.ClassWithInnerLambda' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 0.30.0, expected version is $ABI_VERSION$.
|
||||
The class is loaded from $TESTDATA_DIR$/wrongAbiVersionLib/bin/wrong/ClassWithInnerLambda.class
|
||||
import wrong.ClassWithInnerLambda
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
error: incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors
|
||||
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, nested: A.Nested) {
|
||||
^
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
error: incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors
|
||||
compiler/testData/compileKotlinAgainstCustomBinaries/wrongMetadataVersion/source.kt:5:16: error: class 'a.A' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 42.0.0, expected version is $ABI_VERSION$.
|
||||
The class is loaded from $TMP_DIR$/library-after.jar!/a/A.class
|
||||
fun baz(param: A, nested: A.Nested) {
|
||||
|
||||
Reference in New Issue
Block a user