Skip to content

Commit d7c3666

Browse files
authored
Merge pull request #1868 from ruby/revise-divmod
Revise `#divmod` method so that `sleep` can accept `Float` and `Rational`
2 parents 2a6c00b + 7fd0efc commit d7c3666

File tree

9 files changed

+85
-4
lines changed

9 files changed

+85
-4
lines changed

.github/workflows/ruby.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ jobs:
3232
job: lexer compile confirm_lexer
3333
- ruby: "3.3"
3434
job: rubocop validate test_doc build test_generate_stdlib raap
35+
- ruby: "3.3"
36+
job: typecheck_test
3537
steps:
3638
- uses: actions/checkout@v4
3739
- uses: ruby/setup-ruby@v1
@@ -64,6 +66,10 @@ jobs:
6466
echo "NO_MINITEST=true" >> $GITHUB_ENV
6567
bundle config set --local without 'minitest'
6668
if: ${{ contains(matrix.ruby, 'head') }}
69+
- name: Skip installing type checkers
70+
if: ${{ ! contains(matrix.job, 'typecheck_test') }}
71+
run: |
72+
bundle config set without 'typecheck_test'
6773
- name: bin/setup
6874
run: |
6975
bin/setup

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,7 @@ gem 'csv'
4040
group :minitest do
4141
gem "minitest"
4242
end
43+
44+
group :typecheck_test do
45+
gem "steep", "~> 1.7.0.dev", require: false
46+
end

Gemfile.lock

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,47 @@ GEM
1313
remote: https://rubygems.org/
1414
specs:
1515
abbrev (0.1.2)
16+
activesupport (7.1.3.4)
17+
base64
18+
bigdecimal
19+
concurrent-ruby (~> 1.0, >= 1.0.2)
20+
connection_pool (>= 2.2.5)
21+
drb
22+
i18n (>= 1.6, < 2)
23+
minitest (>= 5.1)
24+
mutex_m
25+
tzinfo (~> 2.0)
1626
addressable (2.8.6)
1727
public_suffix (>= 2.0.2, < 6.0)
1828
ast (2.4.2)
1929
base64 (0.2.0)
2030
benchmark-ips (2.13.0)
2131
bigdecimal (3.1.8)
32+
concurrent-ruby (1.3.1)
33+
connection_pool (2.4.1)
2234
csv (3.3.0)
2335
dbm (1.1.0)
2436
diff-lcs (1.5.1)
2537
digest (3.1.1)
38+
drb (2.2.1)
39+
ffi (1.17.0)
40+
ffi (1.17.0-x86_64-darwin)
2641
fileutils (1.7.2)
2742
goodcheck (3.1.0)
2843
marcel (>= 1.0, < 2.0)
2944
psych (>= 3.1, < 5.0)
3045
rainbow (>= 3.0, < 4.0)
3146
strong_json (>= 1.1, < 2.2)
47+
i18n (1.14.5)
48+
concurrent-ruby (~> 1.0)
3249
json (2.7.2)
3350
json-schema (4.3.0)
3451
addressable (>= 2.8)
3552
language_server-protocol (3.17.0.3)
53+
listen (3.9.0)
54+
rb-fsevent (~> 0.10, >= 0.10.3)
55+
rb-inotify (~> 0.9, >= 0.9.10)
56+
logger (1.6.0)
3657
marcel (1.0.4)
3758
memory_profiler (1.0.1)
3859
minitest (5.23.1)
@@ -58,6 +79,9 @@ GEM
5879
rake (13.2.1)
5980
rake-compiler (1.2.7)
6081
rake
82+
rb-fsevent (0.11.2)
83+
rb-inotify (0.11.1)
84+
ffi (~> 1.0)
6185
rdoc (6.6.3.1)
6286
psych (>= 4.0.0)
6387
regexp_parser (2.9.2)
@@ -92,14 +116,34 @@ GEM
92116
rubocop-rubycw (0.1.6)
93117
rubocop (~> 1.0)
94118
ruby-progressbar (1.13.0)
119+
securerandom (0.3.1)
95120
stackprof (0.2.26)
121+
steep (1.7.0.dev.4)
122+
activesupport (>= 5.1)
123+
concurrent-ruby (>= 1.1.10)
124+
csv (>= 3.0.9)
125+
fileutils (>= 1.1.0)
126+
json (>= 2.1.0)
127+
language_server-protocol (>= 3.15, < 4.0)
128+
listen (~> 3.0)
129+
logger (>= 1.3.0)
130+
parser (>= 3.1)
131+
rainbow (>= 2.2.2, < 4.0)
132+
rbs (>= 3.5.0.pre)
133+
securerandom (>= 0.1)
134+
strscan (>= 1.0.0)
135+
terminal-table (>= 2, < 4)
96136
stringio (3.1.0)
97137
strong_json (2.1.2)
98138
strscan (3.1.0)
99139
tempfile (0.2.1)
140+
terminal-table (3.0.2)
141+
unicode-display_width (>= 1.1.1, < 3)
100142
test-unit (3.6.2)
101143
power_assert
102144
timeout (0.4.1)
145+
tzinfo (2.0.6)
146+
concurrent-ruby (~> 1.0)
103147
unicode-display_width (2.5.0)
104148

