Skip to content

Fix #9538: repl crashes when :type and :doc are invoked with an empty expression #9571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions compiler/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -376,17 +376,25 @@ class ReplDriver(settings: Array[String],
}

case TypeOf(expr) =>
compiler.typeOf(expr)(newRun(state)).fold(
displayErrors,
res => out.println(SyntaxHighlighting.highlight(res)(using state.context))
)
expr match {
case "" => out.println(s":type <expression>")
case _ =>
compiler.typeOf(expr)(newRun(state)).fold(
displayErrors,
res => out.println(SyntaxHighlighting.highlight(res)(using state.context))
)
}
state

case DocOf(expr) =>
compiler.docOf(expr)(newRun(state)).fold(
displayErrors,
res => out.println(res)
)
expr match {
case "" => out.println(s":doc <expression>")
case _ =>
compiler.docOf(expr)(newRun(state)).fold(
displayErrors,
res => out.println(res)
)
}
state

case Quit =>
Expand Down
5 changes: 5 additions & 0 deletions compiler/test-resources/repl/i9538
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
scala>:type
:type <expression>

scala>:doc
:doc <expression>
6 changes: 6 additions & 0 deletions compiler/test/dotty/tools/repl/DocTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ class DocTests extends ReplTest {
assertEquals("Expansion: some-value", doc("Foo.hello"))
}

@Test def docOfEmpty =
fromInitialState { implicit s =>
run(":doc")
assertEquals(":doc <expression>", storedOutput().trim)
}

private def eval(code: String): State =
fromInitialState { implicit s => run(code) }

Expand Down
5 changes: 5 additions & 0 deletions compiler/test/dotty/tools/repl/TypeTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ class TypeTests extends ReplTest {
run(":type x")
assertEquals("Int", storedOutput().trim)
}

@Test def typeOfEmpty = fromInitialState { implicit s =>
run(":type")
assertEquals(":type <expression>", storedOutput().trim)
}
}