-
Notifications
You must be signed in to change notification settings - Fork 219
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
rbs prototype rb
guess return value type even if "def" has multiple statements
#303
Conversation
@@ -408,9 +420,11 @@ def literal_to_type(node) | |||
|
|||
def types_to_union_type(types) | |||
return untyped if types.empty? | |||
return untyped if types.include?(untyped) |
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.
Previously Something | untyped
is squashed to untyped
. But I think Something | untyped
is useful for humans when reviewing the generated types. (The original idea is the type profiler.)
So it will not be squashed by this pull request.
@@ -393,7 +405,7 @@ def literal_to_type(node) | |||
value_types << literal_to_type(v) | |||
end | |||
|
|||
if key_types.all? { |t| t.is_a?(Types::Literal) } | |||
if !key_types.empty? && key_types.all? { |t| t.is_a?(Types::Literal) } |
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.
An empty record is syntax error, so it should be Hash[untyped, untyped]
instead.
@@ -128,6 +128,9 @@ def assert_write(decls, string) | |||
writer.write(decls) | |||
|
|||
assert_equal string, writer.out.string | |||
|
|||
# Check syntax error | |||
RBS::Parser.parse_signature(writer.out.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.
👍
Background
Since #209,
rbs prototype rb
has been aware of returned type. But it only can be aware of the method body has only one statement and it is literal.For example:
What is this pull request
This pull request solves the
bad: () -> untyped
. It will bebad: () -> "foo"
.Previously
rbs prototype rb
only guessed returned types for methods that contain only one literal.But it will guess types for
return
statements and the last statement of the method.