Skip to content

Commit 73d34fd

Browse files
authored
Merge pull request #11362 from griggt/fix-#10883
Fix #10883: Override `line` and `column` in NoSourcePosition
2 parents e606046 + de930cf commit 73d34fd

File tree

4 files changed

+38
-14
lines changed

4 files changed

+38
-14
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+
}

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,8 @@ import dotty.tools.dotc.reporting.MessageRendering
1616
import org.junit.{After, Before}
1717
import org.junit.Assert._
1818

19-
20-
class ReplTest(withStaging: Boolean = false, out: ByteArrayOutputStream = new ByteArrayOutputStream) extends ReplDriver(
21-
Array(
22-
"-classpath",
23-
if (withStaging)
24-
TestConfiguration.withStagingClasspath
25-
else
26-
TestConfiguration.basicClasspath,
27-
"-color:never",
28-
"-Yerased-terms",
29-
),
30-
new PrintStream(out, true, StandardCharsets.UTF_8.name)
31-
) with MessageRendering {
19+
class ReplTest(options: Array[String] = ReplTest.defaultOptions, out: ByteArrayOutputStream = new ByteArrayOutputStream)
20+
extends ReplDriver(options, new PrintStream(out, true, StandardCharsets.UTF_8.name)) with MessageRendering {
3221
/** Get the stored output from `out`, resetting the buffer */
3322
def storedOutput(): String = {
3423
val output = stripColor(out.toString(StandardCharsets.UTF_8.name))
@@ -103,3 +92,8 @@ class ReplTest(withStaging: Boolean = false, out: ByteArrayOutputStream = new By
10392
end if
10493
}
10594
}
95+
96+
object ReplTest:
97+
val commonOptions = Array("-color:never", "-Yerased-terms")
98+
val defaultOptions = commonOptions ++ Array("-classpath", TestConfiguration.basicClasspath)
99+
lazy val withStagingOptions = commonOptions ++ Array("-classpath", TestConfiguration.withStagingClasspath)

staging/test/scala/quoted/staging/repl/StagingScriptedReplTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import org.junit.Test
88
import org.junit.experimental.categories.Category
99

1010
/** Runs all tests contained in `staging/test-resources/repl-staging` */
11-
class StagingScriptedReplTests extends ReplTest(withStaging = true) {
11+
class StagingScriptedReplTests extends ReplTest(ReplTest.withStagingOptions) {
1212

1313
@Category(Array(classOf[BootstrappedOnlyTests]))
1414
@Test def replStagingTests = scripts("/repl-staging").foreach(testFile)

0 commit comments

Comments
 (0)