-
Notifications
You must be signed in to change notification settings - Fork 471
Make inline record fields that overlap with a variant's tag a compile error #7875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make inline record fields that overlap with a variant's tag a compile error #7875
Conversation
…flict with the variant tag
compiler/ml/ast_untagged_variants.ml
Outdated
| _ -> ()); | ||
!st | ||
|
||
let process_as_name (attrs : Parsetree.attributes) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is based on process_tag_name
, located above:
rescript/compiler/ml/ast_untagged_variants.ml
Lines 312 to 324 in c293649
let process_tag_name (attrs : Parsetree.attributes) = | |
let st = ref None in | |
Ext_list.iter attrs (fun ({txt; loc}, payload) -> | |
match txt with | |
| "tag" -> | |
if !st = None then ( | |
(match Ast_payload.is_single_string payload with | |
| None -> () | |
| Some (s, _dec) -> st := Some s); | |
if !st = None then raise (Error (loc, InvalidVariantTagAnnotation))) | |
else raise (Error (loc, Duplicated_bs_as)) | |
| _ -> ()); | |
!st |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Looks good to me. But good if @cristianoc takes a look as well.
rescript
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice improvement! Thanks @mediremi!
@cristianoc would you be able to have a quick check of this PR when you have time please? Just in case I've broken something without realising |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Left a comment on reuse.
@zth any suggestions for the phrasing of the error to make it super clear?
In terms of the message, the only thing I don't think is clear now and that could perhaps be tweaked is that the |
…nstead of only showing runtime name
00076d7
to
40d5e14
Compare
Currently, the following:
compiles to:
Since we don't treat the overlap in tag name and inline record field as a compiler error, this can lead to issues at runtime:
In this PR, I've fixed this issue by making inline record fields that overlap with a variant's tag a compile error.
I've also added checks for duplicate
@as
tags on inline record fields.