Skip to content

Commit 4947141

Browse files
committed
Convert test classes (1)
1 parent 5d350e5 commit 4947141

20 files changed

+47
-41
lines changed

compiler/src/dotty/tools/dotc/classpath/ZipAndJarFileLookupFactory.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import scala.annotation.tailrec
1212
import dotty.tools.io.{AbstractFile, ClassPath, ClassRepresentation, FileZipArchive, ManifestResources}
1313
import dotty.tools.dotc.core.Contexts.{Context, ctx}
1414
import FileUtils._
15+
import dotty.tools.dotc.core.Contexts.{Context, ctx}
1516

1617
/**
1718
* A trait providing an optional cache for classpath entries obtained from zip and jar files.

compiler/test/dotty/tools/CheckTypesTests.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.junit.Assert.{ assertFalse, assertTrue, fail }
55

66
import dotc.ast.Trees._
77
import dotc.core.Decorators._
8+
import dotc.core.Contexts.{Context, ctx}
89

910
class CheckTypeTest extends DottyTest {
1011
@Test
@@ -27,7 +28,7 @@ class CheckTypeTest extends DottyTest {
2728

2829
checkTypes(source, types: _*) {
2930
case (List(a, b, lu, li, lr, ls, la, lb), context) =>
30-
implicit val ctx = context
31+
given Context = context
3132

3233
assertTrue ( b <:< a)
3334
assertTrue (li <:< lu)
@@ -59,7 +60,7 @@ class CheckTypeTest extends DottyTest {
5960

6061
checkTypes(source, List(typesA, typesB)) {
6162
case (List(sups, subs), context) =>
62-
implicit val ctx = context
63+
given Context = context
6364

6465
sups.lazyZip(subs).foreach { (sup, sub) => assertTrue(sub <:< sup) }
6566

compiler/test/dotty/tools/DottyTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ trait DottyTest extends ContextEscapeDetection {
8080
val gatheredSource = s"${source}\nobject A$dummyName {$vals}"
8181
checkCompile("typer", gatheredSource) {
8282
(tree, context) =>
83-
implicit val ctx = context
83+
given Context = context
8484
val findValDef: (List[tpd.ValDef], tpd.Tree) => List[tpd.ValDef] =
8585
(acc , tree) => {
8686
tree match {

compiler/test/dotty/tools/DottyTypeStealer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ object DottyTypeStealer extends DottyTest {
1616
var tp: List[Type] = null
1717
checkCompile("typer", gatheredSource) {
1818
(tree, context) =>
19-
implicit val ctx = context
19+
given Context = context
2020
val findValDef: (List[ValDef], tpd.Tree) => List[ValDef] =
2121
(acc , tree) => tree match {
2222
case t: ValDef if t.name.startsWith(dummyName) => t :: acc

compiler/test/dotty/tools/backend/jvm/DottyBytecodeTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package backend.jvm
44

55
import vulpix.TestConfiguration
66

7-
import dotc.core.Contexts.{Context, ContextBase}
7+
import dotc.core.Contexts.{Context, ContextBase, ctx}
88
import dotc.core.Comments.{ContextDoc, ContextDocstrings}
99
import dotc.core.Phases.Phase
1010
import dotc.Compiler
@@ -58,7 +58,7 @@ trait DottyBytecodeTest {
5858

5959
/** Checks source code from raw strings */
6060
def checkBCode(scalaSources: List[String], javaSources: List[String] = Nil)(checkOutput: AbstractFile => Unit): Unit = {
61-
implicit val ctx: Context = initCtx
61+
given Context = initCtx
6262

6363
val compiler = new Compiler
6464
val run = compiler.newRun

compiler/test/dotty/tools/compilerSupport.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import dotc.core.Comments.{ContextDoc, ContextDocstrings}
2020
def inCompilerContext[T](classpath: String, separateRun: Boolean = true, scalaSources: String*)(op: Context ?=> T): T =
2121
val compiler = Compiler()
2222
val rootCtx = initCtx(classpath)
23-
val firstRun = compiler.newRun(rootCtx)
23+
val firstRun = compiler.newRun(using rootCtx)
2424
firstRun.compileFromStrings(scalaSources.toList)
2525
val opRun = if separateRun
26-
then compiler.newRun(rootCtx)
26+
then compiler.newRun(using rootCtx)
2727
else firstRun
2828
op(using opRun.runContext)
2929

compiler/test/dotty/tools/dotc/ast/DesugarTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class DesugarTests extends DottyTest {
2323

2424
@Test def caseClassHasCorrectMembers: Unit =
2525
checkCompile("typer", "case class Foo(x: Int, y: String)") { (tree, context) =>
26-
implicit val ctx = context
26+
given Context = context
2727
val ccTree = tree.find(tree => tree.symbol.name == typeName("Foo")).get
2828
val List(_, foo) = defPath(ccTree.symbol, tree).map(_.symbol.info)
2929

@@ -38,7 +38,7 @@ class DesugarTests extends DottyTest {
3838

3939
@Test def caseClassCompanionHasCorrectMembers: Unit =
4040
checkCompile("typer", "case class Foo(x: Int, y: String)") { (tree, context) =>
41-
implicit val ctx = context
41+
given Context = context
4242
val ccTree = tree.find(tree => tree.symbol.name == termName("Foo")).get
4343
val List(_, foo) = defPath(ccTree.symbol, tree).map(_.symbol.info)
4444

compiler/test/dotty/tools/dotc/ast/TreeInfoTest.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import core.StdNames.nme
88
import core.Types._
99
import core.Symbols._
1010
import org.junit.Assert._
11+
import core.Contexts.{Context, ctx}
1112

1213
class TreeInfoTest extends DottyTest {
1314

@@ -16,7 +17,7 @@ class TreeInfoTest extends DottyTest {
1617
@Test
1718
def testDefPath: Unit = checkCompile("typer", "class A { def bar = { val x = { val z = 0; 0} }} ") {
1819
(tree, context) =>
19-
implicit val ctx = context
20+
given Context = context
2021
val xTree = tree.find(tree => tree.symbol.name == termName("x")).get
2122
val path = defPath(xTree.symbol, tree)
2223
assertEquals(List(

compiler/test/dotty/tools/dotc/classpath/ZipAndJarFileLookupFactoryTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import org.junit.Test
44
import java.nio.file._
55
import java.nio.file.attribute.FileTime
66

7-
import dotty.tools.dotc.core.Contexts.{Context, ContextBase}
7+
import dotty.tools.dotc.core.Contexts.{Context, ContextBase, ctx}
88
import dotty.tools.io.AbstractFile
99

1010

@@ -16,7 +16,7 @@ class ZipAndJarFileLookupFactoryTest {
1616
val f = Files.createTempFile("test-", ".jar")
1717
Files.delete(f)
1818

19-
implicit val ctx: Context = new ContextBase().initialCtx
19+
given Context = new ContextBase().initialCtx
2020
assert(!ctx.settings.YdisableFlatCpCaching.value) // we're testing with our JAR metadata caching enabled.
2121

2222
def createCp = ZipAndJarClassPathFactory.create(AbstractFile.getFile(f))

compiler/test/dotty/tools/dotc/parsing/ModifiersParsingTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import core.Contexts._
1414
import core.Flags
1515

1616
object ModifiersParsingTest {
17-
implicit val ctx: Context = (new ContextBase).initialCtx
17+
given Context = (new ContextBase).initialCtx
1818

1919
def parse(code: String): Tree = {
2020
val (_, stats) = new Parser(SourceFile.virtual("<meta>", code)).templateStatSeq()
@@ -74,7 +74,7 @@ object ModifiersParsingTest {
7474

7575

7676
class ModifiersParsingTest {
77-
import ModifiersParsingTest._
77+
import ModifiersParsingTest.{_, given _}
7878

7979

8080
@Test def valDef = {

compiler/test/dotty/tools/dotc/printing/PrinterTests.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import dotty.tools.dotc.ast.{Trees,tpd}
55
import dotty.tools.dotc.core.Names._
66
import dotty.tools.dotc.core.Symbols._
77
import dotty.tools.dotc.core.Decorators._
8+
import dotty.tools.dotc.core.Contexts.{Context, ctx}
9+
810
import org.junit.Assert.assertEquals
911
import org.junit.Test
1012

@@ -26,7 +28,7 @@ class PrinterTests extends DottyTest {
2628
"""
2729

2830
checkCompile("typer", source) { (tree, context) =>
29-
implicit val ctx = context
31+
given Context = context
3032
val bar = tree.find(tree => tree.symbol.name == termName("bar")).get
3133
assertEquals("package object foo", bar.symbol.owner.show)
3234
}
@@ -43,7 +45,7 @@ class PrinterTests extends DottyTest {
4345
""".stripMargin
4446

4547
checkCompile("typer", source) { (tree, context) =>
46-
implicit val ctx = context
48+
given Context = context
4749
val bar @ Trees.DefDef(_, _, _, _, _) = tree.find(tree => tree.symbol.name == termName("bar2")).get
4850
assertEquals("Int & (Boolean | String)", bar.tpt.show)
4951
}

compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class SyntaxHighlightingTests extends DottyTest {
1111

1212
private def test(source: String, expected: String): Unit = {
1313
val testCtx = ctx.fresh.setSetting(ctx.settings.color, "always")
14-
val highlighted = SyntaxHighlighting.highlight(source)(testCtx)
14+
val highlighted = SyntaxHighlighting.highlight(source)(using testCtx)
1515
.replace(NoColor, ">")
1616
.replace(CommentColor, "<C|")
1717
.replace(KeywordColor, "<K|")

compiler/test/dotty/tools/dotc/reporting/UserDefinedErrorMessages.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class UserDefinedErrorMessages extends ErrorMessagesTest {
2424
|}
2525
""".stripMargin
2626
}.expect { (itcx, messages) =>
27-
implicit val ctx: Context = itcx
27+
given Context = itcx
2828

2929
assertMessageCount(1, messages)
3030
val (m: NoExplanation) :: Nil = messages
@@ -48,7 +48,7 @@ class UserDefinedErrorMessages extends ErrorMessagesTest {
4848
|}
4949
""".stripMargin
5050
}.expect { (itcx, messages) =>
51-
implicit val ctx: Context = itcx
51+
given Context = itcx
5252

5353
assertMessageCount(1, messages)
5454
val (m: NoExplanation) :: Nil = messages
@@ -73,7 +73,7 @@ class UserDefinedErrorMessages extends ErrorMessagesTest {
7373
|}
7474
""".stripMargin
7575
}.expect { (itcx, messages) =>
76-
implicit val ctx: Context = itcx
76+
given Context = itcx
7777

7878
assertMessageCount(1, messages)
7979
val (m: NoExplanation) :: Nil = messages
@@ -95,7 +95,7 @@ class UserDefinedErrorMessages extends ErrorMessagesTest {
9595
|}
9696
""".stripMargin
9797
}.expect { (itcx, messages) =>
98-
implicit val ctx: Context = itcx
98+
given Context = itcx
9999

100100
assertMessageCount(1, messages)
101101
val (m: NoExplanation) :: Nil = messages
@@ -117,7 +117,7 @@ class UserDefinedErrorMessages extends ErrorMessagesTest {
117117
|}
118118
""".stripMargin
119119
}.expect { (itcx, messages) =>
120-
implicit val ctx: Context = itcx
120+
given Context = itcx
121121

122122
assertMessageCount(1, messages)
123123
val (m: NoExplanation) :: Nil = messages

compiler/test/dotty/tools/dotc/transform/CreateCompanionObjectsTest.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CreateCompanionObjectsTest extends DottyTest {
2525
@Test
2626
def shouldCreateNonExistingObjectsInPackage = checkCompile("typer", "class A{} ") {
2727
(tree, context) =>
28-
implicit val ctx = context
28+
given Context = context
2929
3030
val transformer = new PostTyperTransformer {
3131
override def transformations = Array(new CreateCompanionObjects {
@@ -51,7 +51,7 @@ class CreateCompanionObjectsTest extends DottyTest {
5151
@Test
5252
def shouldCreateNonExistingObjectsInBlock = checkCompile("typer", "class D {def p = {class A{}; 1}} ") {
5353
(tree, context) =>
54-
implicit val ctx = context
54+
given Context = context
5555
val transformer = new PostTyperTransformer {
5656
override def transformations = Array(new CreateCompanionObjects {
5757
@@ -76,7 +76,7 @@ class CreateCompanionObjectsTest extends DottyTest {
7676
@Test
7777
def shouldCreateNonExistingObjectsInTemplate = checkCompile("typer", "class D {class A{}; } ") {
7878
(tree, context) =>
79-
implicit val ctx = context
79+
given Context = context
8080
val transformer = new PostTyperTransformer {
8181
override def transformations = Array(new CreateCompanionObjects {
8282
override def name: String = "create all companion modules"
@@ -100,7 +100,7 @@ class CreateCompanionObjectsTest extends DottyTest {
100100
@Test
101101
def shouldCreateOnlyIfAskedFor = checkCompile("typer", "class DONT {class CREATE{}; } ") {
102102
(tree, context) =>
103-
implicit val ctx = context
103+
given Context = context
104104
val transformer = new PostTyperTransformer {
105105
override def transformations = Array(new CreateCompanionObjects {
106106
override def name: String = "create all companion modules"

compiler/test/dotty/tools/dotc/transform/PostTyperTransformerTest.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class PostTyperTransformerTest extends DottyTest {
2020
@Test
2121
def shouldStripImports = checkCompile("typer", "class A{ import scala.collection.mutable._; val d = 1}") {
2222
(tree, context) =>
23-
implicit val ctx = context
23+
given Context = context
2424
class EmptyTransform extends TreeTransform {
2525
override def name: String = "empty"
2626
init(ctx, ctx.period.firstPhaseId, ctx.period.lastPhaseId)
@@ -40,7 +40,7 @@ class PostTyperTransformerTest extends DottyTest {
4040
@Test
4141
def shouldStripNamedArgs = checkCompile("typer", "class A{ def p(x:Int, y:Int= 2) = 1; p(1, y = 2)}") {
4242
(tree, context) =>
43-
implicit val ctx = context
43+
given Context = context
4444
class EmptyTransform extends TreeTransform {
4545
override def name: String = "empty"
4646
init(ctx, ctx.period.firstPhaseId, ctx.period.lastPhaseId)
@@ -60,7 +60,7 @@ class PostTyperTransformerTest extends DottyTest {
6060
@Test
6161
def shouldReorderExistingObjectsInPackage = checkCompile("typer", "object A{}; class A{} ") {
6262
(tree, context) =>
63-
implicit val ctx = context
63+
given Context = context
6464
class EmptyTransform extends TreeTransform {
6565
override def name: String = "empty"
6666
init(ctx, ctx.period.firstPhaseId, ctx.period.lastPhaseId)
@@ -84,7 +84,7 @@ class PostTyperTransformerTest extends DottyTest {
8484
@Test
8585
def shouldReorderExistingObjectsInBlock = checkCompile("typer", "class D {def p = {object A{}; class A{}; 1}} ") {
8686
(tree, context) =>
87-
implicit val ctx = context
87+
given Context = context
8888
class EmptyTransform extends TreeTransform {
8989
override def name: String = "empty"
9090
init(ctx, ctx.period.firstPhaseId, ctx.period.lastPhaseId)
@@ -108,7 +108,7 @@ class PostTyperTransformerTest extends DottyTest {
108108
@Test
109109
def shouldReorderExistingObjectsInTemplate = checkCompile("typer", "class D {object A{}; class A{}; } ") {
110110
(tree, context) =>
111-
implicit val ctx = context
111+
given Context = context
112112
class EmptyTransform extends TreeTransform {
113113
override def name: String = "empty"
114114
init(ctx, ctx.period.firstPhaseId, ctx.period.lastPhaseId)

compiler/test/dotty/tools/dotc/transform/TreeTransformerTest.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class TreeTransformerTest extends DottyTest {
1313
@Test
1414
def shouldReturnSameTreeIfUnchanged: Unit = checkCompile("typer", "class A{ val d = 1}") {
1515
(tree, context) =>
16-
implicit val ctx = context
16+
given Context = context
1717
class EmptyTransform extends MiniPhase {
1818
override def phaseName: String = "empty"
1919
init(ctx.base, ctx.period.firstPhaseId, ctx.period.lastPhaseId)
@@ -29,7 +29,7 @@ class TreeTransformerTest extends DottyTest {
2929
// Disabled, awaiting resolution. @Test
3030
def canReplaceConstant: Unit = checkCompile("typer", "class A{ val d = 1}") {
3131
(tree, context) =>
32-
implicit val ctx = context
32+
given Context = context
3333
class ConstantTransform extends MiniPhase {
3434

3535
override def transformLiteral(tree: tpd.Literal)(implicit ctx: Context): tpd.Tree = tpd.Literal(Constant(2))
@@ -47,7 +47,7 @@ class TreeTransformerTest extends DottyTest {
4747
@Test
4848
def canOverwrite: Unit = checkCompile("typer", "class A{ val d = 1}") {
4949
(tree, context) =>
50-
implicit val ctx = context
50+
given Context = context
5151
class Transformation extends MiniPhase {
5252

5353
override def transformLiteral(tree: tpd.Literal)(implicit ctx: Context): tpd.Tree = tpd.Literal(Constant(-1))
@@ -73,7 +73,7 @@ class TreeTransformerTest extends DottyTest {
7373
@Test
7474
def transformationOrder: Unit = checkCompile("typer", "class A{ val d = 1}") {
7575
(tree, context) =>
76-
implicit val ctx = context
76+
given Context = context
7777
class Transformation1 extends MiniPhase {
7878
override def phaseName: String = "transformationOrder1"
7979

@@ -115,7 +115,7 @@ class TreeTransformerTest extends DottyTest {
115115
@Test
116116
def invocationCount: Unit = checkCompile("typer", "class A{ val d = 1}") {
117117
(tree, context) =>
118-
implicit val ctx = context
118+
given Context = context
119119
var transformed1 = 0
120120
class Transformation1 extends MiniPhase {
121121
override def phaseName: String = "invocationCount1"

compiler/test/dotty/tools/dotc/typer/DivergenceChecker.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class DivergenceCheckerTests extends DottyTest {
3333

3434
checkTypes(source, List(types, elements)) {
3535
case (List(tpes, elements0), context) =>
36-
implicit val ctx = context
36+
given Context = context
3737

3838
val List(a, b, n, o, s, t2, i, l) = elements0.map(_.typeConstructor)
3939
val expectedCoveringSets = List(

compiler/test/dotty/tools/dotc/typer/SubtypingInvariantTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class SubtypingInvariantTests extends DottyTest {
1111
@Test
1212
def typeVarInvariant(): Unit = {
1313
checkCompile("typer", "class A") { (_, ctx0) =>
14-
implicit val ctx: Context = ctx0
14+
given Context = ctx0
1515
val a = newTypeVar(TypeBounds.empty)
1616
val b = newTypeVar(TypeBounds.empty)
1717
assert(a <:< b)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java.util.regex.Pattern
44

55
import org.junit.Assert.{assertTrue => assert, _}
66
import org.junit.{Ignore, Test}
7+
import dotty.tools.dotc.core.Contexts.Context
78

89
class ReplCompilerTests extends ReplTest {
910
import ReplCompilerTests._
@@ -189,7 +190,7 @@ class ReplCompilerTests extends ReplTest {
189190
}
190191

191192
@Test def i7934: Unit = fromInitialState { state =>
192-
implicit val ctx = state.context
193+
given Context = state.context
193194
assertFalse(ParseResult.isIncomplete("_ + 1")) // was: assertThrows[NullPointerException]
194195
}
195196

0 commit comments

Comments
 (0)