Skip to content

Commit 4daf050

Browse files
authored
Fix infinite loop in Mirror synthesis of unreducible match type (#20133)
This regressed in f7e2e7c (present in 3.4.0). The second commit fixes a soundness bug.
2 parents 133e709 + 4699140 commit 4daf050

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
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.normalized)
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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import deriving.Mirror
2+
import compiletime.summonInline
3+
4+
type DoesNotReduce[T] = T match
5+
case String => Any
6+
7+
type DoesNotReduce2[T] <: T = T match
8+
case String => T
9+
10+
class Foo
11+
@main def Test: Unit =
12+
summonInline[Mirror.Of[DoesNotReduce[Option[Int]]]] // error
13+
summonInline[Mirror.Of[DoesNotReduce2[Option[Int]]]] // error

0 commit comments

Comments
 (0)