Skip to content

Commit 439f8f2

Browse files
committed
Fix #9538: type of empty expression
1 parent 0e67451 commit 439f8f2

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,14 @@ 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) =>

compiler/test-resources/repl/i9538

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

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)