-
Notifications
You must be signed in to change notification settings - Fork 463
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
Support bool untagged variants #6368
Support bool untagged variants #6368
Conversation
@zth can't remember what was the result of the last discussion on this? For the implementation, in case the consensus is to go ahead: Also, gentype needs to be also adapted so it generates the expected type. |
Here's an old closed PR doing the same thing: #6231 My opinion is the same as before - I'm for adding this if there's consensus. Not having it makes working with booleans in untagged variants less ergonomic than it can be. Maybe asking on the forum would be a good next step, to find consensus? |
I think we can just go ahead. |
Do it! |
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.
Other than checking for overlap, some small change is required in the gentype code too so Bool
emits type bool
.
jscomp/test/UntaggedVariants.js
Outdated
} else { | ||
return "true"; | ||
} | ||
} else { |
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.
See comment in the thread that this type declaration should give an error (of overlap between bool and one bool constant) to avoid surprises like this one where the final else
branch is dead code.
From @zth initial PR:
I actually had the feeling you mentioned. This is why I've decided to create the PR. |
@cristianoc I'm going to have little time this week. So I'll fix it the next one |
No rush whatsoever. |
This would be nice to get into v11. @DZakh any chance you'll be able to finish this up soonish? |
fc2cf04
to
9fd7821
Compare
jscomp/test/variantsMatching.res
Outdated
|
||
module UntaggedWithBool = { | ||
@unboxed @genType | ||
type t<'a> = String(string) | Float(float) | Bool(bool) | Object({name: string}) |
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.
Redundant 'a
..?
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.
Yep, thanks
@DZakh is this ready to go? |
Besides the comment it is. #6368 (comment) I'm on vacation trip right now and I don't have much free time. |
d320bb0
to
2fb0cf7
Compare
@zth done |
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 looks good to me! @cristianoc what do you think?
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 comments about an unrelated issue.
@@ -19,3 +19,6 @@ export type MyNullable_t<a> = null | undefined | a; | |||
|
|||
// tslint:disable-next-line:interface-over-type-literal | |||
export type MyNullableExtended_t<a> = null | undefined | "WhyNotAnotherOne" | a; | |||
|
|||
// tslint:disable-next-line:interface-over-type-literal | |||
export type UntaggedWithBool_t = string | number | boolean | string; |
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.
Unrelated: this does not look right.
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.
Is this unrelated to this specific PR?
|
||
module UntaggedWithBool = { | ||
@unboxed @genType | ||
type t = String(string) | Float(float) | Bool(bool) | Object({name: string}) |
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.
Unrelate: this defines string
twice.
It should be an error.
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.
Where does it define string twice? The object prop name
+ the constructor..?
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.
I guess it doesn't look right with this output.
export type UntaggedWithBool_t = string | number | boolean | string;
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.
Ahh, the two comments are connected! Now I see.
Reminder for us: We should probably update Js.Json.t to use this bool type instead of |
No description provided.