Repository navigation
Fix misleading error message in pattern constructor type-checking (#6126) - #6265
Open
mmustafasenoglu wants to merge 2 commits into
Open
mmustafasenoglu wants to merge 2 commits into
mmustafasenoglu wants to merge 2 commits into
Conversation
When a pattern constructor receives an argument of the wrong type, the error message previously said "The Nth argument to enclosing-function". It should say "The Nth argument to Constructor" referring to the data constructor being matched. Fixes unisonweb#6126 Changes: - Context.hs: Add InPatternApply ConstructorReference to PathElement and wrap the pattern constructor subtype check with it - Extractor.hs: Add inPatternApply subsequence extractor - TypeError.hs: Add patternCtor field to FunctionApplication and new applyingPatternConstructor extractor - PrintError.hs: Use constructor name when patternCtor is available
mmustafasenoglu
force-pushed
the
fix/pattern-constructor-error-message
branch
from
October 5, 2026 08:11
5d34180 to
e164d29
Compare
Author
|
Rebased onto current trunk and resolved the conflict in Context.hs — the GADT principality rework touched the same code, so the InPatternApply scope now wraps all three subtype calls in the constructor case. CI needs approval to run on this fork PR, appreciate it when someone has a moment. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a pattern constructor receives an argument of the wrong type, the error message previously said "The Nth argument to
f" wherefwas the enclosing function (e.g.,b). It now correctly says "The Nth argument toConstructor" referring to the data constructor being matched.Fixes #6126
Problem
Given:
The error said: "The 1st argument to
bhas typeTuplebut expectedX"But
bis irrelevant — it should say "The 1st argument toYhas typeTuplebut expectedX"Solution
4 files changed:
Context.hs: Added
InPatternApply ConstructorReferenceto thePathElementADT, and wrapped the pattern constructor subtype check (checkPatternforPattern.Constructor) withscope (InPatternApply ref).Extractor.hs: Added
inPatternApplysubsequence extractor to match the new path element.TypeError.hs: Added
patternCtor :: Maybe ConstructorReferencefield toFunctionApplication, and created a newapplyingPatternConstructorextractor that chains through theInPatternApplyelement in the error path.PrintError.hs: Updated the
FunctionApplicationerror rendering to useshowConstructorwhenpatternCtorisJust, displaying the constructor name instead of the enclosing function name.Key insight
The
SubseqExtractormonad requires strict adjacency (startB == endA + 1) between consecutive path elements. AddingInPatternApplybetweenInSubtypeandInCheckbreaks the existingapplyingFunctionextractor chain, so a separate extractor was needed. TheallErrorslist triesapplyingPatternConstructorbeforeapplyingFunction; the former matches whenInPatternApplyis present, the latter matches for regular function application errors.Testing
fix-6126-pattern-constructor-error.md