-
Notifications
You must be signed in to change notification settings - Fork 226
[Kernel] Tweak signatures for conversion methods, and add unit tests in #2683
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -480,9 +480,12 @@ module Kernel : BasicObject | |
| # | ||
| def self?.Complex: (_ToC complex_like, ?exception: true) -> Complex | ||
| | (_ToC complex_like, exception: bool) -> Complex? | ||
| | (Numeric | String real, ?Numeric | String imag, ?exception: true) -> Complex | ||
| | (Numeric | String real, ?Numeric | String imag, exception: bool) -> Complex? | ||
| | (untyped, ?untyped, ?exception: bool) -> Complex? | ||
| | (Numeric numeric, ?exception: bool) -> Complex | ||
| | (String real_or_both, ?exception: true) -> Complex | ||
| | (untyped real_or_both, exception: bool) -> Complex? | ||
| | (Numeric | String real, Numeric | String imag, ?exception: true) -> Complex | ||
| | (Numeric | String real, Integer | Float | Rational | Complex imag, exception: bool) -> Complex | ||
| | (Numeric | String real, untyped imag, exception: bool) -> Complex? | ||
|
|
||
| # <!-- | ||
| # rdoc-file=kernel.rb | ||
|
|
@@ -502,7 +505,7 @@ module Kernel : BasicObject | |
| # | ||
| def self?.Float: (_ToF float_like, ?exception: true) -> Float | ||
| | (_ToF float_like, exception: bool) -> Float? | ||
| | (untyped, ?exception: bool) -> Float? | ||
| | (untyped, exception: bool) -> Float? | ||
|
|
||
| # <!-- | ||
| # rdoc-file=object.c | ||
|
|
@@ -524,7 +527,7 @@ module Kernel : BasicObject | |
| # Hash(nil) # => {} | ||
| # Hash([]) # => {} | ||
| # | ||
| def self?.Hash: [K, V] (nil | [] _empty) -> Hash[K, V] | ||
| def self?.Hash: [K, V] (nil | []) -> Hash[K, V] | ||
| | [K, V] (hash[K, V] hash_like) -> Hash[K, V] | ||
|
|
||
| # <!-- | ||
|
|
@@ -614,7 +617,7 @@ module Kernel : BasicObject | |
| | (int | _ToI int_like, exception: bool) -> Integer? | ||
| | (string str, int base, ?exception: true) -> Integer | ||
| | (string str, int base, exception: bool) -> Integer? | ||
| | (untyped, ?untyped, ?exception: bool) -> Integer? | ||
| | (untyped, ?int base, exception: bool) -> Integer? | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If provided, the second argument actually has to be an |
||
|
|
||
| # <!-- | ||
| # rdoc-file=rational.c | ||
|
|
@@ -655,14 +658,19 @@ module Kernel : BasicObject | |
| # | ||
| def self?.Rational: (int | _ToR rational_like, ?exception: true) -> Rational | ||
| | (int | _ToR rational_like, exception: bool) -> Rational? | ||
| | (int | _ToR numer, ?int | _ToR denom, ?exception: true) -> Rational | ||
| | (int | _ToR numer, ?int | _ToR denom, exception: bool) -> Rational? | ||
| | [T] (Numeric & _RationalDiv[T] numer, Numeric denom, ?exception: bool) -> T | ||
| | (int | _ToR numer, int | _ToR denom, ?exception: true) -> Rational | ||
| | (int | _ToR numer, int | _ToR denom, exception: bool) -> Rational? | ||
|
Comment on lines
+661
to
+662
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I simplified the signature of this a bit, collapsing the |
||
| | [T < Numeric] (T value, 1, ?exception: bool) -> T | ||
| | (untyped, ?untyped, ?exception: bool) -> Rational? | ||
| | [T] (Numeric & _RationalDiv[T] numer, Numeric denom, ?exception: bool) -> T | ||
| | (untyped, ?untyped, exception: bool) -> Rational? | ||
|
|
||
| # An interface used in `Kernel.Rational` when both arguments are `Numeric`s, | ||
| # but don't define `to_r` or `to_int`. | ||
| # | ||
| # The return type of the division is the return type of `Rational(numer, denom)`. | ||
| interface _RationalDiv[T] | ||
| def /: (Numeric) -> T | ||
| # Divide the numerator by `denom` | ||
| def /: (Numeric denom) -> T | ||
| end | ||
|
|
||
| # <!-- | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -340,7 +340,12 @@ def value(val, type) | |
| when Types::Variable | ||
| true | ||
| when Types::Literal | ||
| type.literal == val | ||
| begin | ||
| type.literal == val | ||
| rescue NoMethodError | ||
| raise if defined?(val.==) | ||
| false | ||
|
Comment on lines
+344
to
+347
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is needed because one of the |
||
| end | ||
| when Types::Union | ||
| type.types.any? {|type| value(val, type) } | ||
| when Types::Intersection | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,11 +180,11 @@ def send_setup(method_type, receiver, method, args, proc) | |
| ) | ||
| errors = typecheck.method_call(method, method_type, trace, errors: []) | ||
|
|
||
| assert_empty errors.map {|x| RBS::Test::Errors.to_string(x) }, "Call trace does not match with given method type: #{trace.inspect}" | ||
| assert_empty errors.map {|x| RBS::Test::Errors.to_string(x) }, proc { "Call trace does not match with given method type: #{trace.inspect}" } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of always creating the string for the |
||
|
|
||
| method_defs = method_defs(method) | ||
| all_errors = method_defs.map {|t| typecheck.method_call(method, t.type, trace, errors: [], annotations: t.each_annotation.to_a) } | ||
| assert all_errors.any? {|es| es.empty? }, "Call trace does not match one of method definitions:\n #{trace.inspect}\n #{method_defs.map(&:type).join(" | ")}" | ||
| assert all_errors.any? {|es| es.empty? }, proc { "Call trace does not match one of method definitions:\n #{trace.inspect}\n #{method_defs.map(&:type).join(" | ")}" } | ||
|
|
||
| raise exception if exception | ||
|
|
||
|
|
||
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 one's been changed because, after looking into it,
Complexis quite messy:Complex(Numeric)can never returnnil, regardless ofexceptionComplex(Numeric | String, denom, exception: false)will actually returnnilwhen the denom is a non-Integer | Float | Complex | RationalNumeric. Wonky, becauseexception: true/omitted doesn't do that, and it's only for the second argument