From 9b060ec20aabe0f74934050a2be5a91799a1ce20 Mon Sep 17 00:00:00 2001 From: Dolphin von Chips Date: Wed, 7 May 2025 09:11:45 +0300 Subject: [PATCH] Handle comparing with TypeVar in mergeRefinedOrApplied Closes #23032 --- compiler/src/dotty/tools/dotc/core/TypeOps.scala | 10 +++++++++- tests/pos/i23032.scala | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i23032.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index a1e26c20fdbb..efd4c6e83cd2 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -278,7 +278,15 @@ object TypeOps: } case AndType(tp11, tp12) => mergeRefinedOrApplied(tp11, tp2) & mergeRefinedOrApplied(tp12, tp2) - case tp1: TypeParamRef if tp1 == tp2 => tp1 + case tp1: TypeParamRef => + tp2.stripTypeVar match + case tp2: TypeParamRef if tp1 == tp2 => tp1 + case _ => fail + case tp1: TypeVar => + tp2 match + case tp2: TypeVar if tp1 == tp2 => tp1 + case tp2: TypeParamRef if tp1.stripTypeVar == tp2 => tp2 + case _ => fail case _ => fail } } diff --git a/tests/pos/i23032.scala b/tests/pos/i23032.scala new file mode 100644 index 000000000000..7e56d0f8b153 --- /dev/null +++ b/tests/pos/i23032.scala @@ -0,0 +1,2 @@ +def f[F[_], T, U]: F[T] | F[U] = ??? +def x = f.toString