diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.kt index 365c77a53ee..0980e6bffee 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.kt @@ -121,12 +121,17 @@ abstract class CLICompiler : CLITool() { return COMPILATION_ERROR } catch (t: Throwable) { MessageCollectorUtil.reportException(collector, t) - return if (t is OutOfMemoryError) OOM_ERROR else INTERNAL_ERROR + return if (t is OutOfMemoryError || t.hasOOMCause()) OOM_ERROR else INTERNAL_ERROR } finally { collector.flush() } } + private fun Throwable.hasOOMCause(): Boolean = when (cause) { + is OutOfMemoryError -> true + else -> cause?.hasOOMCause() ?: false + } + private fun MessageCollector.reportCompilationCancelled(e: CompilationCanceledException) { if (e !is IncrementalNextRoundException) { report(INFO, "Compilation was canceled", null)