steep 0.36.0 → 0.41.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/CHANGELOG.md +29 -0
  4. data/Rakefile +5 -2
  5. data/bin/output_rebaseline.rb +34 -0
  6. data/bin/output_test.rb +53 -0
  7. data/lib/steep.rb +18 -3
  8. data/lib/steep/ast/types/bot.rb +1 -1
  9. data/lib/steep/ast/types/factory.rb +122 -53
  10. data/lib/steep/ast/types/logic.rb +16 -3
  11. data/lib/steep/ast/types/proc.rb +32 -20
  12. data/lib/steep/ast/types/top.rb +1 -1
  13. data/lib/steep/cli.rb +10 -4
  14. data/lib/steep/diagnostic/helper.rb +17 -0
  15. data/lib/steep/diagnostic/lsp_formatter.rb +16 -0
  16. data/lib/steep/diagnostic/ruby.rb +623 -0
  17. data/lib/steep/diagnostic/signature.rb +224 -0
  18. data/lib/steep/drivers/annotations.rb +13 -6
  19. data/lib/steep/drivers/check.rb +171 -56
  20. data/lib/steep/drivers/diagnostic_printer.rb +94 -0
  21. data/lib/steep/drivers/stats.rb +125 -29
  22. data/lib/steep/drivers/trace_printer.rb +5 -1
  23. data/lib/steep/drivers/validate.rb +13 -6
  24. data/lib/steep/drivers/watch.rb +26 -9
  25. data/lib/steep/drivers/worker.rb +5 -0
  26. data/lib/steep/expectations.rb +159 -0
  27. data/lib/steep/index/rbs_index.rb +334 -0
  28. data/lib/steep/index/signature_symbol_provider.rb +154 -0
  29. data/lib/steep/index/source_index.rb +100 -0
  30. data/lib/steep/interface/block.rb +79 -0
  31. data/lib/steep/interface/function.rb +770 -0
  32. data/lib/steep/interface/method_type.rb +32 -812
  33. data/lib/steep/project.rb +6 -0
  34. data/lib/steep/project/options.rb +4 -4
  35. data/lib/steep/project/signature_file.rb +8 -2
  36. data/lib/steep/project/stats_calculator.rb +80 -0
  37. data/lib/steep/project/target.rb +64 -53
  38. data/lib/steep/range_extension.rb +29 -0
  39. data/lib/steep/server/base_worker.rb +42 -4
  40. data/lib/steep/server/code_worker.rb +37 -24
  41. data/lib/steep/server/interaction_worker.rb +1 -0
  42. data/lib/steep/server/master.rb +269 -79
  43. data/lib/steep/server/signature_worker.rb +70 -65
  44. data/lib/steep/server/worker_process.rb +9 -9
  45. data/lib/steep/signature/validator.rb +56 -8
  46. data/lib/steep/subtyping/check.rb +21 -18
  47. data/lib/steep/subtyping/variable_occurrence.rb +2 -2
  48. data/lib/steep/subtyping/variable_variance.rb +2 -2
  49. data/lib/steep/type_construction.rb +471 -267
  50. data/lib/steep/type_inference/block_params.rb +1 -1
  51. data/lib/steep/type_inference/constant_env.rb +5 -1
  52. data/lib/steep/type_inference/logic_type_interpreter.rb +99 -26
  53. data/lib/steep/typing.rb +8 -2
  54. data/lib/steep/version.rb +1 -1
  55. data/smoke/alias/a.rb +0 -3
  56. data/smoke/alias/b.rb +0 -1
  57. data/smoke/alias/c.rb +0 -2
  58. data/smoke/alias/test_expectations.yml +96 -0
  59. data/smoke/and/a.rb +0 -3
  60. data/smoke/and/test_expectations.yml +31 -0
  61. data/smoke/array/a.rb +0 -3
  62. data/smoke/array/b.rb +0 -2
  63. data/smoke/array/c.rb +0 -1
  64. data/smoke/array/test_expectations.yml +103 -0
  65. data/smoke/block/a.rb +0 -2
  66. data/smoke/block/b.rb +0 -2
  67. data/smoke/block/d.rb +0 -4
  68. data/smoke/block/test_expectations.yml +125 -0
  69. data/smoke/case/a.rb +0 -3
  70. data/smoke/case/test_expectations.yml +47 -0
  71. data/smoke/class/a.rb +0 -3
  72. data/smoke/class/c.rb +0 -1
  73. data/smoke/class/f.rb +0 -1
  74. data/smoke/class/g.rb +0 -2
  75. data/smoke/class/i.rb +0 -2
  76. data/smoke/class/test_expectations.yml +120 -0
  77. data/smoke/const/a.rb +0 -3
  78. data/smoke/const/b.rb +7 -0
  79. data/smoke/const/b.rbs +5 -0
  80. data/smoke/const/test_expectations.yml +139 -0
  81. data/smoke/diagnostics-rbs-duplicated/Steepfile +5 -0
  82. data/smoke/diagnostics-rbs-duplicated/a.rbs +5 -0
  83. data/smoke/diagnostics-rbs-duplicated/test_expectations.yml +13 -0
  84. data/smoke/diagnostics-rbs/Steepfile +5 -0
  85. data/smoke/diagnostics-rbs/duplicated-method-definition.rbs +20 -0
  86. data/smoke/diagnostics-rbs/generic-parameter-mismatch.rbs +7 -0
  87. data/smoke/diagnostics-rbs/invalid-method-overload.rbs +3 -0
  88. data/smoke/diagnostics-rbs/invalid-type-application.rbs +7 -0
  89. data/smoke/diagnostics-rbs/invalid_variance_annotation.rbs +3 -0
  90. data/smoke/diagnostics-rbs/recursive-alias.rbs +5 -0
  91. data/smoke/diagnostics-rbs/recursive-class.rbs +8 -0
  92. data/smoke/diagnostics-rbs/superclass-mismatch.rbs +7 -0
  93. data/smoke/diagnostics-rbs/test_expectations.yml +229 -0
  94. data/smoke/diagnostics-rbs/unknown-method-alias.rbs +3 -0
  95. data/smoke/diagnostics-rbs/unknown-type-name.rbs +13 -0
  96. data/smoke/diagnostics/Steepfile +5 -0
  97. data/smoke/diagnostics/a.rbs +26 -0
  98. data/smoke/diagnostics/argument_type_mismatch.rb +1 -0
  99. data/smoke/diagnostics/block_body_type_mismatch.rb +1 -0
  100. data/smoke/diagnostics/block_type_mismatch.rb +3 -0
  101. data/smoke/diagnostics/break_type_mismatch.rb +1 -0
  102. data/smoke/diagnostics/else_on_exhaustive_case.rb +12 -0
  103. data/smoke/diagnostics/incompatible_annotation.rb +6 -0
  104. data/smoke/diagnostics/incompatible_argument.rb +1 -0
  105. data/smoke/diagnostics/incompatible_assignment.rb +8 -0
  106. data/smoke/diagnostics/method_arity_mismatch.rb +11 -0
  107. data/smoke/diagnostics/method_body_type_mismatch.rb +6 -0
  108. data/smoke/diagnostics/method_definition_missing.rb +2 -0
  109. data/smoke/diagnostics/method_return_type_annotation_mismatch.rb +7 -0
  110. data/smoke/diagnostics/missing_keyword.rb +1 -0
  111. data/smoke/diagnostics/no_method.rb +1 -0
  112. data/smoke/diagnostics/required_block_missing.rb +1 -0
  113. data/smoke/diagnostics/return_type_mismatch.rb +6 -0
  114. data/smoke/diagnostics/test_expectations.yml +477 -0
  115. data/smoke/diagnostics/unexpected_block_given.rb +1 -0
  116. data/smoke/diagnostics/unexpected_dynamic_method.rb +3 -0
  117. data/smoke/diagnostics/unexpected_jump.rb +4 -0
  118. data/smoke/diagnostics/unexpected_jump_value.rb +3 -0
  119. data/smoke/diagnostics/unexpected_keyword.rb +1 -0
  120. data/smoke/diagnostics/unexpected_splat.rb +1 -0
  121. data/smoke/diagnostics/unexpected_yield.rb +6 -0
  122. data/smoke/diagnostics/unknown_constant_assigned.rb +7 -0
  123. data/smoke/diagnostics/unresolved_overloading.rb +1 -0
  124. data/smoke/diagnostics/unsatisfiable_constraint.rb +7 -0
  125. data/smoke/diagnostics/unsupported_syntax.rb +2 -0
  126. data/smoke/dstr/a.rb +0 -1
  127. data/smoke/dstr/test_expectations.yml +13 -0
  128. data/smoke/ensure/a.rb +0 -4
  129. data/smoke/ensure/test_expectations.yml +62 -0
  130. data/smoke/enumerator/a.rb +0 -6
  131. data/smoke/enumerator/b.rb +0 -3
  132. data/smoke/enumerator/test_expectations.yml +135 -0
  133. data/smoke/extension/a.rb +0 -1
  134. data/smoke/extension/b.rb +0 -2
  135. data/smoke/extension/c.rb +0 -1
  136. data/smoke/extension/test_expectations.yml +61 -0
  137. data/smoke/hash/b.rb +0 -1
  138. data/smoke/hash/c.rb +0 -3
  139. data/smoke/hash/d.rb +0 -1
  140. data/smoke/hash/e.rb +0 -1
  141. data/smoke/hash/test_expectations.yml +81 -0
  142. data/smoke/hello/hello.rb +0 -2
  143. data/smoke/hello/test_expectations.yml +25 -0
  144. data/smoke/if/a.rb +0 -2
  145. data/smoke/if/test_expectations.yml +34 -0
  146. data/smoke/implements/a.rb +0 -2
  147. data/smoke/implements/test_expectations.yml +23 -0
  148. data/smoke/initialize/test_expectations.yml +1 -0
  149. data/smoke/integer/a.rb +0 -7
  150. data/smoke/integer/test_expectations.yml +101 -0
  151. data/smoke/interface/a.rb +0 -2
  152. data/smoke/interface/test_expectations.yml +23 -0
  153. data/smoke/kwbegin/a.rb +0 -1
  154. data/smoke/kwbegin/test_expectations.yml +17 -0
  155. data/smoke/lambda/a.rb +1 -4
  156. data/smoke/lambda/test_expectations.yml +39 -0
  157. data/smoke/literal/a.rb +0 -5
  158. data/smoke/literal/b.rb +0 -2
  159. data/smoke/literal/test_expectations.yml +106 -0
  160. data/smoke/map/test_expectations.yml +1 -0
  161. data/smoke/method/a.rb +0 -5
  162. data/smoke/method/b.rb +0 -1
  163. data/smoke/method/test_expectations.yml +90 -0
  164. data/smoke/module/a.rb +0 -2
  165. data/smoke/module/b.rb +0 -2
  166. data/smoke/module/c.rb +0 -1
  167. data/smoke/module/d.rb +0 -1
  168. data/smoke/module/f.rb +0 -2
  169. data/smoke/module/test_expectations.yml +75 -0
  170. data/smoke/regexp/a.rb +0 -38
  171. data/smoke/regexp/b.rb +0 -26
  172. data/smoke/regexp/test_expectations.yml +615 -0
  173. data/smoke/regression/set_divide.rb +0 -4
  174. data/smoke/regression/test_expectations.yml +43 -0
  175. data/smoke/rescue/a.rb +0 -5
  176. data/smoke/rescue/test_expectations.yml +79 -0
  177. data/smoke/self/a.rb +0 -2
  178. data/smoke/self/test_expectations.yml +23 -0
  179. data/smoke/skip/skip.rb +0 -2
  180. data/smoke/skip/test_expectations.yml +23 -0
  181. data/smoke/stdout/test_expectations.yml +1 -0
  182. data/smoke/super/a.rb +0 -4
  183. data/smoke/super/test_expectations.yml +79 -0
  184. data/smoke/toplevel/a.rb +0 -1
  185. data/smoke/toplevel/test_expectations.yml +15 -0
  186. data/smoke/tsort/Steepfile +6 -0
  187. data/smoke/tsort/a.rb +12 -0
  188. data/smoke/tsort/test_expectations.yml +43 -0
  189. data/smoke/type_case/a.rb +0 -4
  190. data/smoke/type_case/test_expectations.yml +48 -0
  191. data/smoke/yield/a.rb +0 -3
  192. data/smoke/yield/b.rb +6 -0
  193. data/smoke/yield/test_expectations.yml +68 -0
  194. data/steep.gemspec +3 -3
  195. metadata +113 -18
  196. data/bin/smoke_runner.rb +0 -139
  197. data/lib/steep/drivers/signature_error_printer.rb +0 -25
  198. data/lib/steep/errors.rb +0 -565
  199. data/lib/steep/signature/errors.rb +0 -82
  200. data/lib/steep/type_assignability.rb +0 -367
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5203340eb3b3534da5f1071cc497bbe7a481553e909088277c83dbfe5e5c0bbc
4
- data.tar.gz: 11863c0ea9b692de6fba552ec01645525240c025c598235f9b3bf88e35571ed5
3
+ metadata.gz: 7fe01659cf0cfc1c7063fede02ec238b5772bb6c6fdf44cf501ca555c719c47c
4
+ data.tar.gz: d74ebe84a911514eef46cd92a14dfedc0b90e491aa9bf284f82325a9c4a9c2b4
5
5
  SHA512:
