-
Notifications
You must be signed in to change notification settings - Fork 216
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
Add a shorthand for "TrueClass | FalseClass" #133
Comments
Hi, thank you very much for your proposal and sorry for late reply. Your proposal makes sense. It keeps the syntax of RBS, and we know there is some cases we need the So, my intuition is that:
Do these make sense? |
That makes sense to me, though I still think a lot of users are going to want a strict bool type. I'm fine with waiting and seeing if people actually need it before implementing it :) |
For this use-case, plus for regular in ruby, e.g. This has been requested before: This is what Sorbet does: Feels a bit like the Bignum/Fixnum thing that was improved in Ruby 2.4, where they both merged into Integer. |
I managed to convince |
Like we have I note that there are many instances in the current code base of def all?: () -> bool
# ^^^^ no, should be `true | false`
| (_Pattern[Elem] pattern) -> bool
# ^^^^ no, should be `true | false`
| () { (Elem obj) -> bool } -> bool
# ^^^^ correct, block can return anything, we use only truthiness
# ^^^^ no, should be `true | false` @soutaro could you confirm my understanding? I can provide a PR to fix these, but is |
@marcandre I assume returning |
Opened a WIP pull request to add |
The fact that this method returns If
Looks good to me 👍. Is |
PS: In the block form, if there is a statement of |
@marcandre Thanks! I got the point about So, the next problem would be if we should keep the My concern is if using There would be three options:
(2 seems reasonable to me for now because I haven't found a good name for 3...) Typing |
I like the idea of "intention", e.g. I'd love to use For other names for option 3, We could also have My preferences (I think):
|
I created https://bugs.ruby-lang.org/issues/17265 for addition of |
For example, the return value of the block of Enumerable#all? is handled as bool. In this case, it will bring no difference, but I think it is a good habit to use a more explicit name instead of "untyped". Note, if the definition of `bool` is changed according to ruby#133, they should be changed again.
I see in syntax.md there's a
bool
type, but it allows "nil
or any other values", which seems to defeat the purpose a bit.I'd expect passing anything other than
true
orfalse
to warn, because otherwise the type signature doesn't seem to have a point?If changing
bool
isn't going to happen, I'd like a simple shorthand forTrueClass | FalseClass
that would make passingnil
or a string to a method expecting a boolean give a warning. Maybebool!
? I don't think!
has any meaning in the signature syntax right now, but it might not be a good idea to use!
if you plan on using it for something else at some point.Thanks :)
The text was updated successfully, but these errors were encountered: