From 04531c94dedb6156d2b9d64e80cf48917e0818a1 Mon Sep 17 00:00:00 2001 From: Lluc Santamaria Riba Date: Thu, 4 Dec 2025 09:52:44 +0100 Subject: [PATCH 1/2] Delete TODO on MatchReducer The suggested refactoring to composition over inheritance was blocked because MatchReducer requires modifying the mutable protected state (caseLambda) of its superclass, TypeComparer, before invoking dependent inherited methods. --- compiler/src/dotty/tools/dotc/core/TypeComparer.scala | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 0edb5a38e5bb..fe05a1161281 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -3594,10 +3594,7 @@ object MatchReducer: case Stuck => "Stuck" case NoInstance(fails) => "NoInstance(" ~ Text(fails.map(p.toText(_) ~ p.toText(_)), ", ") ~ ")" -/** A type comparer for reducing match types. - * TODO: Not sure this needs to be a type comparer. Can we make it a - * separate class? - */ +/** A type comparer for reducing match types. */ class MatchReducer(initctx: Context) extends TypeComparer(initctx) { import MatchReducer.* From ae1381aa22f0845333fd80489b4d1c53f31f3b44 Mon Sep 17 00:00:00 2001 From: Matt Bovel Date: Thu, 4 Dec 2025 11:40:20 +0100 Subject: [PATCH 2/2] Add reference to #24488 in `MatchReducer`'s documentation --- compiler/src/dotty/tools/dotc/core/TypeComparer.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index fe05a1161281..8a6fbd431ce9 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -3594,7 +3594,11 @@ object MatchReducer: case Stuck => "Stuck" case NoInstance(fails) => "NoInstance(" ~ Text(fails.map(p.toText(_) ~ p.toText(_)), ", ") ~ ")" -/** A type comparer for reducing match types. */ +/** A [[TypeComparer]] for reducing match types. + * + * This needs to be a [[TypeComparer]] because it mutates the `caseLambda` + * field defined in [[ConstraintHandling]]. See #24488 for more details. + */ class MatchReducer(initctx: Context) extends TypeComparer(initctx) { import MatchReducer.*