steep 0.38.0 → 0.39.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 +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/steep/ast/types/bot.rb +1 -1
- data/lib/steep/ast/types/factory.rb +10 -0
- data/lib/steep/ast/types/logic.rb +16 -3
- data/lib/steep/ast/types/top.rb +1 -1
- data/lib/steep/errors.rb +49 -39
- data/lib/steep/project/target.rb +2 -2
- data/lib/steep/signature/errors.rb +51 -5
- data/lib/steep/signature/validator.rb +28 -4
- data/lib/steep/subtyping/check.rb +2 -2
- data/lib/steep/type_construction.rb +63 -30
- data/lib/steep/type_inference/logic_type_interpreter.rb +99 -26
- data/lib/steep/version.rb +1 -1
- data/smoke/type_case/a.rb +1 -1
- data/steep.gemspec +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 33c89b6005654ebdc947af336b1c7fa47e02c45c480d27b9f4ef0ab6d3403dd1
|
|
4
|
+
data.tar.gz: be7b7812e1ba321b91680884fccc55fd57dd5836c89bf7817624b72706490d6e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 36945eb5fe4a04061c87bc76488c65ef2b009fcdb8279fd542a1249a10a223cd9571371f333e4ec29870a66dd120c4d9e65d572a9d3c90d56dba5c2c1dd95761
|
|
7
|
+
data.tar.gz: d9c2e56878f06d71edeb9a10b275c19afd7ba42b1af16ef01ef890ca3791ad4f92f903f7679fcf77b310638b0d0f5fced596e094ec225ff2f567e0f063bfc527
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
## master
|
|
4
4
|
|
|
5
|
+
## 0.39.0 (2020-12-25)
|
|
6
|
+
|
|
7
|
+
* Update RBS to 1.0.0 ([#282](https://github.com/soutaro/steep/pull/282))
|
|
8
|
+
* Better `&&` and `||` typing ([#276](https://github.com/soutaro/steep/pull/276))
|
|
9
|
+
* Type case based on literals ([#277](https://github.com/soutaro/steep/pull/277))
|
|
10
|
+
* Type case improvements ([#279](https://github.com/soutaro/steep/pull/279), [#283](https://github.com/soutaro/steep/pull/283))
|
|
11
|
+
* Improvements on untyped classes/modules, unsupported syntax error handling, and argument types in untyped methods ([#280](https://github.com/soutaro/steep/pull/280))
|
|
12
|
+
* Fix `bot` and `top` type format ([#278](https://github.com/soutaro/steep/pull/278))
|
|
13
|
+
* Colorfull error messages ([#273](https://github.com/soutaro/steep/pull/273))
|
|
14
|
+
|
|
5
15
|
## 0.38.0 (2020-12-10)
|
|
6
16
|
|
|
7
17
|
* Improve `break`/`next` typing ([#271](https://github.com/soutaro/steep/pull/271))
|
data/lib/steep/ast/types/bot.rb
CHANGED
|
@@ -368,6 +368,8 @@ module Steep
|
|
|
368
368
|
]
|
|
369
369
|
when AST::Types::Name::Alias
|
|
370
370
|
unwrap_optional(expand_alias(type))
|
|
371
|
+
when AST::Types::Boolean
|
|
372
|
+
[AST::Builtin.true_type, AST::Builtin.false_type]
|
|
371
373
|
else
|
|
372
374
|
[type, nil]
|
|
373
375
|
end
|
|
@@ -421,6 +423,14 @@ module Steep
|
|
|
421
423
|
return_type: AST::Types::Logic::ArgIsReceiver.new(location: method_type.type.return_type.location)
|
|
422
424
|
)
|
|
423
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
|
+
)
|
|
433
|
+
)
|
|
424
434
|
end
|
|
425
435
|
end
|
|
426
436
|
end
|
|
@@ -58,16 +58,23 @@ module Steep
|
|
|
58
58
|
end
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
+
class ArgEqualsReceiver < Base
|
|
62
|
+
def initialize(location: nil)
|
|
63
|
+
@location = location
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
61
67
|
class Env < Base
|
|
62
|
-
attr_reader :truthy, :falsy
|
|
68
|
+
attr_reader :truthy, :falsy, :type
|
|
63
69
|
|
|
64
|
-
def initialize(truthy:, falsy:, location: nil)
|
|
70
|
+
def initialize(truthy:, falsy:, type:, location: nil)
|
|
65
71
|
@truthy = truthy
|
|
66
72
|
@falsy = falsy
|
|
73
|
+
@type = type
|
|
67
74
|
end
|
|
68
75
|
|
|
69
76
|
def ==(other)
|
|
70
|
-
other.is_a?(Env) && other.truthy == truthy && other.falsy == falsy
|
|
77
|
+
other.is_a?(Env) && other.truthy == truthy && other.falsy == falsy && other.type == type
|
|
71
78
|
end
|
|
72
79
|
|
|
73
80
|
alias eql? ==
|
|
@@ -75,6 +82,12 @@ module Steep
|
|
|
75
82
|
def hash
|
|
76
83
|
self.class.hash ^ truthy.hash ^ falsy.hash
|
|
77
84
|
end
|
|
85
|
+
|
|
86
|
+
def inspect
|
|
87
|
+
"#<Steep::AST::Types::Env @type=#{type}, @truthy=..., @falsy=...>"
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
alias to_s inspect
|
|
78
91
|
end
|
|
79
92
|
end
|
|
80
93
|
end
|
data/lib/steep/ast/types/top.rb
CHANGED
data/lib/steep/errors.rb
CHANGED
|
@@ -8,7 +8,18 @@ module Steep
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def location_to_str
|
|
11
|
-
Rainbow(
|
|
11
|
+
file = Rainbow(node.loc.expression.source_buffer.name).cyan
|
|
12
|
+
line = Rainbow(node.loc.first_line).bright
|
|
13
|
+
column = Rainbow(node.loc.column).bright
|
|
14
|
+
"#{file}:#{line}:#{column}"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def format_message(message, class_name: self.class.name.split("::").last)
|
|
18
|
+
if message.empty?
|
|
19
|
+
"#{location_to_str}: #{Rainbow(class_name).red}"
|
|
20
|
+
else
|
|
21
|
+
"#{location_to_str}: #{Rainbow(class_name).red}: #{message}"
|
|
22
|
+
end
|
|
12
23
|
end
|
|
13
24
|
|
|
14
25
|
def print_to(io)
|
|
@@ -45,7 +56,7 @@ module Steep
|
|
|
45
56
|
end
|
|
46
57
|
|
|
47
58
|
def to_s
|
|
48
|
-
"
|
|
59
|
+
format_message "lhs_type=#{lhs_type}, rhs_type=#{rhs_type}"
|
|
49
60
|
end
|
|
50
61
|
end
|
|
51
62
|
|
|
@@ -61,7 +72,7 @@ module Steep
|
|
|
61
72
|
end
|
|
62
73
|
|
|
63
74
|
def to_s
|
|
64
|
-
"
|
|
75
|
+
format_message "receiver=#{receiver_type}, method_type=#{method_type}"
|
|
65
76
|
end
|
|
66
77
|
end
|
|
67
78
|
|
|
@@ -79,7 +90,7 @@ module Steep
|
|
|
79
90
|
end
|
|
80
91
|
|
|
81
92
|
def to_s
|
|
82
|
-
"
|
|
93
|
+
format_message "receiver=#{receiver_type}, method_name=#{method_name}, method_types=#{method_types.join(" | ")}"
|
|
83
94
|
end
|
|
84
95
|
end
|
|
85
96
|
|
|
@@ -97,7 +108,7 @@ module Steep
|
|
|
97
108
|
end
|
|
98
109
|
|
|
99
110
|
def to_s
|
|
100
|
-
"
|
|
111
|
+
format_message "receiver=#{receiver_type}, expected=#{expected}, actual=#{actual}"
|
|
101
112
|
end
|
|
102
113
|
end
|
|
103
114
|
|
|
@@ -112,7 +123,7 @@ module Steep
|
|
|
112
123
|
end
|
|
113
124
|
|
|
114
125
|
def to_s
|
|
115
|
-
"
|
|
126
|
+
format_message "expected=#{expected}, actual=#{actual}"
|
|
116
127
|
end
|
|
117
128
|
end
|
|
118
129
|
|
|
@@ -127,7 +138,7 @@ module Steep
|
|
|
127
138
|
end
|
|
128
139
|
|
|
129
140
|
def to_s
|
|
130
|
-
"
|
|
141
|
+
format_message "type=#{type}, method=#{method}", class_name: "NoMethodError"
|
|
131
142
|
end
|
|
132
143
|
end
|
|
133
144
|
|
|
@@ -146,7 +157,7 @@ module Steep
|
|
|
146
157
|
end
|
|
147
158
|
|
|
148
159
|
def to_s
|
|
149
|
-
"
|
|
160
|
+
format_message "expected=#{expected}, actual=#{actual}"
|
|
150
161
|
end
|
|
151
162
|
end
|
|
152
163
|
|
|
@@ -159,7 +170,7 @@ module Steep
|
|
|
159
170
|
end
|
|
160
171
|
|
|
161
172
|
def to_s
|
|
162
|
-
"
|
|
173
|
+
format_message "method_type=#{method_type}"
|
|
163
174
|
end
|
|
164
175
|
end
|
|
165
176
|
|
|
@@ -172,7 +183,7 @@ module Steep
|
|
|
172
183
|
end
|
|
173
184
|
|
|
174
185
|
def to_s
|
|
175
|
-
"
|
|
186
|
+
format_message "method_type=#{method_type}"
|
|
176
187
|
end
|
|
177
188
|
end
|
|
178
189
|
|
|
@@ -191,7 +202,7 @@ module Steep
|
|
|
191
202
|
end
|
|
192
203
|
|
|
193
204
|
def to_s
|
|
194
|
-
"
|
|
205
|
+
format_message "expected=#{expected}, actual=#{actual}"
|
|
195
206
|
end
|
|
196
207
|
end
|
|
197
208
|
|
|
@@ -210,7 +221,7 @@ module Steep
|
|
|
210
221
|
end
|
|
211
222
|
|
|
212
223
|
def to_s
|
|
213
|
-
"
|
|
224
|
+
format_message "expected=#{expected}, actual=#{actual}"
|
|
214
225
|
end
|
|
215
226
|
end
|
|
216
227
|
|
|
@@ -229,25 +240,25 @@ module Steep
|
|
|
229
240
|
end
|
|
230
241
|
|
|
231
242
|
def to_s
|
|
232
|
-
"
|
|
243
|
+
format_message "expected=#{expected}, actual=#{actual}"
|
|
233
244
|
end
|
|
234
245
|
end
|
|
235
246
|
|
|
236
247
|
class UnexpectedJump < Base
|
|
237
248
|
def to_s
|
|
238
|
-
|
|
249
|
+
format_message ""
|
|
239
250
|
end
|
|
240
251
|
end
|
|
241
252
|
|
|
242
253
|
class UnexpectedJumpValue < Base
|
|
243
254
|
def to_s
|
|
244
|
-
|
|
255
|
+
format_message ""
|
|
245
256
|
end
|
|
246
257
|
end
|
|
247
258
|
|
|
248
259
|
class MethodArityMismatch < Base
|
|
249
260
|
def to_s
|
|
250
|
-
"
|
|
261
|
+
format_message "method=#{node.children[0]}"
|
|
251
262
|
end
|
|
252
263
|
end
|
|
253
264
|
|
|
@@ -266,7 +277,7 @@ module Steep
|
|
|
266
277
|
end
|
|
267
278
|
|
|
268
279
|
def to_s
|
|
269
|
-
"
|
|
280
|
+
format_message "interface_method=#{interface_method.type_name}.#{interface_method.name}, annotation_method=#{annotation_method.name}"
|
|
270
281
|
end
|
|
271
282
|
end
|
|
272
283
|
|
|
@@ -279,7 +290,7 @@ module Steep
|
|
|
279
290
|
end
|
|
280
291
|
|
|
281
292
|
def to_s
|
|
282
|
-
"
|
|
293
|
+
format_message "method=#{method.name}, types=#{method.types.join(" | ")}"
|
|
283
294
|
end
|
|
284
295
|
end
|
|
285
296
|
|
|
@@ -298,7 +309,7 @@ module Steep
|
|
|
298
309
|
end
|
|
299
310
|
|
|
300
311
|
def to_s
|
|
301
|
-
"
|
|
312
|
+
format_message "method_type=#{method_type.return_type}, annotation_type=#{annotation_type}"
|
|
302
313
|
end
|
|
303
314
|
end
|
|
304
315
|
|
|
@@ -324,13 +335,13 @@ module Steep
|
|
|
324
335
|
prefix = node.children[0].type == :self ? "self" : "*"
|
|
325
336
|
"#{prefix}.#{node.children[1]}"
|
|
326
337
|
end
|
|
327
|
-
"
|
|
338
|
+
format_message "method=#{method}, expected=#{expected}, actual=#{actual}"
|
|
328
339
|
end
|
|
329
340
|
end
|
|
330
341
|
|
|
331
342
|
class UnexpectedYield < Base
|
|
332
343
|
def to_s
|
|
333
|
-
|
|
344
|
+
format_message ""
|
|
334
345
|
end
|
|
335
346
|
end
|
|
336
347
|
|
|
@@ -343,7 +354,7 @@ module Steep
|
|
|
343
354
|
end
|
|
344
355
|
|
|
345
356
|
def to_s
|
|
346
|
-
"
|
|
357
|
+
format_message "method=#{method}"
|
|
347
358
|
end
|
|
348
359
|
end
|
|
349
360
|
|
|
@@ -356,7 +367,7 @@ module Steep
|
|
|
356
367
|
end
|
|
357
368
|
|
|
358
369
|
def to_s
|
|
359
|
-
"
|
|
370
|
+
format_message "method=#{method}"
|
|
360
371
|
end
|
|
361
372
|
end
|
|
362
373
|
|
|
@@ -379,7 +390,7 @@ module Steep
|
|
|
379
390
|
when :module
|
|
380
391
|
"self.#{missing_method}"
|
|
381
392
|
end
|
|
382
|
-
"
|
|
393
|
+
format_message "module=#{module_name}, method=#{method}"
|
|
383
394
|
end
|
|
384
395
|
end
|
|
385
396
|
|
|
@@ -394,7 +405,7 @@ module Steep
|
|
|
394
405
|
end
|
|
395
406
|
|
|
396
407
|
def to_s
|
|
397
|
-
"
|
|
408
|
+
format_message "module=#{module_name}, method=#{method_name}"
|
|
398
409
|
end
|
|
399
410
|
end
|
|
400
411
|
|
|
@@ -407,7 +418,7 @@ module Steep
|
|
|
407
418
|
end
|
|
408
419
|
|
|
409
420
|
def to_s
|
|
410
|
-
"
|
|
421
|
+
format_message "type=#{type}"
|
|
411
422
|
end
|
|
412
423
|
end
|
|
413
424
|
|
|
@@ -417,7 +428,7 @@ module Steep
|
|
|
417
428
|
end
|
|
418
429
|
|
|
419
430
|
def to_s
|
|
420
|
-
|
|
431
|
+
format_message ""
|
|
421
432
|
end
|
|
422
433
|
end
|
|
423
434
|
|
|
@@ -440,7 +451,7 @@ module Steep
|
|
|
440
451
|
include ResultPrinter
|
|
441
452
|
|
|
442
453
|
def to_s
|
|
443
|
-
"
|
|
454
|
+
format_message "method_type=#{method_type}, constraint=#{sub_type} <: '#{var} <: #{super_type}"
|
|
444
455
|
end
|
|
445
456
|
end
|
|
446
457
|
|
|
@@ -459,7 +470,7 @@ module Steep
|
|
|
459
470
|
include ResultPrinter
|
|
460
471
|
|
|
461
472
|
def to_s
|
|
462
|
-
"
|
|
473
|
+
format_message "var_name=#{var_name}, #{relation}"
|
|
463
474
|
end
|
|
464
475
|
end
|
|
465
476
|
|
|
@@ -478,7 +489,7 @@ module Steep
|
|
|
478
489
|
include ResultPrinter
|
|
479
490
|
|
|
480
491
|
def to_s
|
|
481
|
-
"
|
|
492
|
+
format_message "var_name=#{var_name}, #{relation}"
|
|
482
493
|
end
|
|
483
494
|
end
|
|
484
495
|
|
|
@@ -491,7 +502,7 @@ module Steep
|
|
|
491
502
|
end
|
|
492
503
|
|
|
493
504
|
def to_s
|
|
494
|
-
"
|
|
505
|
+
format_message "type=#{type}"
|
|
495
506
|
end
|
|
496
507
|
end
|
|
497
508
|
|
|
@@ -504,7 +515,7 @@ module Steep
|
|
|
504
515
|
end
|
|
505
516
|
|
|
506
517
|
def to_s
|
|
507
|
-
"
|
|
518
|
+
format_message "type=#{type}"
|
|
508
519
|
end
|
|
509
520
|
end
|
|
510
521
|
|
|
@@ -519,7 +530,7 @@ module Steep
|
|
|
519
530
|
end
|
|
520
531
|
|
|
521
532
|
def to_s
|
|
522
|
-
"
|
|
533
|
+
format_message "expected_tuple=#{expected_tuple}"
|
|
523
534
|
end
|
|
524
535
|
end
|
|
525
536
|
|
|
@@ -532,7 +543,7 @@ module Steep
|
|
|
532
543
|
end
|
|
533
544
|
|
|
534
545
|
def to_s
|
|
535
|
-
|
|
546
|
+
format_message unexpected_keywords.to_a.join(", ")
|
|
536
547
|
end
|
|
537
548
|
end
|
|
538
549
|
|
|
@@ -545,7 +556,7 @@ module Steep
|
|
|
545
556
|
end
|
|
546
557
|
|
|
547
558
|
def to_s
|
|
548
|
-
|
|
559
|
+
format_message missing_keywords.to_a.join(", ")
|
|
549
560
|
end
|
|
550
561
|
end
|
|
551
562
|
|
|
@@ -558,8 +569,7 @@ module Steep
|
|
|
558
569
|
end
|
|
559
570
|
|
|
560
571
|
def to_s
|
|
561
|
-
|
|
562
|
-
"#{location_to_str}: UnsupportedSyntax: #{msg}"
|
|
572
|
+
format_message(message || "#{node.type} is not supported")
|
|
563
573
|
end
|
|
564
574
|
end
|
|
565
575
|
|
|
@@ -574,8 +584,8 @@ module Steep
|
|
|
574
584
|
end
|
|
575
585
|
|
|
576
586
|
def to_s
|
|
577
|
-
<<-MESSAGE
|
|
578
|
-
#{
|
|
587
|
+
format_message <<-MESSAGE
|
|
588
|
+
#{error.class}
|
|
579
589
|
>> #{message}
|
|
580
590
|
MESSAGE
|
|
581
591
|
end
|
data/lib/steep/project/target.rb
CHANGED
|
@@ -192,8 +192,8 @@ module Steep
|
|
|
192
192
|
rescue RBS::DuplicatedDeclarationError => exn
|
|
193
193
|
@status = SignatureValidationErrorStatus.new(
|
|
194
194
|
errors: [
|
|
195
|
-
Signature::Errors::
|
|
196
|
-
|
|
195
|
+
Signature::Errors::DuplicatedDeclarationError.new(
|
|
196
|
+
type_name: exn.name,
|
|
197
197
|
location: exn.decls[0].location
|
|
198
198
|
)
|
|
199
199
|
],
|
|
@@ -19,16 +19,16 @@ module Steep
|
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
class
|
|
23
|
-
attr_reader :
|
|
22
|
+
class DuplicatedDeclarationError < Base
|
|
23
|
+
attr_reader :type_name
|
|
24
24
|
|
|
25
|
-
def initialize(
|
|
26
|
-
@
|
|
25
|
+
def initialize(type_name:, location:)
|
|
26
|
+
@type_name = type_name
|
|
27
27
|
@location = location
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def puts(io)
|
|
31
|
-
io.puts "#{loc_to_s}\
|
|
31
|
+
io.puts "#{loc_to_s}\sDuplicatedDeclarationError: name=#{type_name}"
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
|
|
@@ -76,6 +76,52 @@ module Steep
|
|
|
76
76
|
io.puts "#{loc_to_s}\tInvalidMethodOverloadError: class_name=#{class_name}, method_name=#{method_name}"
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
|
+
|
|
80
|
+
class UnknownMethodAliasError < Base
|
|
81
|
+
attr_reader :class_name
|
|
82
|
+
attr_reader :method_name
|
|
83
|
+
|
|
84
|
+
def initialize(class_name:, method_name:, location:)
|
|
85
|
+
@class_name = class_name
|
|
86
|
+
@method_name = method_name
|
|
87
|
+
@location = location
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def puts(io)
|
|
91
|
+
io.puts "#{loc_to_s}\tUnknownMethodAliasError: class_name=#{class_name}, method_name=#{method_name}"
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
class DuplicatedMethodDefinitionError < Base
|
|
96
|
+
attr_reader :class_name
|
|
97
|
+
attr_reader :method_name
|
|
98
|
+
|
|
99
|
+
def initialize(class_name:, method_name:, location:)
|
|
100
|
+
@class_name = class_name
|
|
101
|
+
@method_name = method_name
|
|
102
|
+
@location = location
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def puts(io)
|
|
106
|
+
io.puts "#{loc_to_s}\tDuplicatedMethodDefinitionError: class_name=#{class_name}, method_name=#{method_name}"
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
class RecursiveAliasError < Base
|
|
111
|
+
attr_reader :class_name
|
|
112
|
+
attr_reader :names
|
|
113
|
+
attr_reader :location
|
|
114
|
+
|
|
115
|
+
def initialize(class_name:, names:, location:)
|
|
116
|
+
@class_name = class_name
|
|
117
|
+
@names = names
|
|
118
|
+
@location = location
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def puts(io)
|
|
122
|
+
io.puts "#{loc_to_s}\tRecursiveAliasError: class_name=#{class_name}, names=#{names.join(", ")}"
|
|
123
|
+
end
|
|
124
|
+
end
|
|
79
125
|
end
|
|
80
126
|
end
|
|
81
127
|
end
|
|
@@ -62,7 +62,7 @@ module Steep
|
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
def validate_one_class(name)
|
|
65
|
-
rescue_validation_errors do
|
|
65
|
+
rescue_validation_errors(name) do
|
|
66
66
|
Steep.logger.debug "Validating class definition `#{name}`..."
|
|
67
67
|
Steep.logger.tagged "#{name}" do
|
|
68
68
|
builder.build_instance(name).each_type do |type|
|
|
@@ -76,7 +76,7 @@ module Steep
|
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
def validate_one_interface(name)
|
|
79
|
-
rescue_validation_errors do
|
|
79
|
+
rescue_validation_errors(name) do
|
|
80
80
|
Steep.logger.debug "Validating interface `#{name}`..."
|
|
81
81
|
Steep.logger.tagged "#{name}" do
|
|
82
82
|
builder.build_interface(name).each_type do |type|
|
|
@@ -117,7 +117,7 @@ module Steep
|
|
|
117
117
|
|
|
118
118
|
def validate_alias
|
|
119
119
|
env.alias_decls.each do |name, entry|
|
|
120
|
-
rescue_validation_errors do
|
|
120
|
+
rescue_validation_errors(name) do
|
|
121
121
|
Steep.logger.debug "Validating alias `#{name}`..."
|
|
122
122
|
builder.expand_alias(name).tap do |type|
|
|
123
123
|
validate_type(type)
|
|
@@ -126,7 +126,7 @@ module Steep
|
|
|
126
126
|
end
|
|
127
127
|
end
|
|
128
128
|
|
|
129
|
-
def rescue_validation_errors
|
|
129
|
+
def rescue_validation_errors(type_name = nil)
|
|
130
130
|
yield
|
|
131
131
|
rescue RBS::InvalidTypeApplicationError => exn
|
|
132
132
|
@errors << Errors::InvalidTypeApplicationError.new(
|
|
@@ -146,6 +146,30 @@ module Steep
|
|
|
146
146
|
method_name: exn.method_name,
|
|
147
147
|
location: exn.members[0].location
|
|
148
148
|
)
|
|
149
|
+
rescue RBS::DuplicatedMethodDefinitionError => exn
|
|
150
|
+
@errors << Errors::DuplicatedMethodDefinitionError.new(
|
|
151
|
+
class_name: type_name,
|
|
152
|
+
method_name: exn.method_name,
|
|
153
|
+
location: exn.location
|
|
154
|
+
)
|
|
155
|
+
rescue RBS::DuplicatedInterfaceMethodDefinitionError => exn
|
|
156
|
+
@errors << Errors::DuplicatedMethodDefinitionError.new(
|
|
157
|
+
class_name: type_name,
|
|
158
|
+
method_name: exn.method_name,
|
|
159
|
+
location: exn.member.location
|
|
160
|
+
)
|
|
161
|
+
rescue RBS::UnknownMethodAliasError => exn
|
|
162
|
+
@errors << Errors::UnknownMethodAliasError.new(
|
|
163
|
+
class_name: type_name,
|
|
164
|
+
method_name: exn.aliased_name,
|
|
165
|
+
location: exn.location
|
|
166
|
+
)
|
|
167
|
+
rescue RBS::RecursiveAliasDefinitionError => exn
|
|
168
|
+
@errors << Errors::RecursiveAliasError.new(
|
|
169
|
+
class_name: exn.type.name,
|
|
170
|
+
names: exn.defs.map(&:name),
|
|
171
|
+
location: exn.defs[0].original.location
|
|
172
|
+
)
|
|
149
173
|
end
|
|
150
174
|
end
|
|
151
175
|
end
|
|
@@ -10,7 +10,7 @@ module Steep
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def instance_super_types(type_name, args:)
|
|
13
|
-
ancestors = factory.definition_builder.one_instance_ancestors(type_name)
|
|
13
|
+
ancestors = factory.definition_builder.ancestor_builder.one_instance_ancestors(type_name)
|
|
14
14
|
|
|
15
15
|
subst = unless args.empty?
|
|
16
16
|
args_ = args.map {|type| factory.type_1(type) }
|
|
@@ -50,7 +50,7 @@ module Steep
|
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def singleton_super_types(type_name)
|
|
53
|
-
ancestors = factory.definition_builder.one_singleton_ancestors(type_name)
|
|
53
|
+
ancestors = factory.definition_builder.ancestor_builder.one_singleton_ancestors(type_name)
|
|
54
54
|
|
|
55
55
|
ancestors.each_ancestor.map do |ancestor|
|
|
56
56
|
name = ancestor.name
|
|
@@ -399,6 +399,9 @@ module Steep
|
|
|
399
399
|
|
|
400
400
|
instance_type = AST::Types::Name::Instance.new(name: class_name, args: class_args)
|
|
401
401
|
module_type = AST::Types::Name::Singleton.new(name: class_name)
|
|
402
|
+
else
|
|
403
|
+
instance_type = AST::Builtin::Object.instance_type
|
|
404
|
+
module_type = AST::Builtin::Object.module_type
|
|
402
405
|
end
|
|
403
406
|
|
|
404
407
|
if annots.instance_type
|
|
@@ -642,7 +645,7 @@ module Steep
|
|
|
642
645
|
Pair.new(type: call.return_type, constr: self)
|
|
643
646
|
end
|
|
644
647
|
|
|
645
|
-
def synthesize(node, hint: nil)
|
|
648
|
+
def synthesize(node, hint: nil, condition: false)
|
|
646
649
|
Steep.logger.tagged "synthesize:(#{node.location.expression.to_s.split(/:/, 2).last})" do
|
|
647
650
|
Steep.logger.debug node.type
|
|
648
651
|
case node.type
|
|
@@ -879,9 +882,7 @@ module Steep
|
|
|
879
882
|
new.typing.add_context_for_node(node, context: new.context)
|
|
880
883
|
new.typing.add_context_for_body(node, context: new.context)
|
|
881
884
|
|
|
882
|
-
|
|
883
|
-
_, new = new.synthesize(arg)
|
|
884
|
-
end
|
|
885
|
+
new = new.synthesize_children(args_node)
|
|
885
886
|
|
|
886
887
|
body_pair = if body_node
|
|
887
888
|
return_type = expand_alias(new.method_context&.return_type)
|
|
@@ -936,14 +937,17 @@ module Steep
|
|
|
936
937
|
checker.factory.definition_builder.build_singleton(name)
|
|
937
938
|
end
|
|
938
939
|
|
|
940
|
+
args_node = node.children[2]
|
|
939
941
|
new = for_new_method(node.children[1],
|
|
940
942
|
node,
|
|
941
|
-
args:
|
|
943
|
+
args: args_node.children,
|
|
942
944
|
self_type: self_type,
|
|
943
945
|
definition: definition)
|
|
944
946
|
new.typing.add_context_for_node(node, context: new.context)
|
|
945
947
|
new.typing.add_context_for_body(node, context: new.context)
|
|
946
948
|
|
|
949
|
+
new = new.synthesize_children(args_node)
|
|
950
|
+
|
|
947
951
|
each_child_node(node.children[2]) do |arg|
|
|
948
952
|
new.synthesize(arg)
|
|
949
953
|
end
|
|
@@ -1091,10 +1095,6 @@ module Steep
|
|
|
1091
1095
|
add_typing(node, type: type)
|
|
1092
1096
|
else
|
|
1093
1097
|
type = AST::Builtin.any_type
|
|
1094
|
-
if context&.method_context&.method_type
|
|
1095
|
-
Steep.logger.error { "Unknown arg type: #{node}" }
|
|
1096
|
-
end
|
|
1097
|
-
|
|
1098
1098
|
lvasgn(node, type)
|
|
1099
1099
|
end
|
|
1100
1100
|
end
|
|
@@ -1514,18 +1514,22 @@ module Steep
|
|
|
1514
1514
|
yield_self do
|
|
1515
1515
|
left, right = node.children
|
|
1516
1516
|
|
|
1517
|
-
left_type, constr = synthesize(left)
|
|
1517
|
+
left_type, constr = synthesize(left, hint: hint, condition: true)
|
|
1518
1518
|
|
|
1519
1519
|
interpreter = TypeInference::LogicTypeInterpreter.new(subtyping: checker, typing: typing)
|
|
1520
1520
|
truthy_env, falsey_env = interpreter.eval(env: constr.context.lvar_env, type: left_type, node: left)
|
|
1521
1521
|
|
|
1522
|
+
if left_type.is_a?(AST::Types::Logic::Env)
|
|
1523
|
+
left_type = left_type.type
|
|
1524
|
+
end
|
|
1525
|
+
|
|
1522
1526
|
right_type, constr = constr
|
|
1523
1527
|
.update_lvar_env { truthy_env }
|
|
1524
1528
|
.tap {|constr| typing.add_context_for_node(right, context: constr.context) }
|
|
1525
1529
|
.for_branch(right)
|
|
1526
|
-
.synthesize(right)
|
|
1530
|
+
.synthesize(right, hint: hint, condition: true)
|
|
1527
1531
|
|
|
1528
|
-
truthy_env, _ = interpreter.eval(env:
|
|
1532
|
+
truthy_env, _ = interpreter.eval(env: constr.context.lvar_env, type: right_type, node: right)
|
|
1529
1533
|
|
|
1530
1534
|
env = if right_type.is_a?(AST::Types::Bot)
|
|
1531
1535
|
falsey_env
|
|
@@ -1534,14 +1538,14 @@ module Steep
|
|
|
1534
1538
|
end
|
|
1535
1539
|
|
|
1536
1540
|
type = case
|
|
1537
|
-
when left_type.is_a?(AST::Types::Logic::Base) && right_type.is_a?(AST::Types::Logic::Base)
|
|
1538
|
-
AST::Types::Logic::Env.new(truthy: truthy_env, falsy: env)
|
|
1539
1541
|
when check_relation(sub_type: left_type, super_type: AST::Types::Boolean.new).success?
|
|
1540
1542
|
union_type(left_type, right_type)
|
|
1541
1543
|
else
|
|
1542
1544
|
union_type(right_type, AST::Builtin.nil_type)
|
|
1543
1545
|
end
|
|
1544
1546
|
|
|
1547
|
+
type = AST::Types::Logic::Env.new(truthy: truthy_env, falsy: env, type: type) if condition
|
|
1548
|
+
|
|
1545
1549
|
add_typing(node,
|
|
1546
1550
|
type: type,
|
|
1547
1551
|
constr: constr.update_lvar_env { env })
|
|
@@ -1551,17 +1555,21 @@ module Steep
|
|
|
1551
1555
|
yield_self do
|
|
1552
1556
|
left, right = node.children
|
|
1553
1557
|
|
|
1554
|
-
left_type, constr = synthesize(left, hint: hint)
|
|
1558
|
+
left_type, constr = synthesize(left, hint: hint, condition: true)
|
|
1555
1559
|
|
|
1556
1560
|
interpreter = TypeInference::LogicTypeInterpreter.new(subtyping: checker, typing: typing)
|
|
1557
1561
|
truthy_env, falsey_env = interpreter.eval(env: constr.context.lvar_env, type: left_type, node: left)
|
|
1558
1562
|
|
|
1563
|
+
if left_type.is_a?(AST::Types::Logic::Env)
|
|
1564
|
+
left_type = left_type.type
|
|
1565
|
+
end
|
|
1559
1566
|
left_type, _ = checker.factory.unwrap_optional(left_type)
|
|
1567
|
+
|
|
1560
1568
|
right_type, constr = constr
|
|
1561
1569
|
.update_lvar_env { falsey_env }
|
|
1562
1570
|
.tap {|constr| typing.add_context_for_node(right, context: constr.context) }
|
|
1563
1571
|
.for_branch(right)
|
|
1564
|
-
.synthesize(right, hint: left_type)
|
|
1572
|
+
.synthesize(right, hint: left_type, condition: true)
|
|
1565
1573
|
|
|
1566
1574
|
_, falsey_env = interpreter.eval(env: falsey_env, type: right_type, node: right)
|
|
1567
1575
|
|
|
@@ -1572,12 +1580,14 @@ module Steep
|
|
|
1572
1580
|
end
|
|
1573
1581
|
|
|
1574
1582
|
type = case
|
|
1575
|
-
when left_type
|
|
1576
|
-
AST::
|
|
1583
|
+
when check_relation(sub_type: left_type, super_type: AST::Builtin.bool_type).success?
|
|
1584
|
+
AST::Builtin.bool_type
|
|
1577
1585
|
else
|
|
1578
1586
|
union_type(left_type, right_type)
|
|
1579
1587
|
end
|
|
1580
1588
|
|
|
1589
|
+
type = AST::Types::Logic::Env.new(truthy: env, falsy: falsey_env, type: type) if condition
|
|
1590
|
+
|
|
1581
1591
|
add_typing(node,
|
|
1582
1592
|
type: type,
|
|
1583
1593
|
constr: constr.update_lvar_env { env })
|
|
@@ -1586,7 +1596,7 @@ module Steep
|
|
|
1586
1596
|
when :if
|
|
1587
1597
|
cond, true_clause, false_clause = node.children
|
|
1588
1598
|
|
|
1589
|
-
cond_type, constr = synthesize(cond)
|
|
1599
|
+
cond_type, constr = synthesize(cond, condition: true)
|
|
1590
1600
|
interpreter = TypeInference::LogicTypeInterpreter.new(subtyping: checker, typing: constr.typing)
|
|
1591
1601
|
truthy_env, falsey_env = interpreter.eval(env: constr.context.lvar_env, type: cond_type, node: cond)
|
|
1592
1602
|
|
|
@@ -1667,7 +1677,7 @@ module Steep
|
|
|
1667
1677
|
|
|
1668
1678
|
tests.each do |test|
|
|
1669
1679
|
test_node = test.updated(:send, [test, :===, var_node])
|
|
1670
|
-
test_type, test_constr = test_constr.synthesize(test_node)
|
|
1680
|
+
test_type, test_constr = test_constr.synthesize(test_node, condition: true)
|
|
1671
1681
|
truthy_env, falsy_env = interpreter.eval(type: test_type, node: test_node, env: test_constr.context.lvar_env)
|
|
1672
1682
|
truthy_env = cond_vars.inject(truthy_env) do |env, var|
|
|
1673
1683
|
env.assign!(var, node: test_node, type: env[first_var])
|
|
@@ -1675,6 +1685,7 @@ module Steep
|
|
|
1675
1685
|
falsy_env = cond_vars.inject(falsy_env) do |env, var|
|
|
1676
1686
|
env.assign!(var, node: test_node, type: env[first_var])
|
|
1677
1687
|
end
|
|
1688
|
+
|
|
1678
1689
|
test_envs << truthy_env
|
|
1679
1690
|
test_constr = test_constr.update_lvar_env { falsy_env }
|
|
1680
1691
|
end
|
|
@@ -1719,21 +1730,20 @@ module Steep
|
|
|
1719
1730
|
branch_pairs = []
|
|
1720
1731
|
|
|
1721
1732
|
when_constr = constr
|
|
1733
|
+
clause_constr = constr
|
|
1722
1734
|
|
|
1723
1735
|
whens.each do |clause|
|
|
1724
1736
|
*tests, body = clause.children
|
|
1725
1737
|
|
|
1726
1738
|
test_constr = when_constr
|
|
1727
|
-
test_envs = []
|
|
1728
1739
|
|
|
1729
1740
|
tests.each do |test|
|
|
1730
|
-
test_type, test_constr = test_constr.synthesize(test)
|
|
1741
|
+
test_type, test_constr = test_constr.synthesize(test, condition: true)
|
|
1731
1742
|
truthy_env, falsy_env = interpreter.eval(env: test_constr.context.lvar_env, type: test_type, node: test)
|
|
1732
|
-
|
|
1743
|
+
clause_constr = clause_constr.update_lvar_env { truthy_env }
|
|
1733
1744
|
test_constr = test_constr.update_lvar_env { falsy_env }
|
|
1734
1745
|
end
|
|
1735
1746
|
|
|
1736
|
-
clause_constr = when_constr.update_lvar_env {|env| env.join(*test_envs) }
|
|
1737
1747
|
when_constr = test_constr
|
|
1738
1748
|
|
|
1739
1749
|
if body
|
|
@@ -1907,7 +1917,7 @@ module Steep
|
|
|
1907
1917
|
when :while, :until
|
|
1908
1918
|
yield_self do
|
|
1909
1919
|
cond, body = node.children
|
|
1910
|
-
cond_type, constr = synthesize(cond)
|
|
1920
|
+
cond_type, constr = synthesize(cond, condition: true)
|
|
1911
1921
|
|
|
1912
1922
|
interpreter = TypeInference::LogicTypeInterpreter.new(subtyping: checker, typing: typing)
|
|
1913
1923
|
truthy_env, falsy_env = interpreter.eval(env: constr.context.lvar_env, node: cond, type: cond_type)
|
|
@@ -2154,7 +2164,12 @@ module Steep
|
|
|
2154
2164
|
|
|
2155
2165
|
when :splat
|
|
2156
2166
|
yield_self do
|
|
2157
|
-
|
|
2167
|
+
typing.add_error(
|
|
2168
|
+
Errors::UnsupportedSyntax.new(
|
|
2169
|
+
node: node,
|
|
2170
|
+
message: "Unsupported splat node occurrence"
|
|
2171
|
+
)
|
|
2172
|
+
)
|
|
2158
2173
|
|
|
2159
2174
|
each_child_node node do |child|
|
|
2160
2175
|
synthesize(child)
|
|
@@ -2173,7 +2188,7 @@ module Steep
|
|
|
2173
2188
|
add_typing node, type: AST::Builtin.any_type, constr: constr
|
|
2174
2189
|
|
|
2175
2190
|
else
|
|
2176
|
-
|
|
2191
|
+
typing.add_error(Errors::UnsupportedSyntax.new(node: node))
|
|
2177
2192
|
|
|
2178
2193
|
end.tap do |pair|
|
|
2179
2194
|
unless pair.is_a?(Pair) && !pair.type.is_a?(Pair)
|
|
@@ -2542,7 +2557,25 @@ module Steep
|
|
|
2542
2557
|
|
|
2543
2558
|
constr.add_call(call)
|
|
2544
2559
|
else
|
|
2545
|
-
|
|
2560
|
+
skips = []
|
|
2561
|
+
skips << receiver if receiver
|
|
2562
|
+
skips << node.children[0] if node.type == :block
|
|
2563
|
+
skips << block_params if block_params
|
|
2564
|
+
skips << block_body if block_body
|
|
2565
|
+
|
|
2566
|
+
constr = synthesize_children(node, skips: skips)
|
|
2567
|
+
if block_params
|
|
2568
|
+
block_annotations = source.annotations(block: node, factory: checker.factory, current_module: current_namespace)
|
|
2569
|
+
|
|
2570
|
+
constr.type_block_without_hint(
|
|
2571
|
+
node: node,
|
|
2572
|
+
block_params: TypeInference::BlockParams.from_node(block_params, annotations: block_annotations),
|
|
2573
|
+
block_annotations: block_annotations,
|
|
2574
|
+
block_body: block_body
|
|
2575
|
+
)
|
|
2576
|
+
end
|
|
2577
|
+
|
|
2578
|
+
constr.add_call(
|
|
2546
2579
|
TypeInference::MethodCall::NoMethodError.new(
|
|
2547
2580
|
node: node,
|
|
2548
2581
|
context: context.method_context,
|
|
@@ -3129,9 +3162,9 @@ module Steep
|
|
|
3129
3162
|
block_constr = for_block(
|
|
3130
3163
|
block_params: block_params,
|
|
3131
3164
|
block_param_hint: nil,
|
|
3132
|
-
block_type_hint:
|
|
3165
|
+
block_type_hint: AST::Builtin.any_type,
|
|
3133
3166
|
block_annotations: block_annotations,
|
|
3134
|
-
node_type_hint:
|
|
3167
|
+
node_type_hint: AST::Builtin.any_type
|
|
3135
3168
|
)
|
|
3136
3169
|
|
|
3137
3170
|
block_constr.typing.add_context_for_body(node, context: block_constr.context)
|
|
@@ -41,8 +41,11 @@ module Steep
|
|
|
41
41
|
|
|
42
42
|
if type.is_a?(AST::Types::Logic::Base)
|
|
43
43
|
vars.each do |var_name|
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
var_type = truthy_env[var_name]
|
|
45
|
+
truthy_type, falsy_type = factory.unwrap_optional(var_type)
|
|
46
|
+
falsy_type ||= AST::Builtin.nil_type
|
|
47
|
+
truthy_env = truthy_env.assign!(var_name, node: node, type: truthy_type) {|_, type, _| type }
|
|
48
|
+
falsy_env = truthy_env.assign!(var_name, node: node, type: falsy_type) {|_, type, _| type }
|
|
46
49
|
end
|
|
47
50
|
|
|
48
51
|
case type
|
|
@@ -77,11 +80,16 @@ module Steep
|
|
|
77
80
|
|
|
78
81
|
if arg_type.is_a?(AST::Types::Name::Singleton)
|
|
79
82
|
receiver_vars.each do |var_name|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
case var_name
|
|
84
|
+
when :_, :__any__, :__skip__
|
|
85
|
+
# skip
|
|
86
|
+
else
|
|
87
|
+
var_type = env[var_name]
|
|
88
|
+
truthy_type, falsy_type = type_case_select(var_type, arg_type.name)
|
|
89
|
+
|
|
90
|
+
truthy_env = truthy_env.assign!(var_name, node: node, type: truthy_type)
|
|
91
|
+
falsy_env = falsy_env.assign!(var_name, node: node, type: falsy_type)
|
|
92
|
+
end
|
|
85
93
|
end
|
|
86
94
|
end
|
|
87
95
|
end
|
|
@@ -93,7 +101,7 @@ module Steep
|
|
|
93
101
|
|
|
94
102
|
if receiver
|
|
95
103
|
_, arg_vars = decompose_value(arg)
|
|
96
|
-
receiver_type = typing.type_of(node: receiver)
|
|
104
|
+
receiver_type = factory.deep_expand_alias(typing.type_of(node: receiver))
|
|
97
105
|
|
|
98
106
|
if receiver_type.is_a?(AST::Types::Name::Singleton)
|
|
99
107
|
arg_vars.each do |var_name|
|
|
@@ -106,6 +114,23 @@ module Steep
|
|
|
106
114
|
end
|
|
107
115
|
end
|
|
108
116
|
end
|
|
117
|
+
when AST::Types::Logic::ArgEqualsReceiver
|
|
118
|
+
case value_node.type
|
|
119
|
+
when :send
|
|
120
|
+
receiver, _, arg = value_node.children
|
|
121
|
+
|
|
122
|
+
if receiver
|
|
123
|
+
_, arg_vars = decompose_value(arg)
|
|
124
|
+
|
|
125
|
+
arg_vars.each do |var_name|
|
|
126
|
+
var_type = factory.deep_expand_alias(env[var_name])
|
|
127
|
+
truthy_types, falsy_types = literal_var_type_case_select(receiver, var_type)
|
|
128
|
+
|
|
129
|
+
truthy_env = truthy_env.assign!(var_name, node: node, type: AST::Types::Union.build(types: truthy_types, location: nil))
|
|
130
|
+
falsy_env = falsy_env.assign!(var_name, node: node, type: AST::Types::Union.build(types: falsy_types, location: nil))
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
109
134
|
when AST::Types::Logic::Not
|
|
110
135
|
receiver, * = value_node.children
|
|
111
136
|
receiver_type = typing.type_of(node: receiver)
|
|
@@ -156,6 +181,60 @@ module Steep
|
|
|
156
181
|
end
|
|
157
182
|
end
|
|
158
183
|
|
|
184
|
+
def literal_var_type_case_select(value_node, arg_type)
|
|
185
|
+
case arg_type
|
|
186
|
+
when AST::Types::Union
|
|
187
|
+
truthy_types = []
|
|
188
|
+
falsy_types = []
|
|
189
|
+
|
|
190
|
+
arg_type.types.each do |type|
|
|
191
|
+
ts, fs = literal_var_type_case_select(value_node, type)
|
|
192
|
+
truthy_types.push(*ts)
|
|
193
|
+
falsy_types.push(*fs)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
[truthy_types, falsy_types]
|
|
197
|
+
else
|
|
198
|
+
value_type = typing.type_of(node: value_node)
|
|
199
|
+
types = [arg_type]
|
|
200
|
+
|
|
201
|
+
case value_node.type
|
|
202
|
+
when :nil
|
|
203
|
+
types.partition do |type|
|
|
204
|
+
type.is_a?(AST::Types::Nil) || AST::Builtin::NilClass.instance_type?(type)
|
|
205
|
+
end
|
|
206
|
+
when :true
|
|
207
|
+
types.partition do |type|
|
|
208
|
+
AST::Builtin::TrueClass.instance_type?(type) ||
|
|
209
|
+
(type.is_a?(AST::Types::Literal) && type.value == true)
|
|
210
|
+
end
|
|
211
|
+
when :false
|
|
212
|
+
types.partition do |type|
|
|
213
|
+
AST::Builtin::FalseClass.instance_type?(type) ||
|
|
214
|
+
(type.is_a?(AST::Types::Literal) && type.value == false)
|
|
215
|
+
end
|
|
216
|
+
when :int, :str, :sym
|
|
217
|
+
types.each.with_object([[], []]) do |type, pair|
|
|
218
|
+
true_types, false_types = pair
|
|
219
|
+
|
|
220
|
+
case
|
|
221
|
+
when type.is_a?(AST::Types::Literal)
|
|
222
|
+
if type.value == value_node.children[0]
|
|
223
|
+
true_types << type
|
|
224
|
+
else
|
|
225
|
+
false_types << type
|
|
226
|
+
end
|
|
227
|
+
else
|
|
228
|
+
true_types << AST::Types::Literal.new(value: value_node.children[0])
|
|
229
|
+
false_types << type
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
else
|
|
233
|
+
[[arg_type], [arg_type]]
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
159
238
|
def type_case_select(type, klass)
|
|
160
239
|
truth_types, false_types = type_case_select0(type, klass)
|
|
161
240
|
|
|
@@ -186,20 +265,6 @@ module Steep
|
|
|
186
265
|
|
|
187
266
|
[truthy_types, falsy_types]
|
|
188
267
|
|
|
189
|
-
when AST::Types::Name::Instance
|
|
190
|
-
relation = Subtyping::Relation.new(sub_type: type, super_type: instance_type)
|
|
191
|
-
if subtyping.check(relation, constraints: Subtyping::Constraints.empty, self_type: AST::Types::Self.new).success?
|
|
192
|
-
[
|
|
193
|
-
[type],
|
|
194
|
-
[]
|
|
195
|
-
]
|
|
196
|
-
else
|
|
197
|
-
[
|
|
198
|
-
[],
|
|
199
|
-
[type]
|
|
200
|
-
]
|
|
201
|
-
end
|
|
202
|
-
|
|
203
268
|
when AST::Types::Name::Alias
|
|
204
269
|
ty = factory.expand_alias(type)
|
|
205
270
|
type_case_select0(ty, klass)
|
|
@@ -217,10 +282,18 @@ module Steep
|
|
|
217
282
|
]
|
|
218
283
|
|
|
219
284
|
else
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
[
|
|
223
|
-
|
|
285
|
+
relation = Subtyping::Relation.new(sub_type: type, super_type: instance_type)
|
|
286
|
+
if subtyping.check(relation, constraints: Subtyping::Constraints.empty, self_type: AST::Types::Self.new).success?
|
|
287
|
+
[
|
|
288
|
+
[type],
|
|
289
|
+
[]
|
|
290
|
+
]
|
|
291
|
+
else
|
|
292
|
+
[
|
|
293
|
+
[],
|
|
294
|
+
[type]
|
|
295
|
+
]
|
|
296
|
+
end
|
|
224
297
|
end
|
|
225
298
|
end
|
|
226
299
|
end
|
data/lib/steep/version.rb
CHANGED
data/smoke/type_case/a.rb
CHANGED
data/steep.gemspec
CHANGED
|
@@ -34,5 +34,5 @@ Gem::Specification.new do |spec|
|
|
|
34
34
|
spec.add_runtime_dependency "rainbow", ">= 2.2.2", "< 4.0"
|
|
35
35
|
spec.add_runtime_dependency "listen", "~> 3.0"
|
|
36
36
|
spec.add_runtime_dependency "language_server-protocol", "~> 3.15.0.1"
|
|
37
|
-
spec.add_runtime_dependency "rbs", "
|
|
37
|
+
spec.add_runtime_dependency "rbs", "~> 1.0.0"
|
|
38
38
|
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.
|
|
4
|
+
version: 0.39.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-12-
|
|
11
|
+
date: 2020-12-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: parser
|
|
@@ -104,16 +104,16 @@ dependencies:
|
|
|
104
104
|
name: rbs
|
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
|
106
106
|
requirements:
|
|
107
|
-
- - "
|
|
107
|
+
- - "~>"
|
|
108
108
|
- !ruby/object:Gem::Version
|
|
109
|
-
version: 0.
|
|
109
|
+
version: 1.0.0
|
|
110
110
|
type: :runtime
|
|
111
111
|
prerelease: false
|
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
|
113
113
|
requirements:
|
|
114
|
-
- - "
|
|
114
|
+
- - "~>"
|
|
115
115
|
- !ruby/object:Gem::Version
|
|
116
|
-
version: 0.
|
|
116
|
+
version: 1.0.0
|
|
117
117
|
description: Gradual Typing for Ruby
|
|
118
118
|
email:
|
|
119
119
|
- matsumoto@soutaro.com
|
|
@@ -389,7 +389,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
389
389
|
- !ruby/object:Gem::Version
|
|
390
390
|
version: '0'
|
|
391
391
|
requirements: []
|
|
392
|
-
rubygems_version: 3.1.
|
|
392
|
+
rubygems_version: 3.1.4
|
|
393
393
|
signing_key:
|
|
394
394
|
specification_version: 4
|
|
395
395
|
summary: Gradual Typing for Ruby
|