Skip to content

Improve error message for pattern matching in function definitions#6217

Open
tfausak wants to merge 6 commits intounisonweb:trunkfrom
tfausak:gh-793-pattern-matching
Open

Improve error message for pattern matching in function definitions#6217
tfausak wants to merge 6 commits intounisonweb:trunkfrom
tfausak:gh-793-pattern-matching

Conversation

@tfausak
Copy link
Copy Markdown
Contributor

@tfausak tfausak commented Apr 3, 2026

Fixes #793.

tfausak and others added 6 commits April 3, 2026 15:09
…nisonweb#793)

When users attempt Haskell-style pattern matching in function heads
(e.g. `isEmpty [] = true`), Unison now reports a clear error explaining
that this syntax is not supported and suggests using `case` instead.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Adds `(` to the set of pattern-like tokens, so constructor patterns
like `f (Some x) = ...` and tuple patterns like `f (a, b) = ...` are
detected inside blocks. The balanced-bracket scanner already handles
these correctly.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
The error message now shows a contextual example using the function name
the user wrote (e.g. "factorial arg = case arg of") instead of a generic
hardcoded example. Also simplifies the suggestion to a single branch.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
@tfausak tfausak marked this pull request as ready for review April 3, 2026 18:03
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.

Confusing error message when using Haskell-style pattern matching

1 participant