Skip to content

Commit a035a17

Browse files
committed
Reset typer state on issueErrors
1 parent ce9fdfc commit a035a17

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4406,6 +4406,12 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
44064406
/** Reports errors for arguments of `appTree` that have a `SearchFailureType`.
44074407
*/
44084408
def issueErrors(fun: Tree, args: List[Tree], failureType: Type): Tree =
4409+
// If there are several arguments, some arguments might already
4410+
// have influenced the context, binding variables, but later ones
4411+
// might fail. In that case the constraint and instantiated variables
4412+
// need to be reset.
4413+
ctx.typerState.resetTo(saved)
4414+
44094415
val errorType = failureType match
44104416
case ai: AmbiguousImplicits => ai.asNested
44114417
case tp => tp
@@ -4426,12 +4432,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
44264432
val args = implicitArgs(wtp.paramInfos, 0, pt)
44274433
val failureType = propagatedFailure(args)
44284434
if failureType.exists then
4429-
// If there are several arguments, some arguments might already
4430-
// have influenced the context, binding variables, but later ones
4431-
// might fail. In that case the constraint and instantiated variables
4432-
// need to be reset.
4433-
ctx.typerState.resetTo(saved)
4434-
44354435
// If method has default params, fall back to regular application
44364436
// where all inferred implicits are passed as named args.
44374437
if hasDefaultParams && !failureType.isInstanceOf[AmbiguousImplicits] then

tests/pos/i23555.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
trait Behavior[A]
2+
3+
object Behavior:
4+
//implicit def mapBehavior[A: Behavior]: Behavior[List[A]] = new Behavior[List[A]] {}
5+
given [A: Behavior] => Behavior[List[A]]
6+
7+
object Model:
8+
case class Foo(i: Int)
9+
object Foo:
10+
given Behavior[Foo] = new Behavior[Foo] {}
11+
//implicit def dummy[A: Behavior](using s: String = "hello"): Option[A] = None
12+
//implicit def dummy[A: Behavior](using s: String = "hello")(using DummyImplicit): Option[A] = None
13+
given [A: Behavior] => (s: String = "hello") => Option[A] = None
14+
15+
@main def Test =
16+
import Model.Foo
17+
//implicitly[Option[List[Foo]]]
18+
//Foo.dummy[List[Foo]](using s = "bye")
19+
summon[Option[List[Foo]]]

0 commit comments

Comments
 (0)