aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools
diff options
context:
space:
mode:
authorodersky <odersky@gmail.com>2016-12-15 17:44:06 +0100
committerGitHub <noreply@github.com>2016-12-15 17:44:06 +0100
commita5620ab882b95ef60acf42814ac5568d5f93bdd4 (patch)
treea524a250769cd72ebb316c30b8166c4c45d7fc43 /compiler/src/dotty/tools
parent9f2b5ad068c06c62e28a3543218f5c1bc0362f74 (diff)
parentbc869e74cb18ffdb4d42b59ad654f55403b9b6bd (diff)
downloaddotty-a5620ab882b95ef60acf42814ac5568d5f93bdd4.tar.gz
dotty-a5620ab882b95ef60acf42814ac5568d5f93bdd4.tar.bz2
dotty-a5620ab882b95ef60acf42814ac5568d5f93bdd4.zip
Merge pull request #1785 from dotty-staging/fix-#1784
Fix #1784: allow to omit types for local implicit vals
Diffstat (limited to 'compiler/src/dotty/tools')
-rw-r--r--compiler/src/dotty/tools/backend/jvm/scalaPrimitives.scala2
-rw-r--r--compiler/src/dotty/tools/dotc/ast/Trees.scala8
-rw-r--r--compiler/src/dotty/tools/dotc/config/PathResolver.scala2
-rw-r--r--compiler/src/dotty/tools/dotc/core/SymDenotations.scala2
-rw-r--r--compiler/src/dotty/tools/dotc/core/TypeComparer.scala4
-rw-r--r--compiler/src/dotty/tools/dotc/core/Types.scala2
-rw-r--r--compiler/src/dotty/tools/dotc/reporting/diagnostic/MessageContainer.scala2
-rw-r--r--compiler/src/dotty/tools/dotc/transform/Erasure.scala4
-rw-r--r--compiler/src/dotty/tools/dotc/transform/TreeChecker.scala2
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Applications.scala2
-rw-r--r--compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala8
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Inliner.scala2
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Namer.scala13
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Typer.scala2
14 files changed, 33 insertions, 22 deletions
diff --git a/compiler/src/dotty/tools/backend/jvm/scalaPrimitives.scala b/compiler/src/dotty/tools/backend/jvm/scalaPrimitives.scala
index 0027defa7..eb4da5400 100644
--- a/compiler/src/dotty/tools/backend/jvm/scalaPrimitives.scala
+++ b/compiler/src/dotty/tools/backend/jvm/scalaPrimitives.scala
@@ -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]()
diff --git a/compiler/src/dotty/tools/dotc/ast/Trees.scala b/compiler/src/dotty/tools/dotc/ast/Trees.scala
index c4b2b2122..20273eb85 100644
--- a/compiler/src/dotty/tools/dotc/ast/Trees.scala
+++ b/compiler/src/dotty/tools/dotc/ast/Trees.scala
@@ -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)
@@ -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)
diff --git a/compiler/src/dotty/tools/dotc/config/PathResolver.scala b/compiler/src/dotty/tools/dotc/config/PathResolver.scala
index aa4d8aeb0..8df9a8c0e 100644
--- a/compiler/src/dotty/tools/dotc/config/PathResolver.scala
+++ b/compiler/src/dotty/tools/dotc/config/PathResolver.scala
@@ -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
val ArgsSummary(sstate, rest, errors) =
ctx.settings.processArguments(args.toList, true)
errors.foreach(println)
diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala
index 8b7c28e19..e2bb0ac1a 100644
--- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -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)
diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala
index f8c0cdac9..743220f55 100644
--- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala
+++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala
@@ -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
@@ -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 {
diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala
index 7e6620f8e..4dffc4542 100644
--- a/compiler/src/dotty/tools/dotc/core/Types.scala
+++ b/compiler/src/dotty/tools/dotc/core/Types.scala
@@ -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
tp match {
case tp: NamedType =>
if (stopAtStatic && tp.symbol.isStatic) tp
diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/MessageContainer.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/MessageContainer.scala
index 7fd50bfdc..c27644ad9 100644
--- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/MessageContainer.scala
+++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/MessageContainer.scala
@@ -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
diff --git a/compiler/src/dotty/tools/dotc/transform/Erasure.scala b/compiler/src/dotty/tools/dotc/transform/Erasure.scala
index 5c880c7bd..7595e5f2e 100644
--- a/compiler/src/dotty/tools/dotc/transform/Erasure.scala
+++ b/compiler/src/dotty/tools/dotc/transform/Erasure.scala
@@ -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(_, _)))
@@ -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 {
diff --git a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala
index 328c8204d..eee429a87 100644
--- a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala
+++ b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala
@@ -129,7 +129,7 @@ class TreeChecker extends Phase with SymTransformer {
try checker.typedExpr(ctx.compilationUnit.tpdTree)(checkingCtx)
catch {
case NonFatal(ex) => //TODO CHECK. Check that we are bootstrapped
- implicit val ctx: Context = checkingCtx
+ implicit val ctx = checkingCtx
println(i"*** error while checking ${ctx.compilationUnit} after phase ${checkingCtx.phase.prev} ***")
throw ex
}
diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala
index 11121e1f3..a3b4cb311 100644
--- a/compiler/src/dotty/tools/dotc/typer/Applications.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala
@@ -992,7 +992,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
val nestedCtx = ctx.fresh.setExploreTyperState
{
- implicit val ctx: Context = nestedCtx
+ implicit val ctx = nestedCtx
isAsSpecificValueType(tp1, constrained(tp2).resultType)
}
case _ => // (3b)
diff --git a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala
index a18c83ff8..a066fc04a 100644
--- a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala
+++ b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala
@@ -46,7 +46,13 @@ object ErrorReporting {
errorMsg(msg, cx.outer)
}
} else msg
- errorMsg(ex.show, ctx)
+
+ if (cycleSym.is(Implicit, butNot = Method) && cycleSym.owner.isTerm)
+ em"""cyclic reference involving implicit $cycleSym
+ |This happens when the right hand-side of $cycleSym's definition involves an implicit search.
+ |To avoid the error, give $cycleSym an explicit type."""
+ else
+ errorMsg(ex.show, ctx)
}
def wrongNumberOfArgs(fntpe: Type, kind: String, expectedArgs: List[TypeParamInfo], actual: List[untpd.Tree], pos: Position)(implicit ctx: Context) =
diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala
index 3931fcaf4..09487570d 100644
--- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala
@@ -189,7 +189,7 @@ object Inliner {
if (!ctx.isAfterTyper) {
val inlineCtx = ctx
sym.updateAnnotation(LazyBodyAnnotation { _ =>
- implicit val ctx: Context = inlineCtx
+ implicit val ctx = inlineCtx
ctx.withNoError(treeExpr(ctx))(makeInlineable)
})
}
diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala
index b8fe46745..4bcdd5071 100644
--- a/compiler/src/dotty/tools/dotc/typer/Namer.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala
@@ -683,7 +683,7 @@ class Namer { typer: Typer =>
//println(i"completing type params of $sym in ${sym.owner}")
nestedCtx = localContext(sym).setNewScope
myTypeParams = {
- implicit val ctx: Context = nestedCtx
+ implicit val ctx = nestedCtx
val tparams = original.rhs match {
case PolyTypeTree(tparams, _) => tparams
case _ => Nil
@@ -998,11 +998,16 @@ class Namer { typer: Typer =>
lhsType // keep constant types that fill in for a non-constant (to be revised when inline has landed).
else inherited
else {
- if (sym is Implicit) {
- val resStr = if (mdef.isInstanceOf[DefDef]) "result " else ""
- ctx.error(s"${resStr}type of implicit definition needs to be given explicitly", mdef.pos)
+ def missingType(modifier: String) = {
+ ctx.error(s"${modifier}type of implicit definition needs to be given explicitly", mdef.pos)
sym.resetFlag(Implicit)
}
+ if (sym is Implicit)
+ mdef match {
+ case _: DefDef => missingType("result")
+ case _: ValDef if sym.owner.isType => missingType("")
+ case _ =>
+ }
lhsType orElse WildcardType
}
}
diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala
index 78c479433..eec3859f9 100644
--- a/compiler/src/dotty/tools/dotc/typer/Typer.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala
@@ -1642,7 +1642,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
tryInsertImplicitOnQualifier(tree, pt).getOrElse(fallBack)
if (isApplyProto(pt)) tryImplicit
- else tryEither(tryApply(_))((_, _) => tryImplicit)
+ else tryEither(tryApply(_))((_, _) => tryImplicit)
}
/** If this tree is a select node `qual.name`, try to insert an implicit conversion