Skip to content

Conversation

ksss
Copy link
Collaborator

@ksss ksss commented Jun 25, 2024

Currently sleep(2 ** 2) results in a type error since 2 ** 2 returns Numeric type.
Because of these problems, it does not seem very convenient to set the return value to Numeric in numerical operations.

In this PR, I have made similar fixes to #** as those in Integer#pow.

It has been exhaustively tested in raap because the combination is complicated.

@ParadoxV5
Copy link
Contributor

+1 for the good intention, but we should keep the (Numeric) -> branch as math operators accept any Numeric that coerce appropriately.

For the intention, we should go through all files and check for Numeric usages and specify known cases as appropriate.
Summon: @sampersand: you had PRs on numerics and they include making the sigs more pedantic exact.

@ksss
Copy link
Collaborator Author

ksss commented Jun 25, 2024

@ParadoxV5
Thanks for the review. Indeed, with this change 1 ** BigDecimal(1) would result in a type error.
What about the idea of extending Integer#** from BigDecimal? Like + or -.

# bigdecimal.rbs
class Integer
  def **: (BigDecimal) -> BigDecimal
        | ...
end

@sampersand
Copy link
Contributor

+1 for the good intention, but we should keep the (Numeric) -> branch as math operators accept any Numeric that coerce appropriately.

For the intention, we should go through all files and check for Numeric usages and specify known cases as appropriate. Summon: @sampersand: you had PRs on numerics and they include making the sigs more pedantic exact.

I hadn't gotten to around to doing integer.rbs, but maybe i should!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants