diff options
author | odersky <odersky@gmail.com> | 2016-12-15 17:44:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-15 17:44:06 +0100 |
commit | a5620ab882b95ef60acf42814ac5568d5f93bdd4 (patch) | |
tree | a524a250769cd72ebb316c30b8166c4c45d7fc43 /compiler/src/dotty/tools/dotc/typer | |
parent | 9f2b5ad068c06c62e28a3543218f5c1bc0362f74 (diff) | |
parent | bc869e74cb18ffdb4d42b59ad654f55403b9b6bd (diff) | |
download | dotty-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/dotc/typer')
5 files changed, 19 insertions, 8 deletions
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 |