Skip to content

Commit d052437

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

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,8 @@ object Types extends TypeUtils {
17531753
if (pre.refinedName ne name) loop(pre.parent) else tp.alias
17541754
case tp: SingletonType =>
17551755
if pre.refinedName ne name then loop(pre.parent) else tp
1756+
case tp: RealTypeBounds =>
1757+
if pre.refinedName ne name then loop(pre.parent) else tp
17561758
case _ =>
17571759
loop(pre.parent)
17581760
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
316316

317317
private def checkRefinement(formal: Type, name: TypeName, expected: Type, span: Span)(using Context): Unit =
318318
val actual = formal.lookupRefined(name)
319-
if actual.exists && !(expected =:= actual)
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)