From 6b315259d3a427b7624f0ff141f3f4cf32e2ca13 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Wed, 12 Apr 2017 19:18:41 +0300 Subject: [PATCH] Fix "Unexpected message" from daemon when CompilerMessageLocation is null Recently the CompilerMessageLocation.NO_LOCATION was replaced with a null value. This caused daemon clients to report "Unexpected message" for compiler messages without location. --- ...CompilerServicesWithResultsFacadeServer.kt | 4 +- ...leIncrementalCompilerServicesFacadeImpl.kt | 38 ++++--------------- 2 files changed, 10 insertions(+), 32 deletions(-) diff --git a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/BasicCompilerServicesWithResultsFacadeServer.kt b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/BasicCompilerServicesWithResultsFacadeServer.kt index 1e04be36b70..94a936ea665 100644 --- a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/BasicCompilerServicesWithResultsFacadeServer.kt +++ b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/BasicCompilerServicesWithResultsFacadeServer.kt @@ -65,8 +65,8 @@ fun MessageCollector.reportFromDaemon(outputsCollector: ((File, List) -> U ReportSeverity.DEBUG -> CompilerMessageSeverity.LOGGING else -> throw IllegalStateException("Unexpected compiler message report severity $severity") } - if (message != null && attachment is CompilerMessageLocation?) { - report(compilerSeverity, message, attachment) + if (message != null) { + report(compilerSeverity, message, attachment as? CompilerMessageLocation) } else { reportUnexpected(category, severity, message, attachment) diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleIncrementalCompilerServicesFacadeImpl.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleIncrementalCompilerServicesFacadeImpl.kt index 5e7131aa835..b90bda8b0e7 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleIncrementalCompilerServicesFacadeImpl.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleIncrementalCompilerServicesFacadeImpl.kt @@ -5,6 +5,7 @@ import org.gradle.api.logging.Logger import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.MessageCollector +import org.jetbrains.kotlin.daemon.client.reportFromDaemon import org.jetbrains.kotlin.daemon.common.* import org.jetbrains.kotlin.daemon.incremental.toDirtyData import org.jetbrains.kotlin.daemon.incremental.toSimpleDirtyData @@ -29,30 +30,7 @@ internal open class GradleCompilerServicesFacadeImpl( protected val log: Logger = project.logger override fun report(category: Int, severity: Int, message: String?, attachment: Serializable?) { - val reportCategory = ReportCategory.fromCode(category) - - when (reportCategory) { - ReportCategory.OUTPUT_MESSAGE -> { - compilerMessageCollector.report(CompilerMessageSeverity.OUTPUT, message!!) - } - ReportCategory.EXCEPTION -> { - compilerMessageCollector.report(CompilerMessageSeverity.EXCEPTION, message!!) - } - ReportCategory.COMPILER_MESSAGE -> { - val compilerSeverity = when (ReportSeverity.fromCode(severity)) { - ReportSeverity.ERROR -> CompilerMessageSeverity.ERROR - ReportSeverity.WARNING -> CompilerMessageSeverity.WARNING - ReportSeverity.INFO -> CompilerMessageSeverity.INFO - ReportSeverity.DEBUG -> CompilerMessageSeverity.LOGGING - else -> throw IllegalStateException("Unexpected compiler message report severity $severity") - } - if (message != null && attachment is CompilerMessageLocation?) { - compilerMessageCollector.report(compilerSeverity, message, attachment) - } - else { - reportUnexpectedMessage(category, severity, message, attachment) - } - } + when (ReportCategory.fromCode(category)) { ReportCategory.IC_MESSAGE -> { log.kotlinDebug { "[IC] $message" } } @@ -60,15 +38,15 @@ internal open class GradleCompilerServicesFacadeImpl( log.kotlinDebug { "[DAEMON] $message" } } else -> { - reportUnexpectedMessage(category, severity, message, attachment) + compilerMessageCollector.reportFromDaemon( + outputsCollector = null, + category = category, + severity = severity, + message = message, + attachment = attachment) } } } - - protected fun reportUnexpectedMessage(category: Int, severity: Int, message: String?, attachment: Serializable?) { - // todo add assert to tests - log.kotlinWarn("Received unexpected message from compiler daemon: category=$category, severity=$severity, message='$message', attachment=$attachment") - } } internal class GradleIncrementalCompilerServicesFacadeImpl(