6
- metadata.gz: 9897fecb7ca5b60da9eeb236e5f06af1a9b2fa2a2df2bd87d07f7a496f0f05b988b30db2e294797304c6d7f0e8fe478cdc1d41049cbaf2e56c45108444b2c721
7
- data.tar.gz: fa2dca2cd37d74e39878ab3da7a5453a714f50e921fcd1c0e75054bf083a11003cb5799f4f92531a10bce6074dce3cce88c90daeb214b9fb45d7f5612e294fb3
6
+ metadata.gz: cd2459353ab367c913f0308b1cb0dd95d297cce18ea3bb4ff537612edc0b8adc2ef4530d4bf8203c6c777fe57b8bccfbf8a8714ebc0ede67400a030e6ea1348f
7
+ data.tar.gz: b3ee38f5e340f05420783dc3f8a31ac662f475ec7bcef82222e5f07360faac1235249fa903c721a1d322b7999034b74e7f812fa47c3d3dec8a9f5763fa2693fb
@@ -16,7 +16,7 @@ jobs:
16
16
  - 2.7.0-bionic
17
17
  task:
18
18
  - test
19
- - smoke
19
+ - test:output
20
20
  - build
21
21
  container:
22
22
  image: rubylang/ruby:${{ matrix.container_tag }}