105149
PLATFORMS
@@ -133,6 +177,7 @@ DEPENDENCIES
133177
rubocop
134178
rubocop-rubycw
135179
stackprof
180+
steep (~> 1.7.0.dev)
136181
tempfile
137182
test-unit
138183

Rakefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Rake::TestTask.new(:test => :compile) do |t|
1919
end
2020
end
2121

22-
multitask :default => [:test, :stdlib_test, :rubocop, :validate, :test_doc]
22+
multitask :default => [:test, :stdlib_test, :typecheck_test, :rubocop, :validate, :test_doc]
2323

2424
task :lexer do
2525
sh "re2c -W --no-generation-date -o ext/rbs_extension/lexer.c ext/rbs_extension/lexer.re"
@@ -92,6 +92,19 @@ task :stdlib_test => :compile do
9292
sh "#{ruby} -Ilib #{bin}/test_runner.rb test/stdlib/Encoding_test.rb"
9393
end
9494

95+
task :typecheck_test => :compile do
96+
FileList["test/typecheck/*"].each do |test|
97+
Dir.chdir(test) do
98+
expectations = File.join(test, "steep_expectations.yml")
99+
if File.exist?(expectations)
100+
sh "steep check --with_expectations"
101+
else
102+
sh "steep check"
103+
end
104+
end
105+
end
106+
end
107+
95108
task :raap => :compile do
96109
sh %q[cat test/raap.txt | egrep -v '^#|^$' | xargs bundle exec raap]
97110
end

core/float.rbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ class Float < Numeric
442442
# 13.0.divmod(4.0) # => [3, 1.0]
443443
# 13.0.divmod(Rational(4, 1)) # => [3, 1.0]
444444
#
445-
def divmod: (Numeric) -> [ Numeric, Numeric ]
445+
def divmod: (Integer | Float | Rational) -> [ Integer, Float ]
446+
| (Numeric) -> [ Numeric, Numeric ]
446447

447448
def dup: () -> self
448449

core/integer.rbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,8 @@ class Integer < Numeric
766766
# 13.divmod(Rational(4, 1)) # => [3, (1/1)]
767767
#
768768
def divmod: (Integer) -> [ Integer, Integer ]
769-
| (Float) -> [ Float, Float ]
769+
| (Float) -> [ Integer, Float ]
770+
| (Rational) -> [ Integer, Rational ]
770771
| (Numeric) -> [ Numeric, Numeric ]
771772

772773
# <!--

core/rational.rbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ class Rational < Numeric
245245

246246
def div: (Numeric) -> Integer
247247

248-
def divmod: (Numeric) -> [ Numeric, Numeric ]
248+
def divmod: (Integer | Float | Rational) -> [ Integer, Rational ]
249+
| (Numeric) -> [ Numeric, Numeric ]
249250

250251
def dup: () -> self
251252

test/typecheck/sleep/Steepfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
D = Steep::Diagnostic
2+
3+
target :test do
4+
signature "."
5+
check "."
6+
configure_code_diagnostics(D::Ruby.all_error)
7+
end

test/typecheck/sleep/sleep.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
sleep 1
2+
sleep 1.0
3+
sleep 1.to_r

0 commit comments

Comments
 (0)