steep 0.47.0 → 0.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -0
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +14 -16
  5. data/lib/steep/ast/types/any.rb +2 -0
  6. data/lib/steep/ast/types/boolean.rb +2 -0
  7. data/lib/steep/ast/types/bot.rb +2 -0
  8. data/lib/steep/ast/types/class.rb +2 -0
  9. data/lib/steep/ast/types/factory.rb +162 -138
  10. data/lib/steep/ast/types/helper.rb +8 -0
  11. data/lib/steep/ast/types/instance.rb +2 -0
  12. data/lib/steep/ast/types/intersection.rb +4 -0
  13. data/lib/steep/ast/types/literal.rb +2 -0
  14. data/lib/steep/ast/types/logic.rb +2 -0
  15. data/lib/steep/ast/types/name.rb +6 -0
  16. data/lib/steep/ast/types/nil.rb +2 -0
  17. data/lib/steep/ast/types/proc.rb +9 -0
  18. data/lib/steep/ast/types/record.rb +4 -0
  19. data/lib/steep/ast/types/self.rb +2 -0
  20. data/lib/steep/ast/types/top.rb +2 -0
  21. data/lib/steep/ast/types/tuple.rb +4 -0
  22. data/lib/steep/ast/types/union.rb +4 -0
  23. data/lib/steep/ast/types/var.rb +16 -3
  24. data/lib/steep/ast/types/void.rb +2 -0
  25. data/lib/steep/diagnostic/ruby.rb +23 -11
  26. data/lib/steep/diagnostic/signature.rb +56 -0
  27. data/lib/steep/interface/function.rb +4 -0
  28. data/lib/steep/interface/method_type.rb +14 -26
  29. data/lib/steep/interface/type_param.rb +103 -0
  30. data/lib/steep/server/base_worker.rb +1 -0
  31. data/lib/steep/server/interaction_worker.rb +1 -1
  32. data/lib/steep/server/type_check_worker.rb +2 -2
  33. data/lib/steep/services/signature_service.rb +2 -2
  34. data/lib/steep/services/type_check_service.rb +2 -1
  35. data/lib/steep/signature/validator.rb +221 -49
  36. data/lib/steep/subtyping/cache.rb +30 -0
  37. data/lib/steep/subtyping/check.rb +600 -705
  38. data/lib/steep/subtyping/constraints.rb +66 -30
  39. data/lib/steep/subtyping/relation.rb +60 -0
  40. data/lib/steep/subtyping/result.rb +190 -16
  41. data/lib/steep/type_construction.rb +543 -395
  42. data/lib/steep/type_inference/block_params.rb +31 -3
  43. data/lib/steep/type_inference/context.rb +37 -3
  44. data/lib/steep/version.rb +1 -1
  45. data/lib/steep.rb +4 -4
  46. data/sample/lib/length.rb +35 -0
  47. data/sample/sig/length.rbs +34 -0
  48. data/smoke/diagnostics-rbs/nonregular-type-alias.rbs +3 -0
  49. data/smoke/diagnostics-rbs/recursive-type-alias.rbs +3 -0
  50. data/smoke/diagnostics-rbs/test_expectations.yml +57 -12
  51. data/smoke/tsort/a.rb +1 -1
  52. data/smoke/tsort/test_expectations.yml +1 -63
  53. data/steep.gemspec +1 -1
  54. metadata +13 -10
  55. data/lib/steep/drivers/trace_printer.rb +0 -29
  56. data/lib/steep/interface/method.rb +0 -78
  57. data/lib/steep/subtyping/trace.rb +0 -71
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcd473b07b749d136220c73d4434747c909fc516b5d14332590a5e46abed65f9
4
- data.tar.gz: c652c1608f635556d3c6704746c901b97047b5f2fc670ea563f50aa30d198210
3
+ metadata.gz: '0273968ec727f3b7c5c1007f9e27966c50ad7bc3128217a4ef30be4f97321037'
4
+ data.tar.gz: 195eb670673894e36af5e00ef911654f2a543c71e8de1d46c15e23035bef19c8
5
5
  SHA512:
