diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index 8228bb5252f8..0413c924c4d3 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -1706,7 +1706,9 @@ trait Implicits: def candSucceedsGiven(sym: Symbol): Boolean = val owner = sym.owner if owner == candSym.owner then - sym.is(GivenVal) && sym.span.exists && sym.span.start <= candSym.span.start + sym.is(GivenVal) + && !sym.name.startsWith("derived$") // logically a synthetic injected at the end of the body + && sym.span.exists && sym.span.start <= candSym.span.start else if owner.isClass then false else candSucceedsGiven(owner) diff --git a/tests/pos/i23897.scala b/tests/pos/i23897.scala new file mode 100644 index 000000000000..4913d37d141f --- /dev/null +++ b/tests/pos/i23897.scala @@ -0,0 +1,11 @@ + +import scala.deriving.Mirror + +class Test[A] +object Test: + def derived[A](using m: Mirror.Of[A], t: Test[Int]): Test[A] = new Test[A] + +case class Foo(i: Int) derives Test +object Foo: + //given i: Test[Int] = new Test[Int] + given Test[Int]()