Skip to content

Commit 4699140

Browse files
committed
Do not assume the superType of a match type gives us a sound mirror
1 parent 5d0c47a commit 4699140

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,9 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
379379
// avoid type aliases for tuples
380380
Right(MirrorSource.GenericTuple(types))
381381
case _ => reduce(tp.underlying)
382-
case tp: MatchType => reduce(tp.tryNormalize.orElse(tp.superType))
382+
case tp: MatchType =>
383+
val n = tp.tryNormalize
384+
if n.exists then reduce(n) else Left(i"its subpart `$tp` is an unreducible match type.")
383385
case _ => reduce(tp.superType)
384386
case tp @ AndType(l, r) =>
385387
for

tests/neg/i19198.scala

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import compiletime.summonInline
44
type DoesNotReduce[T] = T match
55
case String => Any
66

7+
type DoesNotReduce2[T] <: T = T match
8+
case String => T
9+
710
class Foo
811
@main def Test: Unit =
912
summonInline[Mirror.Of[DoesNotReduce[Option[Int]]]] // error
13+
summonInline[Mirror.Of[DoesNotReduce2[Option[Int]]]] // error

0 commit comments

Comments
 (0)