Skip to content

Reset typer state on issueErrors #23556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4406,6 +4406,12 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
/** Reports errors for arguments of `appTree` that have a `SearchFailureType`.
*/
def issueErrors(fun: Tree, args: List[Tree], failureType: Type): Tree =
// If there are several arguments, some arguments might already
// have influenced the context, binding variables, but later ones
// might fail. In that case the constraint and instantiated variables
// need to be reset.
ctx.typerState.resetTo(saved)

val errorType = failureType match
case ai: AmbiguousImplicits => ai.asNested
case tp => tp
Expand All @@ -4426,12 +4432,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
val args = implicitArgs(wtp.paramInfos, 0, pt)
val failureType = propagatedFailure(args)
if failureType.exists then
// If there are several arguments, some arguments might already
// have influenced the context, binding variables, but later ones
// might fail. In that case the constraint and instantiated variables
// need to be reset.
ctx.typerState.resetTo(saved)

// If method has default params, fall back to regular application
// where all inferred implicits are passed as named args.
if hasDefaultParams && !failureType.isInstanceOf[AmbiguousImplicits] then
Expand Down
19 changes: 19 additions & 0 deletions tests/pos/i23555.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
trait Behavior[A]

object Behavior:
//implicit def mapBehavior[A: Behavior]: Behavior[List[A]] = new Behavior[List[A]] {}
given [A: Behavior] => Behavior[List[A]]

object Model:
case class Foo(i: Int)
object Foo:
given Behavior[Foo] = new Behavior[Foo] {}
//implicit def dummy[A: Behavior](using s: String = "hello"): Option[A] = None
//implicit def dummy[A: Behavior](using s: String = "hello")(using DummyImplicit): Option[A] = None
given [A: Behavior] => (s: String = "hello") => Option[A] = None

@main def Test =
import Model.Foo
//implicitly[Option[List[Foo]]]
//Foo.dummy[List[Foo]](using s = "bye")
summon[Option[List[Foo]]]
Loading