From 7c861cba68274e020cef8e5cf0003ae779a33f6c Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Tue, 20 Jun 2023 12:38:54 +0100 Subject: [PATCH] Teach provablyDisjoint to fold compile-time constants --- compiler/src/dotty/tools/dotc/core/TypeComparer.scala | 4 ++++ tests/pos/i16596.scala | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/pos/i16596.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index a0922c1f0574..9ee6684b74ae 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -2845,6 +2845,10 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling else invariantDisjoint(arg1, arg2, tparam) } + case (tp1: AppliedType, tp2) if tp1.tryCompiletimeConstantFold.exists => + provablyDisjoint(tp1.tryCompiletimeConstantFold, tp2) + case (tp1, tp2: AppliedType) if tp2.tryCompiletimeConstantFold.exists => + provablyDisjoint(tp1, tp2.tryCompiletimeConstantFold) case (tp1: HKLambda, tp2: HKLambda) => provablyDisjoint(tp1.resType, tp2.resType) case (_: HKLambda, _) => diff --git a/tests/pos/i16596.scala b/tests/pos/i16596.scala new file mode 100644 index 000000000000..343dd65110bc --- /dev/null +++ b/tests/pos/i16596.scala @@ -0,0 +1,7 @@ +import scala.compiletime.ops.int, int.- + +type Count[N, T] <: Tuple = (N, T) match + case (0, T) => EmptyTuple + case (N, T) => T *: Count[N - 1, T] + +val a: Count[3, Int] = (1, 2, 3)