From 5c36cb810967bf20f1a75d91d4505b660365cd8b Mon Sep 17 00:00:00 2001 From: Fengyun Liu Date: Mon, 23 Oct 2017 17:24:33 +0200 Subject: [PATCH 1/2] Revert "Fix #3348: use a new typeState in inferView" --- compiler/src/dotty/tools/dotc/typer/Typer.scala | 7 ++----- tests/neg/i3348.scala | 10 ---------- 2 files changed, 2 insertions(+), 15 deletions(-) delete mode 100644 tests/neg/i3348.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 5757facc0029..095ccd29bdfe 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -2224,11 +2224,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit if (isFullyDefined(wtp, force = ForceDegree.all) && ctx.typerState.constraint.ne(prevConstraint)) adapt(tree, pt) else err.typeMismatch(tree, pt, failure) - if (ctx.mode.is(Mode.ImplicitsEnabled)) { - val nestedCtx = ctx.fresh.setNewTyperState() - inferView(tree, pt)(nestedCtx) match { + if (ctx.mode.is(Mode.ImplicitsEnabled)) + inferView(tree, pt) match { case SearchSuccess(inferred, _, _, _) => - nestedCtx.typerState.commit() adapt(inferred, pt)(ctx.retractMode(Mode.ImplicitsEnabled)) case failure: SearchFailure => if (pt.isInstanceOf[ProtoType] && !failure.isInstanceOf[AmbiguousImplicits]) @@ -2238,7 +2236,6 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit tree else recover(failure) } - } else recover(NoImplicitMatches) } diff --git a/tests/neg/i3348.scala b/tests/neg/i3348.scala deleted file mode 100644 index d5a9c0566938..000000000000 --- a/tests/neg/i3348.scala +++ /dev/null @@ -1,10 +0,0 @@ -class Test { - import Test.test - "Hello".toto // error -} - -object Test { - def test = { - implicitly[collection.generic.CanBuildFrom[List[Int], Int, List[Int]]] - } -} From 97ea776dcf4688b48f387f1a8839a25c2768fc8b Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Tue, 24 Oct 2017 11:18:02 +0200 Subject: [PATCH 2/2] Fix #3348: remove assertion as completion can happen in inferImplicit --- compiler/src/dotty/tools/dotc/typer/Implicits.scala | 2 -- tests/neg/i3348.scala | 10 ++++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 tests/neg/i3348.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index 14da2a95a23a..657f10564787 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -708,7 +708,6 @@ trait Implicits { self: Typer => assert(!ctx.isAfterTyper, if (argument.isEmpty) i"missing implicit parameter of type $pt after typer" else i"type error: ${argument.tpe} does not conform to $pt${err.whyNoMatchStr(argument.tpe, pt)}") - val prevConstr = ctx.typerState.constraint trace(s"search implicit ${pt.show}, arg = ${argument.show}: ${argument.tpe.show}", implicits, show = true) { assert(!pt.isInstanceOf[ExprType]) val isearch = @@ -737,7 +736,6 @@ trait Implicits { self: Typer => } else result case _ => - assert(prevConstr eq ctx.typerState.constraint) result } } diff --git a/tests/neg/i3348.scala b/tests/neg/i3348.scala new file mode 100644 index 000000000000..34ae282074f6 --- /dev/null +++ b/tests/neg/i3348.scala @@ -0,0 +1,10 @@ +class Test { + import Test.test + "Hello".toto +} + +object Test { + def test = { + implicitly[collection.generic.CanBuildFrom[List[Int], Int, List[Int]]] + } +}