Skip to content

Commit c714b51

Browse files
authored
Merge pull request #3354 from dotty-staging/fix-3348
Fix #3348: use a new typeState in inferView
2 parents 0438e48 + dfa8593 commit c714b51

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,9 +2224,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
22242224
if (isFullyDefined(wtp, force = ForceDegree.all) &&
22252225
ctx.typerState.constraint.ne(prevConstraint)) adapt(tree, pt)
22262226
else err.typeMismatch(tree, pt, failure)
2227-
if (ctx.mode.is(Mode.ImplicitsEnabled))
2228-
inferView(tree, pt) match {
2227+
if (ctx.mode.is(Mode.ImplicitsEnabled)) {
2228+
val nestedCtx = ctx.fresh.setNewTyperState()
2229+
inferView(tree, pt)(nestedCtx) match {
22292230
case SearchSuccess(inferred, _, _, _) =>
2231+
nestedCtx.typerState.commit()
22302232
adapt(inferred, pt)(ctx.retractMode(Mode.ImplicitsEnabled))
22312233
case failure: SearchFailure =>
22322234
if (pt.isInstanceOf[ProtoType] && !failure.isInstanceOf[AmbiguousImplicits])
@@ -2236,6 +2238,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
22362238
tree
22372239
else recover(failure)
22382240
}
2241+
}
22392242
else recover(NoImplicitMatches)
22402243
}
22412244

tests/neg/i3348.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Test {
2+
import Test.test
3+
"Hello".toto // error
4+
}
5+
6+
object Test {
7+
def test = {
8+
implicitly[collection.generic.CanBuildFrom[List[Int], Int, List[Int]]]
9+
}
10+
}

0 commit comments

Comments
 (0)