From 5225f00ab3300bac62a467ecc532c275e02e7f43 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Thu, 3 Mar 2016 23:38:43 +0100 Subject: [PATCH 1/2] Do the implicit search shadowing check in the correct context This commit fixes a very sneaky bug, the following code: ``` lazy val shadowing = typed(untpd.Ident(ref.name) withPos pos.toSynthetic, funProto) (nestedContext.addMode(Mode.ImplicitShadowing).setExploreTyperState) ``` is parsed by scalac as: ``` lazy val shadowing = typed(untpd.Ident(ref.name) withPos pos.toSynthetic, funProto); (nestedContext.addMode(Mode.ImplicitShadowing).setExploreTyperState); ``` So we don't actually use the nested context in `typed`, instead we end up implicitly using `ctx`! --- src/dotty/tools/dotc/typer/Implicits.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala index e3dd113c2cf5..5b336c2e984f 100644 --- a/src/dotty/tools/dotc/typer/Implicits.scala +++ b/src/dotty/tools/dotc/typer/Implicits.scala @@ -491,8 +491,8 @@ trait Implicits { self: Typer => pt) val generated1 = adapt(generated, pt) lazy val shadowing = - typed(untpd.Ident(ref.name) withPos pos.toSynthetic, funProto) - (nestedContext.addMode(Mode.ImplicitShadowing).setExploreTyperState) + typed(untpd.Ident(ref.name) withPos pos.toSynthetic, funProto)( + nestedContext.addMode(Mode.ImplicitShadowing).setExploreTyperState) def refMatches(shadowing: Tree): Boolean = ref.symbol == closureBody(shadowing).symbol || { shadowing match { From 42f87c2cd4f704fcb5ea769a4dbc85c2d183ac12 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Fri, 4 Mar 2016 20:30:20 +0100 Subject: [PATCH 2/2] Allow adding typevars to an uncommitable constraint set We triggered this assert after the fix in the previous commit. --- src/dotty/tools/dotc/typer/ProtoTypes.scala | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/dotty/tools/dotc/typer/ProtoTypes.scala b/src/dotty/tools/dotc/typer/ProtoTypes.scala index 7997d1cf4fba..97b47b2bd114 100644 --- a/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -320,10 +320,8 @@ object ProtoTypes { */ def constrained(pt: PolyType, owningTree: untpd.Tree)(implicit ctx: Context): (PolyType, List[TypeVar]) = { val state = ctx.typerState - def howmany = if (owningTree.isEmpty) "no" else "some" - def committable = if (ctx.typerState.isCommittable) "committable" else "uncommittable" - assert(owningTree.isEmpty != ctx.typerState.isCommittable, - s"inconsistent: $howmany typevars were added to $committable constraint ${state.constraint}") + assert(!(ctx.typerState.isCommittable && owningTree.isEmpty), + s"inconsistent: no typevars were added to committable constraint ${state.constraint}") def newTypeVars(pt: PolyType): List[TypeVar] = for (n <- (0 until pt.paramNames.length).toList)