6
- metadata.gz: 9a540a74cb3d514500a5d57d7111ce45b16cafde7855aa182d0a6a188edf74d7203b17368cc275aa574aaa16f5a7f265eb0a95c1fa9c0a524e42fb78b67bffdc
7
- data.tar.gz: eac07db23cad1f7eeb697d4f27e4548c45174e23d7552e7bd4246494efb25d8a967c10d6f00c112a1b3070b1a86e0131a4e3f0b95af8bf66f65747ba4e57f16b
6
+ metadata.gz: '0908edc4a3221256f450c9fd945d7127bd9ece3fa0359b7da88be8cebea30f7c766e023b84527e89e8f0c7956752310a3b0e98343b8c4808bfde518a89284456'
7
+ data.tar.gz: 4004adb0d0e8f2e0cd2629cd7e0c2bd6513a3a48bbd96d1d77621bbe0979b73686ab9c8ad718e3243081fdf492ff9728b5bf6df8e7357e1b1cf810393dad264c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,29 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.49.0 (2022-03-08)
6
+
7
+ * Better typing for `#flat_map` ([\#504](https://github.com/soutaro/steep/pull/504))
8
+ * Support lambdas (`->`) with block ([\#503](https://github.com/soutaro/steep/pull/503))
9
+ * Let proc type be `::Proc` class instance ([\#502](https://github.com/soutaro/steep/pull/502))
10
+ * Disable contextual typing on `bool` type ([\#501](https://github.com/soutaro/steep/pull/501))
11
+ * Type check `return` without value ([\#500](https://github.com/soutaro/steep/pull/500))
12
+
13
+ ## 0.48.0 (2022-03-07)
14
+
15
+ Steep supports all of the new features of RBS 2. 🎉
16
+ It now requires RBS >= 2.2 and support all of the features.
17
+
18
+ * Update RBS ([\#495](https://github.com/soutaro/steep/pull/495))
19
+ * Support generic type aliases ([\#496](https://github.com/soutaro/steep/pull/496))
20
+ * Support bounded generics ([\#499](https://github.com/soutaro/steep/pull/499))
21
+
22
+ ## 0.47.1 (2022-02-17)
23
+
24
+ This update lets Steep run with Active Support 7.
25
+
26
+ * Fix ActiveSupport requirement in `lib/steep.rb` ([#484](https://github.com/soutaro/steep/pull/484))
27
+
5
28
  ## 0.47.0 (2021-11-30)
6
29
 
7
30
  This update contains update for RBS 1.7.
data/Gemfile CHANGED
@@ -7,6 +7,6 @@ gem "with_steep_types", path: "test/gems/with_steep_types"
7
7
  gem "without_steep_types", path: "test/gems/without_steep_types"
8
8
 
9
9
  gem "rake"
10
- gem "minitest", "~> 5.0"
10
+ gem "minitest", "~> 5.15"
11
11
  gem "minitest-hooks"
12
12
  gem "stackprof"
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- steep (0.47.0)
4
+ steep (0.49.0)
5
5
  activesupport (>= 5.1)
6
6
  language_server-protocol (>= 3.15, < 4.0)
7
7
  listen (~> 3.0)
8
8
  parallel (>= 1.0.0)
9
9
  parser (>= 3.0)
10
10
  rainbow (>= 2.2.2, < 4.0)
11
- rbs (~> 1.7.0)
11
+ rbs (>= 2.2.0)
12
12
  terminal-table (>= 2, < 4)
13
13
 
14
14
  PATH
@@ -24,46 +24,44 @@ PATH
24
24
  GEM
25
25
  remote: https://rubygems.org/
26
26
  specs:
27
- activesupport (6.1.4.1)
27
+ activesupport (7.0.2.2)
28
28
  concurrent-ruby (~> 1.0, >= 1.0.2)
29
29
  i18n (>= 1.6, < 2)
30
30
  minitest (>= 5.1)
31
31
  tzinfo (~> 2.0)
32
- zeitwerk (~> 2.3)
33
32
  ast (2.4.2)
34
33
  concurrent-ruby (1.1.9)
35
- ffi (1.15.4)
36
- i18n (1.8.11)
34
+ ffi (1.15.5)
35
+ i18n (1.10.0)
37
36
  concurrent-ruby (~> 1.0)
38
37
  language_server-protocol (3.16.0.3)
39
- listen (3.7.0)
38
+ listen (3.7.1)
40
39
  rb-fsevent (~> 0.10, >= 0.10.3)
41
40
  rb-inotify (~> 0.9, >= 0.9.10)
42
- minitest (5.14.4)
41
+ minitest (5.15.0)
43
42
  minitest-hooks (1.5.0)
44
43
  minitest (> 5.3)
45
44
  parallel (1.21.0)
46
- parser (3.0.3.1)
45
+ parser (3.1.1.0)
47
46
  ast (~> 2.4.1)
48
- rainbow (3.0.0)
47
+ rainbow (3.1.1)
49
48
  rake (13.0.6)
50
- rb-fsevent (0.11.0)
49
+ rb-fsevent (0.11.1)
51
50
  rb-inotify (0.10.1)
52
51
  ffi (~> 1.0)
53
- rbs (1.7.1)
54
- stackprof (0.2.17)
52
+ rbs (2.2.2)
53
+ stackprof (0.2.19)
55
54
  terminal-table (3.0.2)
56
55
  unicode-display_width (>= 1.1.1, < 3)
57
56
  tzinfo (2.0.4)
58
57
  concurrent-ruby (~> 1.0)
59
58
  unicode-display_width (2.1.0)
60
- zeitwerk (2.5.1)
61
59
 
62
60
  PLATFORMS
63
61
  ruby
64
62
 
65
63
  DEPENDENCIES
66
- minitest (~> 5.0)
64
+ minitest (~> 5.15)
67
65
  minitest-hooks
68
66
  rake
69
67
  stackprof
@@ -72,4 +70,4 @@ DEPENDENCIES
72
70
  without_steep_types!
73
71
 
74
72
  BUNDLED WITH
75
- 2.2.27
73
+ 2.3.8
@@ -28,6 +28,8 @@ module Steep
28
28
 
29
29
  include Helper::NoFreeVariables
30
30
 
31
+ include Helper::NoChild
32
+
31
33
  def level
32
34
  [1]
33
35
  end
@@ -28,6 +28,8 @@ module Steep
28
28
 
29
29
  include Helper::NoFreeVariables
30
30
 
31
+ include Helper::NoChild
32
+
31
33
  def level
32
34
  [0]
33
35
  end
@@ -28,6 +28,8 @@ module Steep
28
28
 
29
29
  include Helper::NoFreeVariables
30
30
 
31
+ include Helper::NoChild
32
+
31
33
  def level
32
34
  [2]
33
35
  end
@@ -30,6 +30,8 @@ module Steep
30
30
  @fvs = Set.new([self])
31
31
  end
32
32
 
33
+ include Helper::NoChild
34
+
33
35
  def level
34
36
  [0]
35
37
  end
@@ -21,143 +21,154 @@ module Steep
21
21
  @type_name_resolver ||= RBS::TypeNameResolver.from_env(definition_builder.env)
22
22
  end
23
23
 
24
+ def type_opt(type)
25
+ if type
26
+ type(type)
27
+ end
28
+ end
29
+
24
30
  def type(type)
25
31
  ty = type_cache[type] and return ty
26
32
 
27
- type_cache[type] = case type
28
- when RBS::Types::Bases::Any
29
- Any.new(location: nil)
30
- when RBS::Types::Bases::Class
31
- Class.new(location: nil)
32
- when RBS::Types::Bases::Instance
33
- Instance.new(location: nil)
34
- when RBS::Types::Bases::Self
35
- Self.new(location: nil)
36
- when RBS::Types::Bases::Top
37
- Top.new(location: nil)
38
- when RBS::Types::Bases::Bottom
39
- Bot.new(location: nil)
40
- when RBS::Types::Bases::Bool
41
- Boolean.new(location: nil)
42
- when RBS::Types::Bases::Void
43
- Void.new(location: nil)
44
- when RBS::Types::Bases::Nil
45
- Nil.new(location: nil)
46
- when RBS::Types::Variable
47
- Var.new(name: type.name, location: nil)
48
- when RBS::Types::ClassSingleton
49
- type_name = type.name
50
- Name::Singleton.new(name: type_name, location: nil)
51
- when RBS::Types::ClassInstance
52
- type_name = type.name
53
- args = type.args.map {|arg| type(arg) }
54
- Name::Instance.new(name: type_name, args: args, location: nil)
55
- when RBS::Types::Interface
56
- type_name = type.name
57
- args = type.args.map {|arg| type(arg) }
58
- Name::Interface.new(name: type_name, args: args, location: nil)
59
- when RBS::Types::Alias
60
- type_name = type.name
61
- Name::Alias.new(name: type_name, args: [], location: nil)
62
- when RBS::Types::Union
63
- Union.build(types: type.types.map {|ty| type(ty) }, location: nil)
64
- when RBS::Types::Intersection
65
- Intersection.build(types: type.types.map {|ty| type(ty) }, location: nil)
66
- when RBS::Types::Optional
67
- Union.build(types: [type(type.type), Nil.new(location: nil)], location: nil)
68
- when RBS::Types::Literal
69
- Literal.new(value: type.literal, location: nil)
70
- when RBS::Types::Tuple
71
- Tuple.new(types: type.types.map {|ty| type(ty) }, location: nil)
72
- when RBS::Types::Record
73
- elements = type.fields.each.with_object({}) do |(key, value), hash|
74
- hash[key] = type(value)
75
- end
76
- Record.new(elements: elements, location: nil)
77
- when RBS::Types::Proc
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
33
+ type_cache[type] =
34
+ case type
35
+ when RBS::Types::Bases::Any
36
+ Any.new(location: type.location)
37
+ when RBS::Types::Bases::Class
38
+ Class.new(location: type.location)
39
+ when RBS::Types::Bases::Instance
40
+ Instance.new(location: type.location)
41
+ when RBS::Types::Bases::Self
42
+ Self.new(location: type.location)
43
+ when RBS::Types::Bases::Top
44
+ Top.new(location: type.location)
45
+ when RBS::Types::Bases::Bottom
46
+ Bot.new(location: type.location)
47
+ when RBS::Types::Bases::Bool
48
+ Boolean.new(location: type.location)
49
+ when RBS::Types::Bases::Void
50
+ Void.new(location: type.location)
51
+ when RBS::Types::Bases::Nil
52
+ Nil.new(location: type.location)
53
+ when RBS::Types::Variable
54
+ Var.new(name: type.name, location: type.location)
55
+ when RBS::Types::ClassSingleton
56
+ type_name = type.name
57
+ Name::Singleton.new(name: type_name, location: type.location)
58
+ when RBS::Types::ClassInstance
59
+ type_name = type.name
60
+ args = type.args.map {|arg| type(arg) }
61
+ Name::Instance.new(name: type_name, args: args, location: type.location)
62
+ when RBS::Types::Interface
63
+ type_name = type.name
64
+ args = type.args.map {|arg| type(arg) }
65
+ Name::Interface.new(name: type_name, args: args, location: type.location)
66
+ when RBS::Types::Alias
67
+ type_name = type.name
68
+ args = type.args.map {|arg| type(arg) }
69
+ Name::Alias.new(name: type_name, args: args, location: type.location)
70
+ when RBS::Types::Union
71
+ Union.build(types: type.types.map {|ty| type(ty) }, location: type.location)
72
+ when RBS::Types::Intersection
73
+ Intersection.build(types: type.types.map {|ty| type(ty) }, location: type.location)
74
+ when RBS::Types::Optional
75
+ Union.build(types: [type(type.type), Nil.new(location: nil)], location: type.location)
76
+ when RBS::Types::Literal
77
+ Literal.new(value: type.literal, location: type.location)
78
+ when RBS::Types::Tuple
79
+ Tuple.new(types: type.types.map {|ty| type(ty) }, location: type.location)
80
+ when RBS::Types::Record
81
+ elements = type.fields.each.with_object({}) do |(key, value), hash|
82
+ hash[key] = type(value)
83
+ end
84
+ Record.new(elements: elements, location: type.location)
85
+ when RBS::Types::Proc
86
+ func = Interface::Function.new(
87
+ params: params(type.type),
88
+ return_type: type(type.type.return_type),
89
+ location: type.location
90
+ )
91
+ block = if type.block
92
+ Interface::Block.new(
93
+ type: Interface::Function.new(
94
+ params: params(type.block.type),
95
+ return_type: type(type.block.type.return_type),
96
+ location: type.location
97
+ ),
98
+ optional: !type.block.required
99
+ )
100
+ end
93
101
 
94
- Proc.new(type: func, block: block)
95
- else
96
- raise "Unexpected type given: #{type}"
97
- end
102
+ Proc.new(type: func, block: block)
103
+ else
104
+ raise "Unexpected type given: #{type}"
105
+ end
98
106
  end
99
107
 
100
108
  def type_1(type)
101
109
  case type
102
110
  when Any
103
- RBS::Types::Bases::Any.new(location: nil)
111
+ RBS::Types::Bases::Any.new(location: type.location)
104
112
  when Class
105
- RBS::Types::Bases::Class.new(location: nil)
113
+ RBS::Types::Bases::Class.new(location: type.location)
106
114
  when Instance
107
- RBS::Types::Bases::Instance.new(location: nil)
115
+ RBS::Types::Bases::Instance.new(location: type.location)
108
116
  when Self
109
- RBS::Types::Bases::Self.new(location: nil)
117
+ RBS::Types::Bases::Self.new(location: type.location)
110
118
  when Top
111
- RBS::Types::Bases::Top.new(location: nil)
119
+ RBS::Types::Bases::Top.new(location: type.location)
112
120
  when Bot
113
- RBS::Types::Bases::Bottom.new(location: nil)
121
+ RBS::Types::Bases::Bottom.new(location: type.location)
114
122
  when Boolean
115
- RBS::Types::Bases::Bool.new(location: nil)
123
+ RBS::Types::Bases::Bool.new(location: type.location)
116
124
  when Void
117
- RBS::Types::Bases::Void.new(location: nil)
125
+ RBS::Types::Bases::Void.new(location: type.location)
118
126
  when Nil
119
- RBS::Types::Bases::Nil.new(location: nil)
127
+ RBS::Types::Bases::Nil.new(location: type.location)
120
128
  when Var
121
- RBS::Types::Variable.new(name: type.name, location: nil)
129
+ RBS::Types::Variable.new(name: type.name, location: type.location)
122
130
  when Name::Singleton
123
- RBS::Types::ClassSingleton.new(name: type.name, location: nil)
131
+ RBS::Types::ClassSingleton.new(name: type.name, location: type.location)
124
132
  when Name::Instance
125
133
  RBS::Types::ClassInstance.new(
126
134
  name: type.name,
127
135
  args: type.args.map {|arg| type_1(arg) },
128
- location: nil
136
+ location: type.location
129
137
  )
130
138
  when Name::Interface
131
139
  RBS::Types::Interface.new(
132
140
  name: type.name,
133
141
  args: type.args.map {|arg| type_1(arg) },
134
- location: nil
142
+ location: type.location
135
143
  )
136
144
  when Name::Alias
137
- type.args.empty? or raise "alias type with args is not supported"
138
- RBS::Types::Alias.new(name: type.name, location: nil)
145
+ RBS::Types::Alias.new(
146
+ name: type.name,
147
+ args: type.args.map {|arg| type_1(arg) },
148
+ location: type.location
149
+ )
139
150
  when Union
140
151
  RBS::Types::Union.new(
141
152
  types: type.types.map {|ty| type_1(ty) },
142
- location: nil
153
+ location: type.location
143
154
  )
144
155
  when Intersection
145
156
  RBS::Types::Intersection.new(
146
157
  types: type.types.map {|ty| type_1(ty) },
147
- location: nil
158
+ location: type.location
148
159
  )
149
160
  when Literal
150
- RBS::Types::Literal.new(literal: type.value, location: nil)
161
+ RBS::Types::Literal.new(literal: type.value, location: type.location)
151
162
  when Tuple
152
163
  RBS::Types::Tuple.new(
153
164
  types: type.types.map {|ty| type_1(ty) },
154
- location: nil
165
+ location: type.location
155
166
  )
156
167
  when Record
157
168
  fields = type.elements.each.with_object({}) do |(key, value), hash|
158
169
  hash[key] = type_1(value)
159
170
  end
160
- RBS::Types::Record.new(fields: fields, location: nil)
171
+ RBS::Types::Record.new(fields: fields, location: type.location)
161
172
  when Proc
162
173
  block = if type.block
163
174
  RBS::Types::Block.new(
@@ -168,10 +179,10 @@ module Steep
168
179
  RBS::Types::Proc.new(
169
180
  type: function_1(type.type),
170
181
  block: block,
171
- location: nil
182
+ location: type.location
172
183
  )
173
184
  when Logic::Base
174
- RBS::Types::Bases::Bool.new(location: nil)
185
+ RBS::Types::Bases::Bool.new(location: type.location)
175
186
  else
176
187
  raise "Unexpected type given: #{type} (#{type.class})"
177
188
  end
@@ -204,45 +215,61 @@ module Steep
204
215
  )
205
216
  end
206
217
 
218
+ def type_param(type_param)
219
+ Interface::TypeParam.new(
220
+ name: type_param.name,
221
+ upper_bound: type_param.upper_bound&.yield_self {|u| type(u) },
222
+ variance: type_param.variance,
223
+ unchecked: type_param.unchecked?
224
+ )
225
+ end
226
+
227
+ def type_param_1(type_param)
228
+ RBS::AST::TypeParam.new(
229
+ name: type_param.name,
230
+ variance: type_param.variance,
231
+ upper_bound: type_param.upper_bound&.yield_self {|u| type_1(u) },
232
+ location: type_param.location
233
+ ).unchecked!(type_param.unchecked)
234
+ end
235
+
207
236
  def method_type(method_type, self_type:, subst2: nil, method_decls:)
208
237
  fvs = self_type.free_variables()
209
238
 
210
239
  type_params = []
211
- alpha_vars = []
212
- alpha_types = []
240
+ conflicting_names = []
213
241
 
214
- method_type.type_params.map do |name|
215
- if fvs.include?(name)
216
- type = Types::Var.fresh(name)
217
- alpha_vars << name
218
- alpha_types << type
219
- type_params << type.name
220
- else
221
- type_params << name
242
+ type_params = method_type.type_params.map do |type_param|
243
+ if fvs.include?(type_param.name)
244
+ conflicting_names << type_param.name
222
245
  end
246
+
247
+ type_param(type_param)
223
248
  end
224
- subst = Interface::Substitution.build(alpha_vars, alpha_types)
249
+
250
+ type_params, subst = Interface::TypeParam.rename(type_params, conflicting_names)
225
251
  subst.merge!(subst2, overwrite: true) if subst2
226
252
 
227
- type = Interface::MethodType.new(
228
- type_params: type_params,
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
- ),
234
- block: method_type.block&.yield_self do |block|
235
- Interface::Block.new(
236
- optional: !block.required,
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
253
+ type =
254
+ Interface::MethodType.new(
255
+ type_params: type_params,
256
+ type: Interface::Function.new(
257
+ params: params(method_type.type).subst(subst),
258
+ return_type: type(method_type.type.return_type).subst(subst),
259
+ location: method_type.location
260
+ ),
261
+ block: method_type.block&.yield_self do |block|
262
+ Interface::Block.new(
263
+ optional: !block.required,
264
+ type: Interface::Function.new(
265
+ params: params(block.type).subst(subst),
266
+ return_type: type(block.type.return_type).subst(subst),
267
+ location: nil
268
+ )
241
269
  )
242
- )
243
- end,
244
- method_decls: method_decls
245
- )
270
+ end,
271
+ method_decls: method_decls
272
+ )
246
273
 
247
274
  if block_given?
248
275
  yield type
@@ -258,20 +285,14 @@ module Steep
258
285
  alpha_vars = []
259
286
  alpha_types = []
260
287
 
261
- method_type.type_params.map do |name|
262
- if fvs.include?(name)
263
- type = RBS::Types::Variable.new(name: name, location: nil),
264
- alpha_vars << name
265
- alpha_types << type
266
- type_params << type.name
267
- else
268
- type_params << name
269
- end
288
+ conflicting_names = method_type.type_params.each.with_object([]) do |param, names|
289
+ names << params.name if fvs.include?(param.name)
270
290
  end
271
- subst = Interface::Substitution.build(alpha_vars, alpha_types)
291
+
292
+ type_params, subst = Interface::TypeParam.rename(method_type.type_params, conflicting_names)
272
293
 
273
294
  type = RBS::MethodType.new(
274
- type_params: type_params,
295
+ type_params: type_params.map {|param| type_param_1(param) },
275
296
  type: function_1(method_type.type.subst(subst)),
276
297
  block: method_type.block&.yield_self do |block|
277
298
  block_type = block.type.subst(subst)
@@ -300,16 +321,19 @@ module Steep
300
321
  end
301
322
  end
302
323
 
303
- def unfold(type_name)
304
- type_name.yield_self do |type_name|
305
- type(definition_builder.expand_alias(type_name))
306
- end
324
+ def unfold(type_name, args)
325
+ type(
326
+ definition_builder.expand_alias2(
327
+ type_name,
328
+ args.empty? ? args : args.map {|t| type_1(t) }
329
+ )
330
+ )
307
331
  end
308
332
 
309
333
  def expand_alias(type)
310
334
  unfolded = case type
311
335
  when AST::Types::Name::Alias
312
- unfold(type.name)
336
+ unfold(type.name, type.args)
313
337
  else
314
338
  type
315
339
  end
@@ -369,7 +393,7 @@ module Steep
369
393
  when AST::Types::Name::Alias
370
394
  unwrap_optional(expand_alias(type))
371
395
  when AST::Types::Boolean
372
- [AST::Builtin.true_type, AST::Builtin.false_type]
396
+ [type, type]
373
397
  else
374
398
  [type, nil]
375
399
  end
@@ -21,6 +21,14 @@ module Steep
21
21
  @fvs ||= Set.new
22
22
  end
23
23
  end
24
+
25
+ module NoChild
26
+ def each_child(&block)
27
+ unless block
28
+ enum_for :each_child
29
+ end
30
+ end
31
+ end
24
32
  end
25
33
  end
26
34
  end
@@ -26,6 +26,8 @@ module Steep
26
26
  @fvs = Set.new([self])
27
27
  end
28
28
 
29
+ include Helper::NoChild
30
+
29
31
  def to_s
30
32
  "instance"
31
33
  end
@@ -72,6 +72,10 @@ module Steep
72
72
 
73
73
  include Helper::ChildrenLevel
74
74
 
75
+ def each_child(&block)
76
+ types.each(&block)
77
+ end
78
+
75
79
  def level
76
80
  [0] + level_of_children(types)
77
81
  end
@@ -31,6 +31,8 @@ module Steep
31
31
 
32
32
  include Helper::NoFreeVariables
33
33
 
34
+ include Helper::NoChild
35
+
34
36
  def level
35
37
  [0]
36
38
  end
@@ -13,6 +13,8 @@ module Steep
13
13
  @fvs ||= Set[]
14
14
  end
15
15
 
16
+ include Helper::NoChild
17
+
16
18
  def hash
17
19
  self.class.hash
18
20
  end
@@ -72,6 +72,10 @@ module Steep
72
72
  end
73
73
  end
74
74
 
75
+ def each_child(&block)
76
+ args.each(&block)
77
+ end
78
+
75
79
  include Helper::ChildrenLevel
76
80
 
77
81
  def level
@@ -98,6 +102,8 @@ module Steep
98
102
  def with_location(new_location)
99
103
  self.class.new(name: name, location: new_location)
100
104
  end
105
+
106
+ include Helper::NoChild
101
107
  end
102
108
 
103
109
  class Instance < Applying