data/CHANGELOG.md CHANGED
@@ -2,6 +2,35 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.41.0 (2021-02-07)
6
+
7
+ * Add `--with-expectations` and `--save-expectations` option ([#303](https://github.com/soutaro/steep/pull/303))
8
+
9
+ ## 0.40.0 (2021-01-31)
10
+
11
+ * Report progress with dots ([#287](https://github.com/soutaro/steep/pull/287))
12
+ * Diagnostics message improvements ([#297](https://github.com/soutaro/steep/pull/297), [#301](https://github.com/soutaro/steep/pull/301))
13
+ * Fix error on implicit `to_proc` syntax when `untyped` is yielded ([#291](https://github.com/soutaro/steep/pull/291))
14
+
15
+ ## 0.39.0 (2020-12-25)
16
+
17
+ * Update RBS to 1.0.0 ([#282](https://github.com/soutaro/steep/pull/282))
18
+ * Better `&&` and `||` typing ([#276](https://github.com/soutaro/steep/pull/276))
19
+ * Type case based on literals ([#277](https://github.com/soutaro/steep/pull/277))
20
+ * Type case improvements ([#279](https://github.com/soutaro/steep/pull/279), [#283](https://github.com/soutaro/steep/pull/283))
21
+ * Improvements on untyped classes/modules, unsupported syntax error handling, and argument types in untyped methods ([#280](https://github.com/soutaro/steep/pull/280))
22
+ * Fix `bot` and `top` type format ([#278](https://github.com/soutaro/steep/pull/278))
23
+ * Colorfull error messages ([#273](https://github.com/soutaro/steep/pull/273))
24
+
25
+ ## 0.38.0 (2020-12-10)
26
+
27
+ * Improve `break`/`next` typing ([#271](https://github.com/soutaro/steep/pull/271))
28
+ * Add LSP `workspace/symbol` feature ([#267](https://github.com/soutaro/steep/pull/267))
29
+
30
+ ## 0.37.0 (2020-12-06)
31
+
32
+ * Update to RBS 0.20.0 with _singleton attribute_ syntax and _proc types with blocks_. ([#264](https://github.com/soutaro/steep/pull/264))
33
+
5
34
  ## 0.36.0 (2020-11-16)
6
35
 
7
36
  * Flow-sensitive typing improvements with `||` and `&&` ([#260](https://github.com/soutaro/steep/pull/260))
data/Rakefile CHANGED
@@ -9,6 +9,9 @@ end
9
9
 
10
10
  task :default => :test
11
11
 
12
- task :smoke do
13
- sh "bundle", "exec", "bin/smoke_runner.rb", *Dir.glob("smoke/*")
12
+ namespace :test do
13
+ desc "Run output test"
14
+ task :output do
15
+ sh "ruby", "bin/output_test.rb"
16
+ end
14
17
  end
@@ -0,0 +1,34 @@
1
+ require "pathname"
2
+ require "yaml"
3
+ require "open3"
4
+ require "tempfile"
5
+
6
+ if ARGV.empty?
7
+ test_dirs = (Pathname(__dir__) + "../smoke").children
8
+ else
9
+ test_dirs = ARGV.map {|p| Pathname.pwd + p }
10
+ end
11
+
12
+ failed_tests = []
13
+
14
+ test_dirs.each do |dir|
15
+ puts "Rebaselining #{dir}..."
16
+
17
+ command = %w(steep check --save-expectations=test_expectations.yml)
18
+ puts " command: #{command.join(" ")}"
19
+
20
+ output, status = Open3.capture2(*command, chdir: dir.to_s)
21
+
22
+ unless status.success?
23
+ puts "Error!!! 👺"
24
+ failed_tests << dir.basename
25
+ end
26
+ end
27
+
28
+ if failed_tests.empty?
29
+ puts "Successfully updated output expectations! 🤡"
30
+ else
31
+ puts "Failed to update the following tests! 💀"
32
+ puts " #{failed_tests.join(", ")}"
33
+ exit 1
34
+ end
@@ -0,0 +1,53 @@
1
+ require "pathname"
2
+ require "yaml"
3
+ require "open3"
4
+ require "tempfile"
5
+ require "optparse"
6
+
7
+ OptionParser.new do |opts|
8
+ opts.on("--verbose", "-v") { @verbose = true }
9
+ end.parse!(ARGV)
10
+
11
+ if ARGV.empty?
12
+ test_dirs = (Pathname(__dir__) + "../smoke").children
13
+ else
14
+ test_dirs = ARGV.map {|p| Pathname.pwd + p }
15
+ end
16
+
17
+ failed_tests = []
18
+
19
+ test_dirs.each do |dir|
20
+ puts "Running test #{dir}..."
21
+
22
+ unless (dir + "test_expectations.yml").file?
23
+ puts "Skipped ⛹️‍♀️"
24
+ next
25
+ end
26
+
27
+ command = %w(steep check --with-expectations=test_expectations.yml)
28
+ puts " command: #{command.join(" ")}"
29
+
30
+ output, status = Open3.capture2(*command, chdir: dir.to_s)
31
+
32
+ unless status.success?
33
+ failed_tests << dir.basename
34
+ puts " Failed! 🤕"
35
+ else
36
+ puts " Succeed! 👍"
37
+ end
38
+
39
+ if @verbose
40
+ puts " Raw output:"
41
+ output.split(/\n/).each do |line|
42
+ puts " > #{line.chomp}"
43
+ end
44
+ end
45
+ end
46
+
47
+ if failed_tests.empty?
48
+ puts "All tests ok! 👏"
49
+ else
50
+ puts "Errors detected! 🤮"
51
+ puts " #{failed_tests.join(", ")}"
52
+ exit 1
53
+ end
data/lib/steep.rb CHANGED
@@ -4,6 +4,7 @@ require "pathname"
4
4
  require "parser/ruby27"
5
5
  require "ast_utils"
6
6
  require "active_support/core_ext/object/try"
7
+ require "active_support/core_ext/string/inflections"
7
8
  require "logger"
8
9
  require "active_support/tagged_logging"
9
10
  require "rainbow"
@@ -13,6 +14,7 @@ require "etc"
13
14
  require "open3"
14
15
  require "stringio"
15
16
  require 'uri'
17
+ require "yaml"
16
18
 
17
19
  require "rbs"
18
20
 
@@ -42,6 +44,10 @@ require "steep/ast/annotation/collection"
42
44
  require "steep/ast/builtin"
43
45
  require "steep/ast/types/factory"
44
46
 
47
+ require "steep/range_extension"
48
+
49
+ require "steep/interface/function"
50
+ require "steep/interface/block"
45
51
  require "steep/interface/method_type"
46
52
  require "steep/interface/substitution"
47
53
  require "steep/interface/interface"
@@ -54,12 +60,14 @@ require "steep/subtyping/constraints"
54
60
  require "steep/subtyping/variable_variance"
55
61
  require "steep/subtyping/variable_occurrence"
56
62
 
57
- require "steep/signature/errors"
63
+ require "steep/diagnostic/helper"
64
+ require "steep/diagnostic/ruby"
65
+ require "steep/diagnostic/signature"
66
+ require "steep/diagnostic/lsp_formatter"
58
67
  require "steep/signature/validator"
59
68
  require "steep/source"
60
69
  require "steep/annotation_parser"
61
70
  require "steep/typing"
62
- require "steep/errors"
63
71
  require "steep/module_helper"
64
72
  require "steep/type_construction"
65
73
  require "steep/type_inference/context"
@@ -74,6 +82,10 @@ require "steep/type_inference/logic_type_interpreter"
74
82
  require "steep/type_inference/method_call"
75
83
  require "steep/ast/types"
76
84
 
85
+ require "steep/index/rbs_index"
86
+ require "steep/index/signature_symbol_provider"
87
+ require "steep/index/source_index"
88
+
77
89
  require "steep/server/utils"
78
90
  require "steep/server/base_worker"
79
91
  require "steep/server/code_worker"
@@ -91,6 +103,9 @@ require "steep/project/dsl"
91
103
  require "steep/project/file_loader"
92
104
  require "steep/project/hover_content"
93
105
  require "steep/project/completion_provider"
106
+ require "steep/project/stats_calculator"
107
+
108
+ require "steep/expectations"
94
109
  require "steep/drivers/utils/driver_helper"
95
110
  require "steep/drivers/check"
96
111
  require "steep/drivers/stats"
@@ -98,12 +113,12 @@ require "steep/drivers/validate"
98
113
  require "steep/drivers/annotations"
99
114
  require "steep/drivers/watch"
100
115
  require "steep/drivers/langserver"
101
- require "steep/drivers/signature_error_printer"
102
116
  require "steep/drivers/trace_printer"
103
117
  require "steep/drivers/print_project"
104
118
  require "steep/drivers/init"
105
119
  require "steep/drivers/vendor"
106
120
  require "steep/drivers/worker"
121
+ require "steep/drivers/diagnostic_printer"
107
122
 
108
123
  if ENV["NO_COLOR"]
109
124
  Rainbow.enabled = false
@@ -23,7 +23,7 @@ module Steep
23
23
  end
24
24
 
25
25
  def to_s
26
- ""
26
+ "bot"
27
27
  end
28
28
 
29
29
  include Helper::NoFreeVariables
@@ -75,9 +75,23 @@ module Steep
75
75
  end
76
76
  Record.new(elements: elements, location: nil)
77
77
  when RBS::Types::Proc
78
- params = params(type.type)
79
- return_type = type(type.type.return_type)
80
- Proc.new(params: params, return_type: return_type, location: nil)
78
+ func = Interface::Function.new(
79
+ params: params(type.type),
80
+ return_type: type(type.type.return_type),
81
+ location: type.location
82
+ )
83
+ block = if type.block
84
+ Interface::Block.new(
85
+ type: Interface::Function.new(
86
+ params: params(type.block.type),
87
+ return_type: type(type.block.type.return_type),
88
+ location: type.location
89
+ ),
90
+ optional: !type.block.required
91
+ )
92
+ end
93
+
94
+ Proc.new(type: func, block: block)
81
95
  else
82
96
  raise "Unexpected type given: #{type}"
83
97
  end
@@ -145,8 +159,15 @@ module Steep
145
159
  end
146
160
  RBS::Types::Record.new(fields: fields, location: nil)
147
161
  when Proc
162
+ block = if type.block
163
+ RBS::Types::Block.new(
164
+ type: function_1(type.block.type),
165
+ required: !type.block.optional?
166
+ )
167
+ end
148
168
  RBS::Types::Proc.new(
149
- type: function_1(type.params, type.return_type),
169
+ type: function_1(type.type),
170
+ block: block,
150
171
  location: nil
151
172
  )
152
173
  when Logic::Base
@@ -156,7 +177,10 @@ module Steep
156
177
  end
157
178
  end
158
179
 
159
- def function_1(params, return_type)
180
+ def function_1(func)
181
+ params = func.params
182
+ return_type = func.return_type
183
+
160
184
  RBS::Types::Function.new(
161
185
  required_positionals: params.required.map {|type| RBS::Types::Function::Param.new(name: nil, type: type_1(type)) },
162
186
  optional_positionals: params.optional.map {|type| RBS::Types::Function::Param.new(name: nil, type: type_1(type)) },
@@ -170,7 +194,7 @@ module Steep
170
194
  end
171
195
 
172
196
  def params(type)
173
- Interface::Params.new(
197
+ Interface::Function::Params.new(
174
198
  required: type.required_positionals.map {|param| type(param.type) },
175
199
  optional: type.optional_positionals.map {|param| type(param.type) },
176
200
  rest: type.rest_positionals&.yield_self {|param| type(param.type) },
@@ -202,13 +226,19 @@ module Steep
202
226
 
203
227
  type = Interface::MethodType.new(
204
228
  type_params: type_params,
205
- return_type: type(method_type.type.return_type).subst(subst),
206
- params: params(method_type.type).subst(subst),
229
+ type: Interface::Function.new(
230
+ params: params(method_type.type).subst(subst),
231
+ return_type: type(method_type.type.return_type).subst(subst),
232
+ location: method_type.location
233
+ ),
207
234
  block: method_type.block&.yield_self do |block|
208
235
  Interface::Block.new(
209
236
  optional: !block.required,
210
- type: Proc.new(params: params(block.type).subst(subst),
211
- return_type: type(block.type.return_type).subst(subst), location: nil)
237
+ type: Interface::Function.new(
238
+ params: params(block.type).subst(subst),
239
+ return_type: type(block.type.return_type).subst(subst),
240
+ location: nil
241
+ )
212
242
  )
213
243
  end,
214
244
  method_decls: method_decls
@@ -242,12 +272,12 @@ module Steep
242
272
 
243
273
  type = RBS::MethodType.new(
244
274
  type_params: type_params,
245
- type: function_1(method_type.params.subst(subst), method_type.return_type.subst(subst)),
275
+ type: function_1(method_type.type.subst(subst)),
246
276
  block: method_type.block&.yield_self do |block|
247
277
  block_type = block.type.subst(subst)
248
278
 
249
- RBS::MethodType::Block.new(
250
- type: function_1(block_type.params, block_type.return_type),
279
+ RBS::Types::Block.new(
280
+ type: function_1(block_type),
251
281
  required: !block.optional
252
282
  )
253
283
  end,
@@ -338,6 +368,8 @@ module Steep
338
368
  ]
339
369
  when AST::Types::Name::Alias
340
370
  unwrap_optional(expand_alias(type))
371
+ when AST::Types::Boolean
372
+ [AST::Builtin.true_type, AST::Builtin.false_type]
341
373
  else
342
374
  [type, nil]
343
375
  end
@@ -354,7 +386,9 @@ module Steep
354
386
  when :is_a?, :kind_of?, :instance_of?
355
387
  if defined_in == RBS::BuiltinNames::Object.name && member.instance?
356
388
  return method_type.with(
357
- return_type: AST::Types::Logic::ReceiverIsArg.new(location: method_type.return_type.location)
389
+ type: method_type.type.with(
390
+ return_type: AST::Types::Logic::ReceiverIsArg.new(location: method_type.type.return_type.location)
391
+ )
358
392
  )
359
393
  end
360
394
 
@@ -363,7 +397,9 @@ module Steep
363
397
  when RBS::BuiltinNames::Object.name,
364
398
  NilClassName
365
399
  return method_type.with(
366
- return_type: AST::Types::Logic::ReceiverIsNil.new(location: method_type.return_type.location)
400
+ type: method_type.type.with(
401
+ return_type: AST::Types::Logic::ReceiverIsNil.new(location: method_type.type.return_type.location)
402
+ )
367
403
  )
368
404
  end
369
405
 
@@ -373,7 +409,9 @@ module Steep
373
409
  RBS::BuiltinNames::TrueClass.name,
374
410
  RBS::BuiltinNames::FalseClass.name
375
411
  return method_type.with(
376
- return_type: AST::Types::Logic::Not.new(location: method_type.return_type.location)
412
+ type: method_type.type.with(
413
+ return_type: AST::Types::Logic::Not.new(location: method_type.type.return_type.location)
414
+ )
377
415
  )
378
416
  end
379
417
 
@@ -381,7 +419,17 @@ module Steep
381
419
  case defined_in
382
420
  when RBS::BuiltinNames::Module.name
383
421
  return method_type.with(
384
- return_type: AST::Types::Logic::ArgIsReceiver.new(location: method_type.return_type.location)
422
+ type: method_type.type.with(
423
+ return_type: AST::Types::Logic::ArgIsReceiver.new(location: method_type.type.return_type.location)
424
+ )
425
+ )
426
+ when RBS::BuiltinNames::Object.name, RBS::BuiltinNames::String.name, RBS::BuiltinNames::Integer.name, RBS::BuiltinNames::Symbol.name,
427
+ RBS::BuiltinNames::TrueClass.name, RBS::BuiltinNames::FalseClass.name, TypeName("::NilClass")
428
+ # Value based type-case works on literal types which is available for String, Integer, Symbol, TrueClass, FalseClass, and NilClass
429
+ return method_type.with(
430
+ type: method_type.type.with(
431
+ return_type: AST::Types::Logic::ArgEqualsReceiver.new(location: method_type.type.return_type.location)
432
+ )
385
433
  )
386
434
  end
387
435
  end
@@ -572,14 +620,17 @@ module Steep
572
620
  method_types: type.types.map.with_index {|elem_type, index|
573
621
  Interface::MethodType.new(
574
622
  type_params: [],
575
- params: Interface::Params.new(required: [AST::Types::Literal.new(value: index)],
576
- optional: [],
577
- rest: nil,
578
- required_keywords: {},
579
- optional_keywords: {},
580
- rest_keywords: nil),
623
+ type: Interface::Function.new(
624
+ params: Interface::Function::Params.new(required: [AST::Types::Literal.new(value: index)],
625
+ optional: [],
626
+ rest: nil,
627
+ required_keywords: {},
628
+ optional_keywords: {},
629
+ rest_keywords: nil),
630
+ return_type: elem_type,
631
+ location: nil
632
+ ),
581
633
  block: nil,
582
- return_type: elem_type,
583
634
  method_decls: Set[]
584
635
  )
585
636
  } + aref.method_types
@@ -591,14 +642,17 @@ module Steep
591
642
  method_types: type.types.map.with_index {|elem_type, index|
592
643
  Interface::MethodType.new(
593
644
  type_params: [],
594
- params: Interface::Params.new(required: [AST::Types::Literal.new(value: index), elem_type],
595
- optional: [],
596
- rest: nil,
597
- required_keywords: {},
598
- optional_keywords: {},
599
- rest_keywords: nil),
645
+ type: Interface::Function.new(
646
+ params: Interface::Function::Params.new(required: [AST::Types::Literal.new(value: index), elem_type],
647
+ optional: [],
648
+ rest: nil,
649
+ required_keywords: {},
650
+ optional_keywords: {},
651
+ rest_keywords: nil),
652
+ return_type: elem_type,
653
+ location: nil
654
+ ),
600
655
  block: nil,
601
- return_type: elem_type,
602
656
  method_decls: Set[]
603
657
  )
604
658
  } + update.method_types
@@ -610,9 +664,12 @@ module Steep
610
664
  method_types: [
611
665
  Interface::MethodType.new(
612
666
  type_params: [],
613
- params: Interface::Params.empty,
667
+ type: Interface::Function.new(
668
+ params: Interface::Function::Params.empty,
669
+ return_type: type.types[0] || AST::Builtin.nil_type,
670
+ location: nil
671
+ ),
614
672
  block: nil,
615
- return_type: type.types[0] || AST::Builtin.nil_type,
616
673
  method_decls: Set[]
617
674
  )
618
675
  ]
@@ -624,9 +681,12 @@ module Steep
624
681
  method_types: [
625
682
  Interface::MethodType.new(
626
683
  type_params: [],
627
- params: Interface::Params.empty,
684
+ type: Interface::Function.new(
685
+ params: Interface::Function::Params.empty,
686
+ return_type: type.types.last || AST::Builtin.nil_type,
687
+ location: nil
688
+ ),
628
689
  block: nil,
629
- return_type: type.types.last || AST::Builtin.nil_type,
630
690
  method_decls: Set[]
631
691
  )
632
692
  ]
@@ -651,14 +711,17 @@ module Steep
651
711
 
652
712
  Interface::MethodType.new(
653
713
  type_params: [],
654
- params: Interface::Params.new(required: [key_type],
655
- optional: [],
656
- rest: nil,
657
- required_keywords: {},
658
- optional_keywords: {},
659
- rest_keywords: nil),
714
+ type: Interface::Function.new(
715
+ params: Interface::Function::Params.new(required: [key_type],
716
+ optional: [],
717
+ rest: nil,
718
+ required_keywords: {},
719
+ optional_keywords: {},
720
+ rest_keywords: nil),
721
+ return_type: value_type,
722
+ location: nil
723
+ ),
660
724
  block: nil,
661
- return_type: value_type,
662
725
  method_decls: Set[]
663
726
  )
664
727
  } + ref.method_types
@@ -671,14 +734,16 @@ module Steep
671
734
  key_type = Literal.new(value: key_value, location: nil)
672
735
  Interface::MethodType.new(
673
736
  type_params: [],
674
- params: Interface::Params.new(required: [key_type, value_type],
675
- optional: [],
676
- rest: nil,
677
- required_keywords: {},
678
- optional_keywords: {},
679
- rest_keywords: nil),
737
+ type: Interface::Function.new(
738
+ params: Interface::Function::Params.new(required: [key_type, value_type],
739
+ optional: [],
740
+ rest: nil,
741
+ required_keywords: {},
742
+ optional_keywords: {},
743
+ rest_keywords: nil),
744
+ return_type: value_type,
745
+ location: nil),
680
746
  block: nil,
681
- return_type: value_type,
682
747
  method_decls: Set[]
683
748
  )
684
749
  } + update.method_types
@@ -691,14 +756,18 @@ module Steep
691
756
  interface(Builtin::Proc.instance_type, private: private, self_type: self_type).tap do |interface|
692
757
  method_type = Interface::MethodType.new(
693
758
  type_params: [],
694
- params: type.params,
695
- return_type: type.return_type,
696
- block: nil,
759
+ type: type.type,
760
+ block: type.block,
697
761
  method_decls: Set[]
698
762
  )
699
763
 
700
- interface.methods[:[]] = Interface::Interface::Entry.new(method_types: [method_type])
701
764
  interface.methods[:call] = Interface::Interface::Entry.new(method_types: [method_type])
765
+
766
+ if type.block_required?
767
+ interface.methods.delete(:[])
768
+ else
769
+ interface.methods[:[]] = Interface::Interface::Entry.new(method_types: [method_type.with(block: nil)])
770
+ end
702
771
  end
703
772
 
704
773
  when Logic::Base