Skip to content

Commit 4c1bf42

Browse files
committed
Drop explicit types for local implicit vals
Drop explicit types for local implicit vals of type Context and Position. Exercises the functionality and shortens the code.
1 parent 1c03d45 commit 4c1bf42

File tree

13 files changed

+49
-49
lines changed

13 files changed

+49
-49
lines changed

compiler/sjs/backend/sjs/JSCodeGen.scala

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class JSCodeGen()(implicit ctx: Context) {
127127
/* Finally, we emit true code for the remaining class defs. */
128128
for (td <- allTypeDefs) {
129129
val sym = td.symbol
130-
implicit val pos: Position = sym.pos
130+
implicit val pos = sym.pos
131131

132132
/* Do not actually emit code for primitive types nor scala.Array. */
133133
val isPrimitive =
@@ -203,7 +203,7 @@ class JSCodeGen()(implicit ctx: Context) {
203203
*/
204204
private def genScalaClass(td: TypeDef): js.ClassDef = {
205205
val sym = td.symbol.asClass
206-
implicit val pos: Position = sym.pos
206+
implicit val pos = sym.pos
207207

208208
assert(!sym.is(Trait),
209209
"genScalaClass() must be called only for normal classes: "+sym)
@@ -336,7 +336,7 @@ class JSCodeGen()(implicit ctx: Context) {
336336
*/
337337
private def genRawJSClassData(td: TypeDef): js.ClassDef = {
338338
val sym = td.symbol.asClass
339-
implicit val pos: Position = sym.pos
339+
implicit val pos = sym.pos
340340

341341
val classIdent = encodeClassFullNameIdent(sym)
342342
val superClass =
@@ -358,7 +358,7 @@ class JSCodeGen()(implicit ctx: Context) {
358358
*/
359359
private def genInterface(td: TypeDef): js.ClassDef = {
360360
val sym = td.symbol.asClass
361-
implicit val pos: Position = sym.pos
361+
implicit val pos = sym.pos
362362

363363
val classIdent = encodeClassFullNameIdent(sym)
364364

@@ -408,7 +408,7 @@ class JSCodeGen()(implicit ctx: Context) {
408408
f <- classSym.info.decls
409409
if !f.is(Method) && f.isTerm
410410
} yield {
411-
implicit val pos: Position = f.pos
411+
implicit val pos = f.pos
412412

413413
val name =
414414
/*if (isExposed(f)) js.StringLiteral(jsNameOf(f))
@@ -479,7 +479,7 @@ class JSCodeGen()(implicit ctx: Context) {
479479
* Other (normal) methods are emitted with `genMethodBody()`.
480480
*/
481481
private def genMethodWithCurrentLocalNameScope(dd: DefDef): Option[js.MethodDef] = {
482-
implicit val pos: Position = dd.pos
482+
implicit val pos = dd.pos
483483
val sym = dd.symbol
484484
val vparamss = dd.vparamss
485485
val rhs = dd.rhs
@@ -501,7 +501,7 @@ class JSCodeGen()(implicit ctx: Context) {
501501
val methodName: js.PropertyName = encodeMethodSym(sym)
502502

503503
def jsParams = for (param <- params) yield {
504-
implicit val pos: Position = param.pos
504+
implicit val pos = param.pos
505505
js.ParamDef(encodeLocalSym(param), toIRType(param.info),
506506
mutable = false, rest = false)
507507
}
@@ -574,13 +574,13 @@ class JSCodeGen()(implicit ctx: Context) {
574574
private def genMethodDef(static: Boolean, methodName: js.PropertyName,
575575
paramsSyms: List[Symbol], resultIRType: jstpe.Type,
576576
tree: Tree, optimizerHints: OptimizerHints): js.MethodDef = {
577-
implicit val pos: Position = tree.pos
577+
implicit val pos = tree.pos
578578

579579
ctx.debuglog("genMethod " + methodName.name)
580580
ctx.debuglog("")
581581

582582
val jsParams = for (param <- paramsSyms) yield {
583-
implicit val pos: Position = param.pos
583+
implicit val pos = param.pos
584584
js.ParamDef(encodeLocalSym(param), toIRType(param.info),
585585
mutable = false, rest = false)
586586
}
@@ -621,7 +621,7 @@ class JSCodeGen()(implicit ctx: Context) {
621621
/* Any JavaScript expression is also a statement, but at least we get rid
622622
* of some pure expressions that come from our own codegen.
623623
*/
624-
implicit val pos: Position = tree.pos
624+
implicit val pos = tree.pos
625625
tree match {
626626
case js.Block(stats :+ expr) => js.Block(stats :+ exprToStat(expr))
627627
case _:js.Literal | js.This() => js.Skip()
@@ -644,7 +644,7 @@ class JSCodeGen()(implicit ctx: Context) {
644644
* is transformed into an equivalent portion of the JS AST.
645645
*/
646646
private def genStatOrExpr(tree: Tree, isStat: Boolean): js.Tree = {
647-
implicit val pos: Position = tree.pos
647+
implicit val pos = tree.pos
648648

649649
ctx.debuglog(" " + tree)
650650
ctx.debuglog("")
@@ -902,7 +902,7 @@ class JSCodeGen()(implicit ctx: Context) {
902902
* primitives, JS calls, etc. They are further dispatched in here.
903903
*/
904904
private def genApply(tree: Apply, isStat: Boolean): js.Tree = {
905-
implicit val pos: Position = tree.pos
905+
implicit val pos = tree.pos
906906
val args = tree.args
907907
val sym = tree.fun.symbol
908908

@@ -951,7 +951,7 @@ class JSCodeGen()(implicit ctx: Context) {
951951
* irrelevant.
952952
*/
953953
private def genSuperCall(tree: Apply, isStat: Boolean): js.Tree = {
954-
implicit val pos: Position = tree.pos
954+
implicit val pos = tree.pos
955955
val Apply(fun @ Select(sup @ Super(_, mix), _), args) = tree
956956
val sym = fun.symbol
957957

@@ -987,7 +987,7 @@ class JSCodeGen()(implicit ctx: Context) {
987987
* * regular new
988988
*/
989989
private def genApplyNew(tree: Apply): js.Tree = {
990-
implicit val pos: Position = tree.pos
990+
implicit val pos = tree.pos
991991

992992
val Apply(fun @ Select(New(tpt), nme.CONSTRUCTOR), args) = tree
993993
val ctor = fun.symbol
@@ -1023,7 +1023,7 @@ class JSCodeGen()(implicit ctx: Context) {
10231023
private def genPrimitiveOp(tree: Apply, isStat: Boolean): js.Tree = {
10241024
import scala.tools.nsc.backend.ScalaPrimitives._
10251025

1026-
implicit val pos: Position = tree.pos
1026+
implicit val pos = tree.pos
10271027

10281028
val Apply(fun, args) = tree
10291029
val receiver = qualifierOf(fun)
@@ -1063,7 +1063,7 @@ class JSCodeGen()(implicit ctx: Context) {
10631063
private def genSimpleUnaryOp(tree: Apply, arg: Tree, code: Int): js.Tree = {
10641064
import scala.tools.nsc.backend.ScalaPrimitives._
10651065

1066-
implicit val pos: Position = tree.pos
1066+
implicit val pos = tree.pos
10671067

10681068
val genArg = genExpr(arg)
10691069
val resultIRType = toIRType(tree.tpe)
@@ -1118,7 +1118,7 @@ class JSCodeGen()(implicit ctx: Context) {
11181118
}
11191119
import OpTypes._
11201120

1121-
implicit val pos: Position = tree.pos
1121+
implicit val pos = tree.pos
11221122

11231123
val lhsIRType = toIRType(lhs.tpe)
11241124
val rhsIRType = toIRType(rhs.tpe)
@@ -1374,7 +1374,7 @@ class JSCodeGen()(implicit ctx: Context) {
13741374
*/
13751375
private def genStringConcat(tree: Apply, receiver: Tree,
13761376
args: List[Tree]): js.Tree = {
1377-
implicit val pos: Position = tree.pos
1377+
implicit val pos = tree.pos
13781378

13791379
val arg = args.head
13801380

@@ -1401,7 +1401,7 @@ class JSCodeGen()(implicit ctx: Context) {
14011401

14021402
/** Gen JS code for a call to Any.## */
14031403
private def genScalaHash(tree: Apply, receiver: Tree): js.Tree = {
1404-
implicit val pos: Position = tree.pos
1404+
implicit val pos = tree.pos
14051405

14061406
genModuleApplyMethod(defn.ScalaRuntimeModule.requiredMethod(nme.hash_),
14071407
List(genExpr(receiver)))
@@ -1411,7 +1411,7 @@ class JSCodeGen()(implicit ctx: Context) {
14111411
private def genArrayOp(tree: Tree, code: Int): js.Tree = {
14121412
import scala.tools.nsc.backend.ScalaPrimitives._
14131413

1414-
implicit val pos: Position = tree.pos
1414+
implicit val pos = tree.pos
14151415

14161416
val Apply(fun, args) = tree
14171417
val arrayObj = qualifierOf(fun)
@@ -1462,7 +1462,7 @@ class JSCodeGen()(implicit ctx: Context) {
14621462
// common case for which there is no side-effect nor NPE
14631463
genArg
14641464
case _ =>
1465-
implicit val pos: Position = tree.pos
1465+
implicit val pos = tree.pos
14661466
/* TODO Check for a null receiver?
14671467
* In theory, it's UB, but that decision should be left for link time.
14681468
*/
@@ -1474,7 +1474,7 @@ class JSCodeGen()(implicit ctx: Context) {
14741474
private def genCoercion(tree: Apply, receiver: Tree, code: Int): js.Tree = {
14751475
import scala.tools.nsc.backend.ScalaPrimitives._
14761476

1477-
implicit val pos: Position = tree.pos
1477+
implicit val pos = tree.pos
14781478

14791479
val source = genExpr(receiver)
14801480

@@ -1544,7 +1544,7 @@ class JSCodeGen()(implicit ctx: Context) {
15441544

15451545
/** Gen a call to the special `throw` method. */
15461546
private def genThrow(tree: Apply, args: List[Tree]): js.Tree = {
1547-
implicit val pos: Position = tree.pos
1547+
implicit val pos = tree.pos
15481548
val exception = args.head
15491549
val genException = genExpr(exception)
15501550
js.Throw {
@@ -1568,7 +1568,7 @@ class JSCodeGen()(implicit ctx: Context) {
15681568
* * Regular method call
15691569
*/
15701570
private def genNormalApply(tree: Apply, isStat: Boolean): js.Tree = {
1571-
implicit val pos: Position = tree.pos
1571+
implicit val pos = tree.pos
15721572

15731573
val fun = tree.fun match {
15741574
case fun: Ident => desugarIdent(fun).get
@@ -1616,7 +1616,7 @@ class JSCodeGen()(implicit ctx: Context) {
16161616
superIn: Option[Symbol] = None)(
16171617
implicit pos: Position): js.Tree = {
16181618

1619-
implicit val pos: Position = tree.pos
1619+
implicit val pos = tree.pos
16201620

16211621
def noSpread = !args.exists(_.isInstanceOf[js.JSSpread])
16221622
val argc = args.size // meaningful only for methods that don't have varargs
@@ -1775,7 +1775,7 @@ class JSCodeGen()(implicit ctx: Context) {
17751775
* primitive instead.)
17761776
*/
17771777
private def genTypeApply(tree: TypeApply): js.Tree = {
1778-
implicit val pos: Position = tree.pos
1778+
implicit val pos = tree.pos
17791779

17801780
val TypeApply(fun, targs) = tree
17811781

@@ -1803,7 +1803,7 @@ class JSCodeGen()(implicit ctx: Context) {
18031803

18041804
/** Gen JS code for a Java Seq literal. */
18051805
private def genJavaSeqLiteral(tree: JavaSeqLiteral): js.Tree = {
1806-
implicit val pos: Position = tree.pos
1806+
implicit val pos = tree.pos
18071807

18081808
val genElems = tree.elems.map(genExpr)
18091809
val arrayType = toReferenceType(tree.tpe).asInstanceOf[jstpe.ArrayType]
@@ -1852,7 +1852,7 @@ class JSCodeGen()(implicit ctx: Context) {
18521852
* available in the `body`.
18531853
*/
18541854
private def genClosure(tree: Closure): js.Tree = {
1855-
implicit val pos: Position = tree.pos
1855+
implicit val pos = tree.pos
18561856
val Closure(env, call, functionalInterface) = tree
18571857

18581858
val envSize = env.size
@@ -1868,7 +1868,7 @@ class JSCodeGen()(implicit ctx: Context) {
18681868
val allCaptureValues = qualifier :: env
18691869

18701870
val (formalCaptures, actualCaptures) = allCaptureValues.map { value =>
1871-
implicit val pos: Position = value.pos
1871+
implicit val pos = value.pos
18721872
val formalIdent = value match {
18731873
case Ident(name) => freshLocalIdent(name.toString)
18741874
case This(_) => freshLocalIdent("this")
@@ -1988,7 +1988,7 @@ class JSCodeGen()(implicit ctx: Context) {
19881988

19891989
/** Gen JS code for an isInstanceOf test (for reference types only) */
19901990
private def genIsInstanceOf(tree: Tree, value: js.Tree, to: Type): js.Tree = {
1991-
implicit val pos: Position = tree.pos
1991+
implicit val pos = tree.pos
19921992
val sym = to.widenDealias.typeSymbol
19931993

19941994
if (sym == defn.ObjectClass) {
@@ -2242,7 +2242,7 @@ class JSCodeGen()(implicit ctx: Context) {
22422242
* to perform the conversion to js.Array, then wrap in a Spread
22432243
* operator.
22442244
*/
2245-
implicit val pos: Position = arg.pos
2245+
implicit val pos = arg.pos
22462246
val jsArrayArg = genModuleApplyMethod(
22472247
jsdefn.RuntimePackage_genTraversableOnce2jsArray,
22482248
List(genExpr(arg)))
@@ -2259,7 +2259,7 @@ class JSCodeGen()(implicit ctx: Context) {
22592259
*/
22602260
private def tryGenRepeatedParamAsJSArray(arg: Tree,
22612261
handleNil: Boolean): Option[List[js.Tree]] = {
2262-
implicit val pos: Position = arg.pos
2262+
implicit val pos = arg.pos
22632263

22642264
// Given a method `def foo(args: T*)`
22652265
arg match {

compiler/src/dotty/tools/backend/jvm/scalaPrimitives.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class DottyPrimitives(ctx: Context) {
125125
/** Initialize the primitive map */
126126
private def init: immutable.Map[Symbol, Int] = {
127127

128-
implicit val ctx: Context = this.ctx
128+
implicit val ctx = this.ctx
129129

130130
import core.Symbols.defn
131131
val primitives = new mutable.HashMap[Symbol, Int]()

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ object Trees {
12241224
case AppliedTypeTree(tpt, args) =>
12251225
this(this(x, tpt), args)
12261226
case PolyTypeTree(tparams, body) =>
1227-
implicit val ctx: Context = localCtx
1227+
implicit val ctx = localCtx
12281228
this(this(x, tparams), body)
12291229
case ByNameTypeTree(result) =>
12301230
this(x, result)
@@ -1237,13 +1237,13 @@ object Trees {
12371237
case UnApply(fun, implicits, patterns) =>
12381238
this(this(this(x, fun), implicits), patterns)
12391239
case tree @ ValDef(name, tpt, _) =>
1240-
implicit val ctx: Context = localCtx
1240+
implicit val ctx = localCtx
12411241
this(this(x, tpt), tree.rhs)
12421242
case tree @ DefDef(name, tparams, vparamss, tpt, _) =>
1243-
implicit val ctx: Context = localCtx
1243+
implicit val ctx = localCtx
12441244
this(this((this(x, tparams) /: vparamss)(apply), tpt), tree.rhs)
12451245
case TypeDef(name, rhs) =>
1246-
implicit val ctx: Context = localCtx
1246+
implicit val ctx = localCtx
12471247
this(x, rhs)
12481248
case tree @ Template(constr, parents, self, _) =>
12491249
this(this(this(this(x, constr), parents), self), tree.body)

compiler/src/dotty/tools/dotc/config/PathResolver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ object PathResolver {
143143
println(Defaults)
144144
}
145145
else {
146-
implicit val ctx: Context = (new ContextBase).initialCtx // Dotty deviation: implicits need explicit type
146+
implicit val ctx = (new ContextBase).initialCtx // Dotty deviation: implicits need explicit type
147147
val ArgsSummary(sstate, rest, errors) =
148148
ctx.settings.processArguments(args.toList, true)
149149
errors.foreach(println)

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ trait SymDenotations { this: Context =>
7575
def explainSym(msg: String) = explain(s"$msg\n defined = ${denot.definedPeriodsString}")
7676
if (denot.is(ValidForever) || denot.isRefinementClass) true
7777
else {
78-
implicit val ctx: Context = this
78+
implicit val ctx = this
7979
val initial = denot.initial
8080
if ((initial ne denot) || ctx.phaseId != initial.validFor.firstPhaseId) {
8181
ctx.withPhase(initial.validFor.firstPhaseId).traceInvalid(initial)

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import scala.util.control.NonFatal
1616
/** Provides methods to compare types.
1717
*/
1818
class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
19-
implicit val ctx: Context = initctx
19+
implicit val ctx = initctx
2020

2121
val state = ctx.typerState
2222
import state.constraint
@@ -156,7 +156,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
156156
private def firstTry(tp1: Type, tp2: Type): Boolean = tp2 match {
157157
case tp2: NamedType =>
158158
def compareNamed(tp1: Type, tp2: NamedType): Boolean = {
159-
implicit val ctx: Context = this.ctx
159+
implicit val ctx = this.ctx
160160
tp2.info match {
161161
case info2: TypeAlias => isSubType(tp1, info2.alias)
162162
case _ => tp1 match {

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3378,7 +3378,7 @@ object Types {
33783378

33793379
/** Map this function over given type */
33803380
def mapOver(tp: Type): Type = {
3381-
implicit val ctx: Context = this.ctx // Dotty deviation: implicits need explicit type
3381+
implicit val ctx = this.ctx // Dotty deviation: implicits need explicit type
33823382
tp match {
33833383
case tp: NamedType =>
33843384
if (stopAtStatic && tp.symbol.isStatic) tp

compiler/src/dotty/tools/dotc/reporting/diagnostic/MessageContainer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object MessageContainer {
1414

1515
implicit class MessageContext(val c: Context) extends AnyVal {
1616
def shouldExplain(cont: MessageContainer): Boolean = {
17-
implicit val ctx: Context = c
17+
implicit val ctx = c
1818
cont.contained.explanation match {
1919
case "" => false
2020
case _ => ctx.settings.explain.value

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ object Erasure extends TypeTestsCasts{
575575
val bridge = ctx.newSymbol(ctx.owner, nme.ANON_FUN, Flags.Synthetic | Flags.Method, sam.info)
576576
val bridgeCtx = ctx.withOwner(bridge)
577577
Closure(bridge, bridgeParamss => {
578-
implicit val ctx: Context = bridgeCtx
578+
implicit val ctx = bridgeCtx
579579

580580
val List(bridgeParams) = bridgeParamss
581581
val rhs = Apply(meth, (bridgeParams, implParamTypes).zipped.map(adapt(_, _)))
@@ -691,7 +691,7 @@ object Erasure extends TypeTestsCasts{
691691
val bridgeCtx = ctx.withOwner(bridge)
692692

693693
tpd.DefDef(bridge, { paramss: List[List[tpd.Tree]] =>
694-
implicit val ctx: Context = bridgeCtx
694+
implicit val ctx = bridgeCtx
695695

696696
val rhs = paramss.foldLeft(sel)((fun, vparams) =>
697697
fun.tpe.widen match {

0 commit comments

Comments
 (0)