diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 095ccd29bdfe..5757facc0029 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -2224,9 +2224,11 @@ 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)) - inferView(tree, pt) match { + if (ctx.mode.is(Mode.ImplicitsEnabled)) { + val nestedCtx = ctx.fresh.setNewTyperState() + inferView(tree, pt)(nestedCtx) match { case SearchSuccess(inferred, _, _, _) => + nestedCtx.typerState.commit() adapt(inferred, pt)(ctx.retractMode(Mode.ImplicitsEnabled)) case failure: SearchFailure => if (pt.isInstanceOf[ProtoType] && !failure.isInstanceOf[AmbiguousImplicits]) @@ -2236,6 +2238,7 @@ 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 new file mode 100644 index 000000000000..d5a9c0566938 --- /dev/null +++ b/tests/neg/i3348.scala @@ -0,0 +1,10 @@ +class Test { + import Test.test + "Hello".toto // error +} + +object Test { + def test = { + implicitly[collection.generic.CanBuildFrom[List[Int], Int, List[Int]]] + } +}