From 6fd2734e7fc8f473342c526c8e0616e2418f3935 Mon Sep 17 00:00:00 2001 From: Eugene Flesselle Date: Thu, 11 Apr 2024 23:16:17 +0200 Subject: [PATCH] tryCompiletimeConstantFold in disjointnessBoundary Fixes #20166 --- .../dotty/tools/dotc/core/TypeComparer.scala | 2 ++ tests/pos/i20166.scala | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/pos/i20166.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index cee1ec7fffa8..0890d5889fa7 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -2902,6 +2902,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling tp case tp: ConstantType => tp + case tp: AppliedType if tp.tryCompiletimeConstantFold.exists => + tp.tryCompiletimeConstantFold case tp: HKTypeLambda => tp case tp: ParamRef => diff --git a/tests/pos/i20166.scala b/tests/pos/i20166.scala new file mode 100644 index 000000000000..38b7556a82f4 --- /dev/null +++ b/tests/pos/i20166.scala @@ -0,0 +1,24 @@ +import scala.compiletime.ops.int.* + +// NOTE ops.int.S is documented as equivalent to MyS + +type MyS[X] = X match + case 0 => 1 + case 1 => 2 + case 2 => 3 + +type M[I <: Int] = 4 match + case 1 - 1 => "0" + case MyS[I] => "2" + case S[I] => "2" // Not provablyDisjoint before changes + case 2 + I => "3" + case I + 3 => "4" + +val _: M[1] = "4" + + +type M2[I <: Int, P] = I match + case P => "b" + case _ => "c" + +val _: M2[5, 2 + 3] = "b"