Skip to content

Commit 4c681d9

Browse files
committed
Fix REPL tests
1 parent c949205 commit 4c681d9

File tree

10 files changed

+49
-47
lines changed

10 files changed

+49
-47
lines changed

src/dotty/tools/dotc/Compiler.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,6 @@ class Compiler {
139139
.setTyper(new Typer)
140140
.setMode(Mode.ImplicitsEnabled)
141141
.setTyperState(new MutableTyperState(ctx.typerState, ctx.typerState.reporter, isCommittable = true))
142-
.setReporter(
143-
if (ctx.settings.color.value == "never") new ConsoleReporter()
144-
else new FancyConsoleReporter()
145-
)
146142
ctx.initialize()(start) // re-initialize the base context with start
147143
def addImport(ctx: Context, refFn: () => TermRef) =
148144
ctx.fresh.setImportInfo(ImportInfo.rootImport(refFn)(ctx))

src/dotty/tools/dotc/Driver.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ abstract class Driver extends DotClass {
2222
protected def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter =
2323
if (fileNames.nonEmpty)
2424
try {
25-
val run = compiler.newRun
25+
val fresh = ctx.fresh.setReporter {
26+
if (ctx.settings.color.value == "never") new ConsoleReporter()
27+
else new FancyConsoleReporter()
28+
}
29+
val run = compiler.newRun(fresh)
2630
run.compile(fileNames)
2731
run.printSummary()
2832
}

src/dotty/tools/dotc/reporting/ConsoleReporter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ConsoleReporter(
3737
/** Prints the message with the given position indication. */
3838
def printMessageAndPos(msg: String, pos: SourcePosition, kind: String = "")(implicit ctx: Context): Unit = {
3939
val posStr = if (pos.exists) s"$pos: " else ""
40-
printMessage(posStr + kind + msg)
40+
printMessage(s"${posStr}$kind: $msg")
4141
if (pos.exists) {
4242
printSourceLine(pos)
4343
printColumnMarker(pos)

src/dotty/tools/dotc/reporting/diagnostic/MessageCreator.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import util.{SourcePosition, NoSourcePosition}
77
import core.Contexts.Context
88

99
object MessageCreator {
10-
implicit def toNoExplanation(str: String) =
10+
implicit def toNoExplanation(str: String): MessageCreator =
1111
new NoExplanation(str)
1212
}
1313

src/dotty/tools/dotc/typer/ErrorReporting.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ object ErrorReporting {
131131
val found1 = reported(found)
132132
reported.setVariance(-1)
133133
val expected1 = reported(expected)
134-
ex"""type mismatch:
135-
| found : $found1
136-
| required: $expected1""" + whyNoMatchStr(found, expected)
134+
ex"""|type mismatch:
135+
|found: $found1
136+
|required: $expected1""".stripMargin + whyNoMatchStr(found, expected)
137137
}
138138

139139
/** Format `raw` implicitNotFound argument, replacing all

test/dotc/tests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class tests extends CompilerTest {
2323
val defaultOutputDir = "./out/"
2424

2525
implicit val defaultOptions = noCheckOptions ++ List(
26-
"-Yno-deep-subtypes", "-Yno-double-bindings", "-Yforce-sbt-phases",
26+
"-Yno-deep-subtypes", "-Yno-double-bindings", "-Yforce-sbt-phases", "-color:never",
2727
"-d", defaultOutputDir) ++ {
2828
if (isRunByJenkins) List("-Ycheck:tailrec,resolveSuper,mixin,restoreScopes,labelDef") // should be Ycheck:all, but #725
2929
else List("-Ycheck:tailrec,resolveSuper,mixin,restoreScopes,labelDef")

test/test/CompilerTest.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import dotty.partest.DPConfig
55
import dotty.tools.dotc.{Main, Bench, Driver}
66
import dotty.tools.dotc.interfaces.Diagnostic.ERROR
77
import dotty.tools.dotc.reporting._
8+
import diagnostic.Message
89
import dotty.tools.dotc.util.SourcePosition
910
import dotty.tools.dotc.config.CompilerCommand
1011
import dotty.tools.io.PlainFile
@@ -237,13 +238,13 @@ abstract class CompilerTest {
237238
val storeReporter = new Reporter with UniqueMessagePositions with HideNonSensicalMessages {
238239
private val consoleReporter = new ConsoleReporter()
239240
private val innerStoreReporter = new StoreReporter(consoleReporter)
240-
def doReport(d: Diagnostic)(implicit ctx: Context): Unit = {
241-
if (d.level == ERROR) {
241+
def doReport(m: Message)(implicit ctx: Context): Unit = {
242+
if (m.level == ERROR) {
242243
innerStoreReporter.flush()
243-
consoleReporter.doReport(d)
244+
consoleReporter.doReport(m)
244245
}
245-
else if (errorCount > 0) consoleReporter.doReport(d)
246-
else innerStoreReporter.doReport(d)
246+
else if (errorCount > 0) consoleReporter.doReport(m)
247+
else innerStoreReporter.doReport(m)
247248
}
248249
}
249250
val reporter = processor.process(allArgs, storeReporter)

test/test/OtherEntryPointsTest.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.junit.Assert._
55
import dotty.tools.dotc.Main
66
import dotty.tools.dotc.interfaces.{CompilerCallback, SourceFile}
77
import dotty.tools.dotc.reporting._
8+
import dotty.tools.dotc.reporting.diagnostic.Message
89
import dotty.tools.dotc.core.Contexts._
910
import java.io.File
1011
import scala.collection.mutable.ListBuffer
@@ -50,7 +51,7 @@ class OtherEntryPointsTest {
5051
private class CustomReporter extends Reporter
5152
with UniqueMessagePositions
5253
with HideNonSensicalMessages {
53-
def doReport(d: Diagnostic)(implicit ctx: Context): Unit = {
54+
def doReport(m: Message)(implicit ctx: Context): Unit = {
5455
}
5556
}
5657

tests/repl/errmsgs.check

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
scala> class Inv[T](x: T)
22
defined class Inv
33
scala> val x: List[String] = List(1)
4-
<console>:4: error: type mismatch:
5-
found : Int(1)
6-
required: String
4+
<console>:4: Error: type mismatch:
5+
found: Int(1)
6+
required: String
77
val x: List[String] = List(1)
88
^
99
scala> val y: List[List[String]] = List(List(1))
10-
<console>:4: error: type mismatch:
11-
found : Int(1)
12-
required: String
10+
<console>:4: Error: type mismatch:
11+
found: Int(1)
12+
required: String
1313
val y: List[List[String]] = List(List(1))
1414
^
1515
scala> val z: (List[String], List[Int]) = (List(1), List("a"))
16-
<console>:4: error: type mismatch:
17-
found : Int(1)
18-
required: String
16+
<console>:4: Error: type mismatch:
17+
found: Int(1)
18+
required: String
1919
val z: (List[String], List[Int]) = (List(1), List("a"))
2020
^
21-
<console>:4: error: type mismatch:
22-
found : String("a")
23-
required: Int
21+
<console>:4: Error: type mismatch:
22+
found: String("a")
23+
required: Int
2424
val z: (List[String], List[Int]) = (List(1), List("a"))
2525
^
2626
scala> val a: Inv[String] = new Inv(new Inv(1))
27-
<console>:5: error: type mismatch:
28-
found : Inv[T]
29-
required: String
27+
<console>:5: Error: type mismatch:
28+
found: Inv[T]
29+
required: String
3030

3131
where T is a type variable with constraint >: Int(1)
3232

3333
val a: Inv[String] = new Inv(new Inv(1))
3434
^
3535
scala> val b: Inv[String] = new Inv(1)
36-
<console>:5: error: type mismatch:
37-
found : Int(1)
38-
required: String
36+
<console>:5: Error: type mismatch:
37+
found: Int(1)
38+
required: String
3939
val b: Inv[String] = new Inv(1)
4040
^
4141
scala> abstract class C {
@@ -53,18 +53,18 @@ scala> abstract class C {
5353
}
5454
}
5555
}
56-
<console>:9: error: type mismatch:
57-
found : C.this.T(C.this.x)
58-
required: T'
56+
<console>:9: Error: type mismatch:
57+
found: C.this.T(C.this.x)
58+
required: T'
5959

6060
where T is a type in class C
6161
T' is a type in the initalizer of value s which is an alias of String
6262

6363
var y: T = x
6464
^
65-
<console>:13: error: type mismatch:
66-
found : T(y)
67-
required: T'
65+
<console>:13: Error: type mismatch:
66+
found: T(y)
67+
required: T'
6868

6969
where T is a type in the initalizer of value s which is an alias of String
7070
T' is a type in method f which is an alias of Int

tests/repl/imports.check

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ defined module o
77
scala> import o._
88
import o._
99
scala> buf += xs
10-
<console>:11: error: type mismatch:
11-
found : scala.collection.immutable.List[Int](o.xs)
12-
required: String
10+
<console>:11: Error: type mismatch:
11+
found: scala.collection.immutable.List[Int](o.xs)
12+
required: String
1313
buf += xs
1414
^
15-
<console>:11: error: type mismatch:
16-
found : String
17-
required: scala.collection.mutable.ListBuffer[Int]
15+
<console>:11: Error: type mismatch:
16+
found: String
17+
required: scala.collection.mutable.ListBuffer[Int]
1818
buf += xs
1919
^
2020
scala> buf ++= xs

0 commit comments

Comments
 (0)