Skip to content
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

Fix Integer#pow signature #1706

Merged
merged 1 commit into from Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions core/integer.rbs
Expand Up @@ -1028,9 +1028,10 @@ class Integer < Numeric
# a.pow(b) #=> same as a**b
# a.pow(b, m) #=> same as (a**b) % m, but avoids huge temporary values
#
def pow: (Integer other, ?Integer modulo) -> Integer
| (Float) -> Float
| (Rational) -> Rational
def pow: (Integer other) -> (Integer | Rational)
| (Integer other, Integer modulo) -> Integer
| (Float) -> (Float | Complex)
| (Rational) -> (Float | Rational | Complex)
| (Complex) -> Complex

# <!--
Expand Down
27 changes: 27 additions & 0 deletions test/stdlib/Integer_test.rb
Expand Up @@ -369,3 +369,30 @@ def test_try_convert
)
end
end

class IntegerInstanceTest < Test::Unit::TestCase
include TestHelper

testing "::Integer"

def test_pow
assert_send_type "(Integer) -> Integer",
1, :pow, 2
assert_send_type "(Integer) -> Rational",
-2, :pow, -1
assert_send_type "(Integer, Integer) -> Integer",
1, :pow, 2, 10
assert_send_type "(Float) -> Float",
1, :pow, 1.0
assert_send_type "(Float) -> Complex",
-9, :pow, 0.1
assert_send_type "(Rational) -> Float",
2, :pow, 1/2r
assert_send_type "(Rational) -> Rational",
1, :pow, 1r
assert_send_type "(Rational) -> Complex",
-3, :pow, -4/3r
assert_send_type "(Complex) -> Complex",
1, :pow, 1i
end
end