Skip to content

Commit f2fba0b

Browse files
Remove implicit conversion in repl tests
1 parent 4f119bc commit f2fba0b

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@ import ReplTest._
1414
class ReplCompilerTests extends ReplTest {
1515

1616
@Test def compileSingle: Unit = fromInitialState { implicit state =>
17-
compiler.compile("def foo: 1 = 1").stateOrFail
17+
compiler.compile("def foo: 1 = 1".toParsed).stateOrFail
1818
}
1919

2020

2121
@Test def compileTwo =
2222
fromInitialState { implicit state =>
23-
compiler.compile("def foo: 1 = 1").stateOrFail
23+
compiler.compile("def foo: 1 = 1".toParsed).stateOrFail
2424
}
2525
.andThen { implicit state =>
26-
val s2 = compiler.compile("def foo(i: Int): i.type = i").stateOrFail
26+
val s2 = compiler.compile("def foo(i: Int): i.type = i".toParsed).stateOrFail
2727
assert(s2.objectIndex == 2,
2828
s"Wrong object offset: expected 2 got ${s2.objectIndex}")
2929
}
3030

3131
@Test def inspectSingle =
3232
fromInitialState { implicit state =>
33-
val untpdTree = compiler.compile("def foo: 1 = 1").map(_._1.untpdTree)
33+
val untpdTree = compiler.compile("def foo: 1 = 1".toParsed).map(_._1.untpdTree)
3434

3535
untpdTree.fold(
3636
onErrors,
@@ -44,7 +44,7 @@ class ReplCompilerTests extends ReplTest {
4444
}
4545

4646
@Test def testVar = fromInitialState { implicit state =>
47-
compile("var x = 5")
47+
compile("var x = 5".toParsed)
4848
assertEquals("var x: Int = 5\n", storedOutput())
4949
}
5050

@@ -54,7 +54,7 @@ class ReplCompilerTests extends ReplTest {
5454
|val x = 5 + 5
5555
|1 + 1
5656
|var y = 5
57-
|10 + 10""".stripMargin
57+
|10 + 10""".stripMargin.toParsed
5858
}
5959

6060
val expected = Set("def foo: Int",
@@ -68,12 +68,12 @@ class ReplCompilerTests extends ReplTest {
6868

6969
@Test def testImportMutable =
7070
fromInitialState { implicit state =>
71-
compile("import scala.collection.mutable")
71+
compile("import scala.collection.mutable".toParsed)
7272
}
7373
.andThen { implicit state =>
7474
assert(state.imports.nonEmpty, "Didn't add import to `State` after compilation")
7575

76-
compile("""mutable.Map("one" -> 1)""")
76+
compile("""mutable.Map("one" -> 1)""".toParsed)
7777

7878
assertEquals(
7979
"val res0: scala.collection.mutable.Map[String, Int] = Map(one -> 1)\n",
@@ -82,9 +82,9 @@ class ReplCompilerTests extends ReplTest {
8282
}
8383

8484
@Test def rebindVariable =
85-
fromInitialState { implicit s => compile("var x = 5") }
85+
fromInitialState { implicit s => compile("var x = 5".toParsed) }
8686
.andThen { implicit s =>
87-
compile("x = 10")
87+
compile("x = 10".toParsed)
8888
assertEquals(
8989
"""|var x: Int = 5
9090
|x: Int = 10
@@ -96,28 +96,28 @@ class ReplCompilerTests extends ReplTest {
9696
// FIXME: Tests are not run in isolation, the classloader is corrupted after the first exception
9797
@Ignore def i3305: Unit = {
9898
fromInitialState { implicit s =>
99-
compile("null.toString")
99+
compile("null.toString".toParsed)
100100
assertTrue(storedOutput().startsWith("java.lang.NullPointerException"))
101101
}
102102

103103
fromInitialState { implicit s =>
104-
compile("def foo: Int = 1 + foo; foo")
104+
compile("def foo: Int = 1 + foo; foo".toParsed)
105105
assertTrue(storedOutput().startsWith("def foo: Int\njava.lang.StackOverflowError"))
106106
}
107107

108108
fromInitialState { implicit s =>
109-
compile("""throw new IllegalArgumentException("Hello")""")
109+
compile("""throw new IllegalArgumentException("Hello")""".toParsed)
110110
assertTrue(storedOutput().startsWith("java.lang.IllegalArgumentException: Hello"))
111111
}
112112

113113
fromInitialState { implicit s =>
114-
compile("val (x, y) = null")
114+
compile("val (x, y) = null".toParsed)
115115
assertTrue(storedOutput().startsWith("scala.MatchError: null"))
116116
}
117117
}
118118

119119
@Test def i2789: Unit = fromInitialState { implicit state =>
120-
compile("(x: Int) => println(x)")
120+
compile("(x: Int) => println(x)".toParsed)
121121
assertTrue(storedOutput().startsWith("val res0: Int => Unit ="))
122122
}
123123
}

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ class ReplTest extends ReplDriver(
4444
def storedOutput(): String =
4545
stripColor(out.asInstanceOf[StoringPrintStream].flushStored())
4646

47-
protected implicit def toParsed(expr: String)(implicit state: State): Parsed = {
48-
implicit val ctx = state.run.runContext
49-
ParseResult(expr) match {
50-
case pr: Parsed => pr
51-
case pr =>
52-
throw new java.lang.AssertionError(s"Expected parsed, got: $pr")
47+
implicit class StringToParsed(expr: String) {
48+
def toParsed(implicit state: State): Parsed = {
49+
implicit val ctx = state.run.runContext
50+
ParseResult(expr) match {
51+
case pr: Parsed => pr
52+
case pr =>
53+
throw new java.lang.AssertionError(s"Expected parsed, got: $pr")
54+
}
5355
}
5456
}
5557

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TypeTests extends ReplTest {
1818
}
1919

2020
@Test def typeOfX =
21-
fromInitialState { implicit s => compile("val x = 5") }
21+
fromInitialState { implicit s => compile("val x = 5".toParsed) }
2222
.andThen { implicit s =>
2323
compiler.typeOf("x")
2424
.fold(onErrors, assertEquals("Int", _))

0 commit comments

Comments
 (0)