Skip to content

Commit 4dbe0b7

Browse files
authored
Merge pull request #9571 from december32/fix-#9538-repl-crash
Fix #9538: repl crashes when :type and :doc are invoked with an empty expression
2 parents 15a6c8b + a6c538d commit 4dbe0b7

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

compiler/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,17 +376,25 @@ class ReplDriver(settings: Array[String],
376376
}
377377

378378
case TypeOf(expr) =>
379-
compiler.typeOf(expr)(newRun(state)).fold(
380-
displayErrors,
381-
res => out.println(SyntaxHighlighting.highlight(res)(using state.context))
382-
)
379+
expr match {
380+
case "" => out.println(s":type <expression>")
381+
case _ =>
382+
compiler.typeOf(expr)(newRun(state)).fold(
383+
displayErrors,
384+
res => out.println(SyntaxHighlighting.highlight(res)(using state.context))
385+
)
386+
}
383387
state
384388

385389
case DocOf(expr) =>
386-
compiler.docOf(expr)(newRun(state)).fold(
387-
displayErrors,
388-
res => out.println(res)
389-
)
390+
expr match {
391+
case "" => out.println(s":doc <expression>")
392+
case _ =>
393+
compiler.docOf(expr)(newRun(state)).fold(
394+
displayErrors,
395+
res => out.println(res)
396+
)
397+
}
390398
state
391399

392400
case Quit =>

compiler/test-resources/repl/i9538

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
scala>:type
2+
:type <expression>
3+
4+
scala>:doc
5+
:doc <expression>

compiler/test/dotty/tools/repl/DocTests.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ class DocTests extends ReplTest {
177177
assertEquals("Expansion: some-value", doc("Foo.hello"))
178178
}
179179

180+
@Test def docOfEmpty =
181+
fromInitialState { implicit s =>
182+
run(":doc")
183+
assertEquals(":doc <expression>", storedOutput().trim)
184+
}
185+
180186
private def eval(code: String): State =
181187
fromInitialState { implicit s => run(code) }
182188

compiler/test/dotty/tools/repl/TypeTests.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ class TypeTests extends ReplTest {
2121
run(":type x")
2222
assertEquals("Int", storedOutput().trim)
2323
}
24+
25+
@Test def typeOfEmpty = fromInitialState { implicit s =>
26+
run(":type")
27+
assertEquals(":type <expression>", storedOutput().trim)
28+
}
2429
}

0 commit comments

Comments
 (0)