Skip to content
Merged
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
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,10 @@ 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.span.exists && sym.span.start <= candSym.span.start
&& (sym.span.isSourceDerived || !sym.name.startsWith("derived$", 0))
// logically a synthetic injected at the end of the body
else if owner.isClass then false
else candSucceedsGiven(owner)

Expand Down
14 changes: 14 additions & 0 deletions tests/pos/i23897.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

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]

case class Bar(i: Int) derives Test
object Bar:
given Test[Int]()
31 changes: 31 additions & 0 deletions tests/run/i23897.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

import scala.deriving.Mirror

trait Semigroup[A] {
def combine(x: A, y: A): A
}
object Semigroup {
given semigroupInt: Semigroup[Int] = _ + _

given emptyTuple: Semigroup[EmptyTuple] = (x, _) => x

given tupleN[H, T <: Tuple](using h: Semigroup[H], t: Semigroup[T]): Semigroup[H *: T] =
(x, y) => h.combine(x.head, y.head) *: t.combine(x.tail, y.tail)

def derived[A <: Product](using m: Mirror.ProductOf[A], s: Semigroup[m.MirroredElemTypes]): Semigroup[A] =
(x, y) => m.fromTuple(s.combine(Tuple.fromProductTyped(x), Tuple.fromProductTyped(y)))
}

case class Foo(i: Int) derives Semigroup
object Foo {
given overrideSemigroupInt: Semigroup[Int] = _ * _
}

@main def Test =
assert:
summon[Semigroup[Foo]].combine(Foo(2), Foo(3)) == Foo(6)

// Scala 3.3 and 3.4
//summon[Semigroup[Foo]].combine(Foo(2), Foo(3)) // => Foo(6)
// Scala 3.5+
//summon[Semigroup[Foo]].combine(Foo(2), Foo(3)) // => Foo(5)
Loading