diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/messages/ReplTerminalDiagnosticMessageHolder.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/messages/ReplTerminalDiagnosticMessageHolder.kt index 5a40c15b69a..ef72098dd2d 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/messages/ReplTerminalDiagnosticMessageHolder.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/messages/ReplTerminalDiagnosticMessageHolder.kt @@ -16,15 +16,25 @@ package org.jetbrains.kotlin.cli.jvm.repl.messages -import org.jetbrains.kotlin.cli.common.messages.* +import org.jetbrains.kotlin.cli.common.messages.GroupingMessageCollector +import org.jetbrains.kotlin.cli.common.messages.MessageCollectorBasedReporter +import org.jetbrains.kotlin.cli.common.messages.MessageRenderer +import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector import java.io.ByteArrayOutputStream import java.io.PrintStream import java.nio.ByteBuffer -class ReplTerminalDiagnosticMessageHolder() : MessageCollectorBasedReporter, DiagnosticMessageHolder { +class ReplTerminalDiagnosticMessageHolder : MessageCollectorBasedReporter, DiagnosticMessageHolder { private val outputStream = ByteArrayOutputStream() - override val messageCollector = PrintingMessageCollector(PrintStream(outputStream), MessageRenderer.WITHOUT_PATHS, false) + + override val messageCollector: GroupingMessageCollector = GroupingMessageCollector( + PrintingMessageCollector(PrintStream(outputStream), MessageRenderer.WITHOUT_PATHS, false) + ) override val renderedDiagnostics: String - get() = Charsets.UTF_8.decode(ByteBuffer.wrap(outputStream.toByteArray())).toString() -} \ No newline at end of file + get() { + messageCollector.flush() + val bytes = outputStream.toByteArray() + return Charsets.UTF_8.decode(ByteBuffer.wrap(bytes)).toString() + } +} diff --git a/compiler/testData/repl/controlFlow/incompleteWhen.repl b/compiler/testData/repl/controlFlow/incompleteWhen.repl index 6a40f55fcda..9ff1e6f2711 100644 --- a/compiler/testData/repl/controlFlow/incompleteWhen.repl +++ b/compiler/testData/repl/controlFlow/incompleteWhen.repl @@ -2,9 +2,6 @@ error: 'when' expression must be exhaustive, add necessary 'else' branch val a = when(null) { } ^ -warning: the expression is unused -val a = when(null) { } - ^ >>> "" + when (true) { true -> 42 } error: 'when' expression must be exhaustive, add necessary 'false' branch or 'else' branch instead "" + when (true) { true -> 42 } diff --git a/compiler/testData/repl/noWarningsWithErrors.repl b/compiler/testData/repl/noWarningsWithErrors.repl new file mode 100644 index 00000000000..210ecb7df3a --- /dev/null +++ b/compiler/testData/repl/noWarningsWithErrors.repl @@ -0,0 +1,11 @@ +>>> (listOf(1) as List).unresolved() +error: unresolved reference: unresolved +(listOf(1) as List).unresolved() + ^ +>>> listOf(1!!) +error: the integer literal does not conform to the expected type String? +listOf(1!!) + ^ +error: type mismatch: inferred type is Int but String was expected +listOf(1!!) + ^ diff --git a/compiler/tests/org/jetbrains/kotlin/repl/ReplInterpreterTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/repl/ReplInterpreterTestGenerated.java index e4559000631..9f6902d0f48 100644 --- a/compiler/tests/org/jetbrains/kotlin/repl/ReplInterpreterTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/repl/ReplInterpreterTestGenerated.java @@ -114,6 +114,12 @@ public class ReplInterpreterTestGenerated extends AbstractReplInterpreterTest { doTest(fileName); } + @TestMetadata("noWarningsWithErrors.repl") + public void testNoWarningsWithErrors() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/repl/noWarningsWithErrors.repl"); + doTest(fileName); + } + @TestMetadata("simple.repl") public void testSimple() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/repl/simple.repl");