From d3174a14f5a26670dd1c3afa67082fdfe0d9862c Mon Sep 17 00:00:00 2001 From: Eugene Flesselle Date: Tue, 5 Dec 2023 13:42:31 +0100 Subject: [PATCH 1/2] Normalize mirrorType before reducing to mirrorSource --- .../src/dotty/tools/dotc/typer/Synthesizer.scala | 2 +- tests/pos/i19198.scala | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i19198.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala b/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala index 67853001d8f0..2dcef257a36a 100644 --- a/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala @@ -339,7 +339,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context): * or a TermRef to a singleton value. These are * the base elements required to generate a mirror. */ - def reduce(mirroredType: Type)(using Context): Either[String, MirrorSource] = mirroredType match + def reduce(mirroredType: Type)(using Context): Either[String, MirrorSource] = mirroredType.normalized match case tp: TypeRef => val sym = tp.symbol if sym.isClass then // direct ref to a class, not an alias diff --git a/tests/pos/i19198.scala b/tests/pos/i19198.scala new file mode 100644 index 000000000000..23550aac807f --- /dev/null +++ b/tests/pos/i19198.scala @@ -0,0 +1,13 @@ +import deriving.Mirror +import compiletime.summonInline + +inline def check1[Tps <: NonEmptyTuple]: Unit = + summonInline[Mirror.Of[Tuple.Head[Tps]]] + +inline def check2[Tps <: NonEmptyTuple]: Unit = + type FromType = Tuple.Head[Tps] + summonInline[Mirror.Of[FromType]] + +@main def Test: Unit = + check1[Option[Int] *: EmptyTuple] // Ok + check2[Option[Int] *: EmptyTuple] // Error: FromType is widened to Any in Syntheziser From f7e2e7ce752f9c472c06fe1685464879fa06f6f7 Mon Sep 17 00:00:00 2001 From: Eugene Flesselle Date: Tue, 5 Dec 2023 19:51:27 +0100 Subject: [PATCH 2/2] Normalize only when needed --- compiler/src/dotty/tools/dotc/typer/Synthesizer.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala b/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala index 2dcef257a36a..c94724faf4d4 100644 --- a/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala @@ -339,7 +339,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context): * or a TermRef to a singleton value. These are * the base elements required to generate a mirror. */ - def reduce(mirroredType: Type)(using Context): Either[String, MirrorSource] = mirroredType.normalized match + def reduce(mirroredType: Type)(using Context): Either[String, MirrorSource] = mirroredType match case tp: TypeRef => val sym = tp.symbol if sym.isClass then // direct ref to a class, not an alias @@ -379,6 +379,7 @@ 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 _ => reduce(tp.superType) case tp @ AndType(l, r) => for