steep 0.20.0 → 0.21.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 566e77aa4db03cb06ae80569f4db9f5409e65199b1af4af9fc6f2598e911f694
4
- data.tar.gz: 41f1d54c5196fdec7cc58751899aec208066d845eef717234bb37266313c7d8d
3
+ metadata.gz: 6109c6ce90265363be0ef33fe06e517577f3e884a6fc20c921f5d716c4916de1
4
+ data.tar.gz: 1bcba16bfab23e534eb40b7302dd21e43b487ba6441a02d0da403ac4df54d788
5
5
  SHA512:
6
- metadata.gz: 46366ed11a6328a6a237c52042ef49eb12d5ce3db111fb55c5038109b62aa471ba6634c8c060575f6862658dcc0f388684a083f9a691becd6d90f076acb05908
7
- data.tar.gz: 9cb15861e6de6b5209dd82745f1c7cf67c212e3e15cc9c1f92956b84089801f994c7c1cd79ff8972f37da229530e7354d237ce4a74ce844083daf656936286dc
6
+ metadata.gz: b8bffda05cd158a3ce849fca2722fcb0d62de0d6307a88d4fa0d3758a7965aef706bccab3b4a634a3343e2c0bbd1cc87bec8e5f5b31cfa52e19a6d3f2931b5eb
7
+ data.tar.gz: 57cb080c69a71fb31f52bd4e65e37ca1719f46718b02632d2c5af3ff72c8b34eba56f098831558fd7df18afbdec0fd6802d0fbb326c5cb4086c147ba11b5447f
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.21.0 (2020-07-20)
6
+
7
+ * Fix LSP hover ([#168](https://github.com/soutaro/steep/pull/168))
8
+ * Nominal subtyping ([#167](https://github.com/soutaro/steep/pull/167))
9
+
5
10
  ## 0.20.0 (2020-07-17)
6
11
 
7
12
  * Support singleton class definitions ([#166](https://github.com/soutaro/steep/pull/166))
@@ -95,8 +95,8 @@ module Steep
95
95
  ```
96
96
  HOVER
97
97
  if content.definition
98
- if content.definition.comment
99
- string << "\n----\n\n#{content.definition.comment.string}"
98
+ if content.definition.comments
99
+ string << "\n----\n\n#{content.definition.comments.map(&:string).join("\n\n")}"
100
100
  end
101
101
 
102
102
  string << "\n----\n\n#{content.definition.method_types.map {|x| "- `#{x}`\n" }.join()}"
@@ -111,7 +111,7 @@ def #{content.method_name}: #{content.method_type}
111
111
  ```
112
112
  HOVER
113
113
  if (comment = content.comment_string)
114
- string << "\n----\n\n#{comment.string}\n"
114
+ string << "\n----\n\n#{comment}\n"
115
115
  end
116
116
 
117
117
  if content.definition.method_types.size > 1
@@ -9,6 +9,84 @@ module Steep
9
9
  @cache = {}
10
10
  end
11
11
 
12
+ def instance_super_types(type_name, args:)
13
+ type_name_1 = factory.type_name_1(type_name)
14
+ ancestors = factory.definition_builder.one_instance_ancestors(type_name_1)
15
+
16
+ subst = unless args.empty?
17
+ args_ = args.map {|type| factory.type_1(type) }
18
+ RBS::Substitution.build(ancestors.params, args_)
19
+ end
20
+
21
+ ancestors.each_ancestor.map do |ancestor|
22
+ name = factory.type_name(ancestor.name)
23
+
24
+ case ancestor
25
+ when RBS::Definition::Ancestor::Instance
26
+ args = ancestor.args.map do |type|
27
+ type = type.sub(subst) if subst
28
+ factory.type(type)
29
+ end
30
+
31
+ if ancestor.name.class?
32
+ AST::Types::Name::Instance.new(
33
+ name: name,
34
+ args: args,
35
+ location: nil
36
+ )
37
+ else
38
+ AST::Types::Name::Interface.new(
39
+ name: name,
40
+ args: args,
41
+ location: nil
42
+ )
43
+ end
44
+ when RBS::Definition::Ancestor::Singleton
45
+ AST::Types::Name::Class.new(
46
+ name: name,
47
+ constructor: nil,
48
+ location: nil
49
+ )
50
+ end
51
+ end
52
+ end
53
+
54
+ def singleton_super_types(type_name)
55
+ type_name_1 = factory.type_name_1(type_name)
56
+ ancestors = factory.definition_builder.one_singleton_ancestors(type_name_1)
57
+
58
+ ancestors.each_ancestor.map do |ancestor|
59
+ name = factory.type_name(ancestor.name)
60
+
61
+ case ancestor
62
+ when RBS::Definition::Ancestor::Instance
63
+ args = ancestor.args.map do |type|
64
+ factory.type(type)
65
+ end
66
+
67
+ if ancestor.name.class?
68
+ AST::Types::Name::Instance.new(
69
+ name: name,
70
+ args: args,
71
+ location: nil
72
+ )
73
+ else
74
+ AST::Types::Name::Interface.new(
75
+ name: name,
76
+ args: args,
77
+ location: nil
78
+ )
79
+ end
80
+ when RBS::Definition::Ancestor::Singleton
81
+ AST::Types::Name::Class.new(
82
+ name: name,
83
+ constructor: nil,
84
+ location: nil
85
+ )
86
+ end
87
+ end
88
+ end
89
+
12
90
  def check(relation, constraints:, self_type:, assumption: Set.new, trace: Trace.new)
13
91
  Steep.logger.tagged "#{relation.sub_type} <: #{relation.super_type}" do
14
92
  prefix = trace.size
@@ -175,30 +253,45 @@ module Steep
175
253
  failure(error: Result::Failure::UnknownPairError.new(relation: relation),
176
254
  trace: trace)
177
255
 
178
- when relation.sub_type.is_a?(AST::Types::Name::Base) && relation.super_type.is_a?(AST::Types::Name::Base)
179
- if (pairs = extract_nominal_pairs(relation))
180
- results = pairs.flat_map do |(sub, sup)|
181
- Relation.new(sub_type: sub, super_type: sup).yield_self do |rel|
182
- [rel, rel.flip]
183
- end
184
- end.map do |relation|
185
- check(relation,
186
- self_type: self_type,
187
- assumption: assumption,
188
- trace: trace,
189
- constraints: constraints)
190
- end
256
+ when relation.super_type.is_a?(AST::Types::Name::Interface)
257
+ sub_interface = factory.interface(relation.sub_type, private: false)
258
+ super_interface = factory.interface(relation.super_type, private: false)
191
259
 
192
- if results.all?(&:success?)
193
- results.first
260
+ check_interface(sub_interface,
261
+ super_interface,
262
+ self_type: self_type,
263
+ assumption: assumption,
264
+ trace: trace,
265
+ constraints: constraints)
266
+
267
+ when relation.sub_type.is_a?(AST::Types::Name::Base) && relation.super_type.is_a?(AST::Types::Name::Base)
268
+ if relation.sub_type.name == relation.super_type.name && relation.sub_type.class == relation.super_type.class
269
+ if arg_type?(relation.sub_type) && arg_type?(relation.super_type)
270
+ check_type_arg(relation, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
194
271
  else
195
- results.find(&:failure?)
272
+ success(constraints: constraints)
196
273
  end
197
274
  else
198
- sub_interface = factory.interface(relation.sub_type, private: false)
199
- super_interface = factory.interface(relation.super_type, private: false)
200
-
201
- check_interface(sub_interface, super_interface, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
275
+ possible_sub_types = case relation.sub_type
276
+ when AST::Types::Name::Instance
277
+ instance_super_types(relation.sub_type.name, args: relation.sub_type.args)
278
+ when AST::Types::Name::Class
279
+ singleton_super_types(relation.sub_type.name)
280
+ else
281
+ []
282
+ end
283
+
284
+ unless possible_sub_types.empty?
285
+ success_any?(possible_sub_types) do |sub_type|
286
+ check(Relation.new(sub_type: sub_type, super_type: relation.super_type),
287
+ self_type: self_type,
288
+ assumption: assumption,
289
+ trace: trace,
290
+ constraints: constraints)
291
+ end
292
+ else
293
+ failure(error: Result::Failure::UnknownPairError.new(relation: relation), trace: trace)
294
+ end
202
295
  end
203
296
 
204
297
  when relation.sub_type.is_a?(AST::Types::Proc) && relation.super_type.is_a?(AST::Types::Proc)
@@ -283,6 +376,80 @@ module Steep
283
376
  end
284
377
  end
285
378
 
379
+ def definition_for_type(type)
380
+ type_name = factory.type_name_1(type.name)
381
+
382
+ case type
383
+ when AST::Types::Name::Instance
384
+ factory.definition_builder.build_instance(type_name)
385
+ when AST::Types::Name::Class
386
+ factory.definition_builder.build_singleton(type_name)
387
+ when AST::Types::Name::Interface
388
+ factory.definition_builder.build_interface(type_name)
389
+ else
390
+ raise
391
+ end
392
+ end
393
+
394
+ def arg_type?(type)
395
+ case type
396
+ when AST::Types::Name::Instance, AST::Types::Name::Interface
397
+ type.args.size > 0
398
+ else
399
+ false
400
+ end
401
+ end
402
+
403
+ def check_type_arg(relation, self_type:, assumption:, trace:, constraints:)
404
+ sub_args = relation.sub_type.args
405
+ sup_args = relation.super_type.args
406
+
407
+ sup_def = definition_for_type(relation.super_type)
408
+ sup_params = sup_def.type_params_decl
409
+
410
+ success_all?(sub_args.zip(sup_args, sup_params.each)) do |sub_arg, sup_arg, sup_param|
411
+ case sup_param.variance
412
+ when :covariant
413
+ check(Relation.new(sub_type: sub_arg, super_type: sup_arg), self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
414
+ when :contravariant
415
+ check(Relation.new(sub_type: sup_arg, super_type: sub_arg), self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
416
+ when :invariant
417
+ rel = Relation.new(sub_type: sub_arg, super_type: sup_arg)
418
+ success_all?([rel, rel.flip]) do |r|
419
+ check(r, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
420
+ end
421
+ end
422
+ end
423
+ end
424
+
425
+ def success_all?(collection, &block)
426
+ results = collection.map do |obj|
427
+ result = yield(obj)
428
+
429
+ if result.failure?
430
+ return result
431
+ end
432
+
433
+ result
434
+ end
435
+
436
+ results[0]
437
+ end
438
+
439
+ def success_any?(collection, &block)
440
+ results = collection.map do |obj|
441
+ result = yield(obj)
442
+
443
+ if result.success?
444
+ return result
445
+ end
446
+
447
+ result
448
+ end
449
+
450
+ results[0]
451
+ end
452
+
286
453
  def extract_nominal_pairs(relation)
287
454
  sub_type = relation.sub_type
288
455
  super_type = relation.super_type
@@ -316,20 +483,7 @@ module Steep
316
483
  return true
317
484
  end
318
485
 
319
- case
320
- when relation.sub_type == relation.super_type
321
- true
322
- when relation.sub_type.is_a?(AST::Types::Name::Base) && relation.super_type.is_a?(AST::Types::Name::Base)
323
- if (pairs = extract_nominal_pairs(relation))
324
- pairs.all? do |(s, t)|
325
- same_type?(Relation.new(sub_type: s, super_type: t), assumption: assumption)
326
- end
327
- else
328
- false
329
- end
330
- else
331
- false
332
- end
486
+ relation.sub_type == relation.super_type
333
487
  end
334
488
 
335
489
  def check_interface(sub_interface, super_interface, self_type:, assumption:, trace:, constraints:)
@@ -1,3 +1,3 @@
1
1
  module Steep
2
- VERSION = "0.20.0"
2
+ VERSION = "0.21.0"
3
3
  end
@@ -18,7 +18,6 @@ class D
18
18
  def foo: -> untyped
19
19
  end
20
20
 
21
- class E
22
- def initialize: () -> untyped
21
+ interface _E
23
22
  def foo: -> untyped
24
23
  end
@@ -1,8 +1,10 @@
1
- # @type var e: E
1
+ # @type var e: _E
2
2
  # @type var d: D
3
3
 
4
4
  e = (_ = nil)
5
5
  d = (_ = nil)
6
6
 
7
7
  e = d
8
+
9
+ # !expects IncompatibleAssignment: lhs_type=::D, rhs_type=::_E
8
10
  d = e
@@ -41,5 +41,5 @@ Gem::Specification.new do |spec|
41
41
  spec.add_runtime_dependency "rainbow", ">= 2.2.2", "< 4.0"
42
42
  spec.add_runtime_dependency "listen", "~> 3.1"
43
43
  spec.add_runtime_dependency "language_server-protocol", "~> 3.14.0.2"
44
- spec.add_runtime_dependency "rbs", ">= 0.6.0", '< 0.7.0'
44
+ spec.add_runtime_dependency "rbs", "~> 0.7.0"
45
45
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 0.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-17 00:00:00.000000000 Z
11
+ date: 2020-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -188,20 +188,14 @@ dependencies:
188
188
  name: rbs
189
189
  requirement: !ruby/object:Gem::Requirement
190
190
  requirements:
191
- - - ">="
192
- - !ruby/object:Gem::Version
193
- version: 0.6.0
194
- - - "<"
191
+ - - "~>"
195
192
  - !ruby/object:Gem::Version
196
193
  version: 0.7.0
197
194
  type: :runtime
198
195
  prerelease: false
199
196
  version_requirements: !ruby/object:Gem::Requirement
200
197
  requirements:
201
- - - ">="
202
- - !ruby/object:Gem::Version
203
- version: 0.6.0
204
- - - "<"
198
+ - - "~>"
205
199
  - !ruby/object:Gem::Version
206
200
  version: 0.7.0
207
201
  description: Gradual Typing for Ruby