Skip to content

Fix #1784: allow to omit types for local implicit vals #1785

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 7 commits into from
Dec 15, 2016
Merged
Show file tree
Hide file tree
Changes from 3 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
64 changes: 32 additions & 32 deletions compiler/sjs/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class JSCodeGen()(implicit ctx: Context) {
/* Finally, we emit true code for the remaining class defs. */
for (td <- allTypeDefs) {
val sym = td.symbol
implicit val pos: Position = sym.pos
implicit val pos = sym.pos

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

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

val classIdent = encodeClassFullNameIdent(sym)
val superClass =
Expand All @@ -358,7 +358,7 @@ class JSCodeGen()(implicit ctx: Context) {
*/
private def genInterface(td: TypeDef): js.ClassDef = {
val sym = td.symbol.asClass
implicit val pos: Position = sym.pos
implicit val pos = sym.pos

val classIdent = encodeClassFullNameIdent(sym)

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

val name =
/*if (isExposed(f)) js.StringLiteral(jsNameOf(f))
Expand Down Expand Up @@ -479,7 +479,7 @@ class JSCodeGen()(implicit ctx: Context) {
* Other (normal) methods are emitted with `genMethodBody()`.
*/
private def genMethodWithCurrentLocalNameScope(dd: DefDef): Option[js.MethodDef] = {
implicit val pos: Position = dd.pos
implicit val pos = dd.pos
val sym = dd.symbol
val vparamss = dd.vparamss
val rhs = dd.rhs
Expand All @@ -501,7 +501,7 @@ class JSCodeGen()(implicit ctx: Context) {
val methodName: js.PropertyName = encodeMethodSym(sym)

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

ctx.debuglog("genMethod " + methodName.name)
ctx.debuglog("")

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

ctx.debuglog(" " + tree)
ctx.debuglog("")
Expand Down Expand Up @@ -902,7 +902,7 @@ class JSCodeGen()(implicit ctx: Context) {
* primitives, JS calls, etc. They are further dispatched in here.
*/
private def genApply(tree: Apply, isStat: Boolean): js.Tree = {
implicit val pos: Position = tree.pos
implicit val pos = tree.pos
val args = tree.args
val sym = tree.fun.symbol

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

Expand Down Expand Up @@ -987,7 +987,7 @@ class JSCodeGen()(implicit ctx: Context) {
* * regular new
*/
private def genApplyNew(tree: Apply): js.Tree = {
implicit val pos: Position = tree.pos
implicit val pos = tree.pos

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

implicit val pos: Position = tree.pos
implicit val pos = tree.pos

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

implicit val pos: Position = tree.pos
implicit val pos = tree.pos

val genArg = genExpr(arg)
val resultIRType = toIRType(tree.tpe)
Expand Down Expand Up @@ -1118,7 +1118,7 @@ class JSCodeGen()(implicit ctx: Context) {
}
import OpTypes._

implicit val pos: Position = tree.pos
implicit val pos = tree.pos

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

val arg = args.head

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

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

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

implicit val pos: Position = tree.pos
implicit val pos = tree.pos

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

implicit val pos: Position = tree.pos
implicit val pos = tree.pos

val source = genExpr(receiver)

Expand Down Expand Up @@ -1544,7 +1544,7 @@ class JSCodeGen()(implicit ctx: Context) {

/** Gen a call to the special `throw` method. */
private def genThrow(tree: Apply, args: List[Tree]): js.Tree = {
implicit val pos: Position = tree.pos
implicit val pos = tree.pos
val exception = args.head
val genException = genExpr(exception)
js.Throw {
Expand All @@ -1568,7 +1568,7 @@ class JSCodeGen()(implicit ctx: Context) {
* * Regular method call
*/
private def genNormalApply(tree: Apply, isStat: Boolean): js.Tree = {
implicit val pos: Position = tree.pos
implicit val pos = tree.pos

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

implicit val pos: Position = tree.pos
implicit val pos = tree.pos

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

val TypeApply(fun, targs) = tree

Expand Down Expand Up @@ -1803,7 +1803,7 @@ class JSCodeGen()(implicit ctx: Context) {

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

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

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

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

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

if (sym == defn.ObjectClass) {
Expand Down Expand Up @@ -2242,7 +2242,7 @@ class JSCodeGen()(implicit ctx: Context) {
* to perform the conversion to js.Array, then wrap in a Spread
* operator.
*/
implicit val pos: Position = arg.pos
implicit val pos = arg.pos
val jsArrayArg = genModuleApplyMethod(
jsdefn.RuntimePackage_genTraversableOnce2jsArray,
List(genExpr(arg)))
Expand All @@ -2259,7 +2259,7 @@ class JSCodeGen()(implicit ctx: Context) {
*/
private def tryGenRepeatedParamAsJSArray(arg: Tree,
handleNil: Boolean): Option[List[js.Tree]] = {
implicit val pos: Position = arg.pos
implicit val pos = arg.pos

// Given a method `def foo(args: T*)`
arg match {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/scalaPrimitives.scala
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class DottyPrimitives(ctx: Context) {
/** Initialize the primitive map */
private def init: immutable.Map[Symbol, Int] = {

implicit val ctx: Context = this.ctx
implicit val ctx = this.ctx

import core.Symbols.defn
val primitives = new mutable.HashMap[Symbol, Int]()
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ object Trees {
case AppliedTypeTree(tpt, args) =>
this(this(x, tpt), args)
case PolyTypeTree(tparams, body) =>
implicit val ctx: Context = localCtx
implicit val ctx = localCtx
this(this(x, tparams), body)
case ByNameTypeTree(result) =>
this(x, result)
Expand All @@ -1237,13 +1237,13 @@ object Trees {
case UnApply(fun, implicits, patterns) =>
this(this(this(x, fun), implicits), patterns)
case tree @ ValDef(name, tpt, _) =>
implicit val ctx: Context = localCtx
implicit val ctx = localCtx
this(this(x, tpt), tree.rhs)
case tree @ DefDef(name, tparams, vparamss, tpt, _) =>
implicit val ctx: Context = localCtx
implicit val ctx = localCtx
this(this((this(x, tparams) /: vparamss)(apply), tpt), tree.rhs)
case TypeDef(name, rhs) =>
implicit val ctx: Context = localCtx
implicit val ctx = localCtx
this(x, rhs)
case tree @ Template(constr, parents, self, _) =>
this(this(this(this(x, constr), parents), self), tree.body)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/PathResolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ object PathResolver {
println(Defaults)
}
else {
implicit val ctx: Context = (new ContextBase).initialCtx // Dotty deviation: implicits need explicit type
implicit val ctx = (new ContextBase).initialCtx // Dotty deviation: implicits need explicit type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another obsolete comment.

val ArgsSummary(sstate, rest, errors) =
ctx.settings.processArguments(args.toList, true)
errors.foreach(println)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ trait SymDenotations { this: Context =>
def explainSym(msg: String) = explain(s"$msg\n defined = ${denot.definedPeriodsString}")
if (denot.is(ValidForever) || denot.isRefinementClass) true
else {
implicit val ctx: Context = this
implicit val ctx = this
val initial = denot.initial
if ((initial ne denot) || ctx.phaseId != initial.validFor.firstPhaseId) {
ctx.withPhase(initial.validFor.firstPhaseId).traceInvalid(initial)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import scala.util.control.NonFatal
/** Provides methods to compare types.
*/
class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
implicit val ctx: Context = initctx
implicit val ctx = initctx

val state = ctx.typerState
import state.constraint
Expand Down Expand Up @@ -156,7 +156,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
private def firstTry(tp1: Type, tp2: Type): Boolean = tp2 match {
case tp2: NamedType =>
def compareNamed(tp1: Type, tp2: NamedType): Boolean = {
implicit val ctx: Context = this.ctx
implicit val ctx = this.ctx
tp2.info match {
case info2: TypeAlias => isSubType(tp1, info2.alias)
case _ => tp1 match {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3378,7 +3378,7 @@ object Types {

/** Map this function over given type */
def mapOver(tp: Type): Type = {
implicit val ctx: Context = this.ctx // Dotty deviation: implicits need explicit type
implicit val ctx = this.ctx // Dotty deviation: implicits need explicit type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the comment is obsolete :P

tp match {
case tp: NamedType =>
if (stopAtStatic && tp.symbol.isStatic) tp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object MessageContainer {

implicit class MessageContext(val c: Context) extends AnyVal {
def shouldExplain(cont: MessageContainer): Boolean = {
implicit val ctx: Context = c
implicit val ctx = c
cont.contained.explanation match {
case "" => false
case _ => ctx.settings.explain.value
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ object Erasure extends TypeTestsCasts{
val bridge = ctx.newSymbol(ctx.owner, nme.ANON_FUN, Flags.Synthetic | Flags.Method, sam.info)
val bridgeCtx = ctx.withOwner(bridge)
Closure(bridge, bridgeParamss => {
implicit val ctx: Context = bridgeCtx
implicit val ctx = bridgeCtx

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

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

val rhs = paramss.foldLeft(sel)((fun, vparams) =>
fun.tpe.widen match {
Expand Down
Loading