ruby / rbs

Type Signature for Ruby
Other
1.94k stars 211 forks source link

Fix double-splat method #1909

Open ksss opened 3 months ago

ksss commented 3 months ago

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 commented 3 months ago

+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 commented 3 months ago

@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 commented 2 months ago

+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!