Skip to content

Commit 26b2745

Browse files
committed
Derived members succeed other givens in cycle test
In avoiding cycles in givens, assume quasi-synthetic derived members come after other sibling givens (which are eligible). This preserves the position of the derived symbol (which is not synthetic); the corresponding tree is appended to the body of the enclosing template. The "derived" name prefix is conventional.
1 parent c4c48e3 commit 26b2745

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1706,7 +1706,9 @@ trait Implicits:
17061706
def candSucceedsGiven(sym: Symbol): Boolean =
17071707
val owner = sym.owner
17081708
if owner == candSym.owner then
1709-
sym.is(GivenVal) && sym.span.exists && sym.span.start <= candSym.span.start
1709+
sym.is(GivenVal)
1710+
&& !sym.name.startsWith("derived$") // logically a synthetic injected at the end of the body
1711+
&& sym.span.exists && sym.span.start <= candSym.span.start
17101712
else if owner.isClass then false
17111713
else candSucceedsGiven(owner)
17121714

tests/pos/i23897.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
import scala.deriving.Mirror
3+
4+
class Test[A]
5+
object Test:
6+
def derived[A](using m: Mirror.Of[A], t: Test[Int]): Test[A] = new Test[A]
7+
8+
case class Foo(i: Int) derives Test
9+
object Foo:
10+
//given i: Test[Int] = new Test[Int]
11+
given Test[Int]()

0 commit comments

Comments
 (0)