From ad29ce89624470de6204b242f0c3ee75fde727a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Fri, 11 Aug 2023 15:57:51 +0200 Subject: [PATCH] Fix #17115: Try to normalize while computing `typeSize`. --- compiler/src/dotty/tools/dotc/core/Types.scala | 4 +++- tests/pos/i17115.scala | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i17115.scala diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 576f9a6c64f6..c5f65c73f57c 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -6459,7 +6459,9 @@ object Types { seen += tp tp match { case tp: AppliedType => - foldOver(n + 1, tp) + val tpNorm = tp.tryNormalize + if tpNorm.exists then apply(n, tpNorm) + else foldOver(n + 1, tp) case tp: RefinedType => foldOver(n + 1, tp) case tp: TypeRef if tp.info.isTypeAlias => diff --git a/tests/pos/i17115.scala b/tests/pos/i17115.scala new file mode 100644 index 000000000000..5a7cac5d0dc1 --- /dev/null +++ b/tests/pos/i17115.scala @@ -0,0 +1,9 @@ +trait A[T <: Tuple] { val x: Int } +given empty: A[EmptyTuple] with { val x = 1 } +given inductive[Tup <: NonEmptyTuple](using A[Tuple.Tail[Tup]]): A[Tup] with { val x = summon[A[Tuple.Tail[Tup]]].x + 1 } + +object Test: + def main(args: Array[String]): Unit = + println(summon[A[(String, String, String)]].x) //this line is fine + println(summon[A[(String, String, String, String)]].x) //this line gives error +end Test