Skip to content

Fix #10883: Override line and column in NoSourcePosition #11362

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 2 commits into from
Feb 12, 2021
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
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/util/SourcePosition.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ extends SrcPos, interfaces.SourcePosition, Showable {

/** A sentinel for a non-existing source position */
@sharable object NoSourcePosition extends SourcePosition(NoSource, NoSpan, null) {
override def line: Int = -1
override def column: Int = -1
override def toString: String = "?"
override def withOuter(outer: SourcePosition): SourcePosition = outer
}
Expand Down
28 changes: 28 additions & 0 deletions compiler/test/dotty/tools/repl/ReplCompilerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,31 @@ object ReplCompilerTests {
}

}

class ReplXPrintTyperTests extends ReplTest(ReplTest.defaultOptions :+ "-Xprint:typer") {
@Test def i9111 = fromInitialState { implicit state =>
run("""|enum E {
| case A
|}""".stripMargin)
assert(storedOutput().trim().endsWith("// defined class E"))
}

@Test def i10883 = fromInitialState { implicit state =>
run("val a = 42")
assert(storedOutput().trim().endsWith("val a: Int = 42"))
}
}

class ReplVerboseTests extends ReplTest(ReplTest.defaultOptions :+ "-verbose") {
@Test def i9111 = fromInitialState { implicit state =>
run("""|enum E {
| case A
|}""".stripMargin)
assert(storedOutput().trim().endsWith("// defined class E"))
}

@Test def i10883 = fromInitialState { implicit state =>
run("val a = 42")
assert(storedOutput().trim().endsWith("val a: Int = 42"))
}
}
20 changes: 7 additions & 13 deletions compiler/test/dotty/tools/repl/ReplTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,8 @@ import dotty.tools.dotc.reporting.MessageRendering
import org.junit.{After, Before}
import org.junit.Assert._


class ReplTest(withStaging: Boolean = false, out: ByteArrayOutputStream = new ByteArrayOutputStream) extends ReplDriver(
Array(
"-classpath",
if (withStaging)
TestConfiguration.withStagingClasspath
else
TestConfiguration.basicClasspath,
"-color:never",
"-Yerased-terms",
),
new PrintStream(out, true, StandardCharsets.UTF_8.name)
) with MessageRendering {
class ReplTest(options: Array[String] = ReplTest.defaultOptions, out: ByteArrayOutputStream = new ByteArrayOutputStream)
extends ReplDriver(options, new PrintStream(out, true, StandardCharsets.UTF_8.name)) with MessageRendering {
/** Get the stored output from `out`, resetting the buffer */
def storedOutput(): String = {
val output = stripColor(out.toString(StandardCharsets.UTF_8.name))
Expand Down Expand Up @@ -103,3 +92,8 @@ class ReplTest(withStaging: Boolean = false, out: ByteArrayOutputStream = new By
end if
}
}

object ReplTest:
val commonOptions = Array("-color:never", "-Yerased-terms")
val defaultOptions = commonOptions ++ Array("-classpath", TestConfiguration.basicClasspath)
lazy val withStagingOptions = commonOptions ++ Array("-classpath", TestConfiguration.withStagingClasspath)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.junit.Test
import org.junit.experimental.categories.Category

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

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