Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite loop in Mirror synthesis of unreducible match type #20133

Merged
merged 2 commits into from
Apr 8, 2024
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
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Synthesizer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,9 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
// avoid type aliases for tuples
Right(MirrorSource.GenericTuple(types))
case _ => reduce(tp.underlying)
case tp: MatchType => reduce(tp.normalized)
case tp: MatchType =>
val n = tp.tryNormalize
if n.exists then reduce(n) else Left(i"its subpart `$tp` is an unreducible match type.")
Copy link
Contributor

@EugeneFlesselle EugeneFlesselle Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should return the unreduced match type instead.
An instance could have been provided manually for it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reduce requires that we return a class symbol it seems. Also the Synthesizer logic should only be used as a fallback if an implicit wasn't found by regular search.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good point, then an error sounds fine to me.

case _ => reduce(tp.superType)
case tp @ AndType(l, r) =>
for
Expand Down
13 changes: 13 additions & 0 deletions tests/neg/i19198.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import deriving.Mirror
import compiletime.summonInline

type DoesNotReduce[T] = T match
case String => Any

type DoesNotReduce2[T] <: T = T match
case String => T

class Foo
@main def Test: Unit =
summonInline[Mirror.Of[DoesNotReduce[Option[Int]]]] // error
summonInline[Mirror.Of[DoesNotReduce2[Option[Int]]]] // error