Skip to content

restore the specialized error path for record patterns#1872

Merged
gasche merged 1 commit intoocaml:trunkfrom
Octachron:restore_mixed_record_labels_pattern_error
Jul 1, 2018
Merged

restore the specialized error path for record patterns#1872
gasche merged 1 commit intoocaml:trunkfrom
Octachron:restore_mixed_record_labels_pattern_error

Conversation

@Octachron
Copy link
Copy Markdown
Member

This PR restores a specialized error path for mixed record labels in record patterns:
on the expression side, mixing record labels (from different record types) inside a record expression

type t = {x:unit}
type s = {y:unit}
let r = {x=();y=()};;

yields a specialized error message:

Error: The record field y belongs to the type s
but is mixed here with fields of type t

Contrarily, the error message for erroneous record patterns

let f = function {x;y} -> x

is the generic one

Error: This pattern matches values of type s
but a pattern was expected which matches values of type t

This difference is due to a small exception imbroglio: the label typing code was expecting an Unify exception after a call to unify_pat_types but unify_pat_types catches Unify exception by itself and transform them into Pattern_type_clash errors.

Copy link
Copy Markdown
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat, thanks!

@gasche gasche merged commit 159bc75 into ocaml:trunk Jul 1, 2018
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants