Skip to content

Conversation

@Lluc24
Copy link

@Lluc24 Lluc24 commented Nov 20, 2025

Closes #24120: Refactor: Move MatchReducer to its own file

  • Decoupled File Structure: MatchReducer has been moved from TypeComparer.scala to a dedicated file: compiler/src/dotty/tools/dotc/core/MatchReducer.scala.
  • Inheritance Rationale: 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.
  • Blame Handling: Added the commit hash to .git-blame-ignore-revs to ensure accurate git blame history tracking of the original authors.
  • Cleanup: Removed the originating TODO comment from TypeComparer.scala.

MatchReducer modifies caseLambda variable of the superclass, and this modification is later needed when invoking methods of TypeComparer:

// compiler/src/dotty/tools/dotc/core/MatchReducer.scala, line 328
def matchLegacyPatMat(spec: MatchTypeCaseSpec.LegacyPatMat): MatchResult =
 val caseLambda = constrained(spec.origMatchCase, ast.tpd.EmptyTree)._1.asInstanceOf[HKTypeLambda]
 this.caseLambda = caseLambda
 ...

Mutable protected state caseLambda:

// compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala, line 44
** Potentially a type lambda that is still instantiatable, even though the constraint
*  is generally frozen.
*/
protected var caseLambda: Type = NoType

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Separate MatchReducer from TypeComparer?

2 participants