Skip to content

Commit de930cf

Browse files
committed
Override line and column in NoSourcePosition
Otherwise, usage causes an assertion error. The use of the value -1 is in agreement with the documentation in interfaces/src/dotty/tools/dotc/interfaces/SourcePosition.java The REPL driver depends on these methods for ordering its output, and some diagnostics are reported (intentionally) using NoSoucePosition.
1 parent bfd72c2 commit de930cf

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

compiler/src/dotty/tools/dotc/util/SourcePosition.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ extends SrcPos, interfaces.SourcePosition, Showable {
8686

8787
/** A sentinel for a non-existing source position */
8888
@sharable object NoSourcePosition extends SourcePosition(NoSource, NoSpan, null) {
89+
override def line: Int = -1
90+
override def column: Int = -1
8991
override def toString: String = "?"
9092
override def withOuter(outer: SourcePosition): SourcePosition = outer
9193
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,31 @@ object ReplCompilerTests {
233233
}
234234

235235
}
236+
237+
class ReplXPrintTyperTests extends ReplTest(ReplTest.defaultOptions :+ "-Xprint:typer") {
238+
@Test def i9111 = fromInitialState { implicit state =>
239+
run("""|enum E {
240+
| case A
241+
|}""".stripMargin)
242+
assert(storedOutput().trim().endsWith("// defined class E"))
243+
}
244+
245+
@Test def i10883 = fromInitialState { implicit state =>
246+
run("val a = 42")
247+
assert(storedOutput().trim().endsWith("val a: Int = 42"))
248+
}
249+
}
250+
251+
class ReplVerboseTests extends ReplTest(ReplTest.defaultOptions :+ "-verbose") {
252+
@Test def i9111 = fromInitialState { implicit state =>
253+
run("""|enum E {
254+
| case A
255+
|}""".stripMargin)
256+
assert(storedOutput().trim().endsWith("// defined class E"))
257+
}
258+
259+
@Test def i10883 = fromInitialState { implicit state =>
260+
run("val a = 42")
261+
assert(storedOutput().trim().endsWith("val a: Int = 42"))
262+
}
263+
}

0 commit comments

Comments
 (0)