Skip to content

Commit fcfa406

Browse files
committed
Also checkRefinement for Singleton mirror
Also improves the refinement check to also handle bounds properly.
1 parent dc33947 commit fcfa406

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
315315
loop(formal)
316316

317317
private def checkRefinement(formal: Type, name: TypeName, expected: Type, span: Span)(using Context): Unit =
318-
val actual = formal.lookupRefined(name)
319-
if actual.exists && !(expected =:= actual)
318+
val actual = formal.findMember(name, NoPrefix).info
319+
if actual.exists && !(actual.bounds.contains(expected))
320320
then report.error(
321321
em"$name mismatch, expected: $expected, found: $actual.", ctx.source.atSpan(span))
322322

@@ -504,6 +504,8 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
504504
case MirrorSource.Singleton(_, tref) =>
505505
val singleton = tref.termSymbol // prefer alias name over the original name
506506
val singletonPath = tpd.singleton(tref).withSpan(span)
507+
checkRefinement(formal, tpnme.MirroredElemTypes, defn.EmptyTupleModule.termRef, span)
508+
checkRefinement(formal, tpnme.MirroredElemLabels, defn.EmptyTupleModule.termRef, span)
507509
if tref.classSymbol.is(Scala2x) then // could be Scala 3 alias of Scala 2 case object.
508510
val mirrorType = formal.constrained_& {
509511
mirrorCore(defn.Mirror_SingletonProxyClass, mirroredType, mirroredType, singleton.name)

tests/neg/i22851.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
object Test {
2+
def first[T <: Product](t: T)(using
3+
m: scala.deriving.Mirror.ProductOf[T] {
4+
type MirroredElemTypes <: NonEmptyTuple
5+
}
6+
): Tuple.Head[m.MirroredElemTypes] = ???
7+
8+
first(EmptyTuple) // error
9+
// MirroredElemTypes missmatch, expected: EmptyString, found: <: NonEmptyTuple.
10+
}

0 commit comments

Comments
 (0)