steep 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/LICENSE +21 -0
  4. data/bin/smoke_runner.rb +3 -0
  5. data/lib/steep/ast/annotation/collection.rb +120 -43
  6. data/lib/steep/ast/annotation.rb +5 -10
  7. data/lib/steep/ast/location.rb +1 -1
  8. data/lib/steep/ast/method_type.rb +3 -1
  9. data/lib/steep/ast/signature/alias.rb +19 -0
  10. data/lib/steep/ast/signature/env.rb +9 -0
  11. data/lib/steep/ast/signature/members.rb +4 -0
  12. data/lib/steep/ast/types/proc.rb +79 -0
  13. data/lib/steep/ast/types/void.rb +4 -0
  14. data/lib/steep/cli.rb +2 -1
  15. data/lib/steep/drivers/check.rb +4 -1
  16. data/lib/steep/errors.rb +13 -0
  17. data/lib/steep/interface/builder.rb +90 -47
  18. data/lib/steep/interface/instantiated.rb +1 -1
  19. data/lib/steep/interface/method.rb +8 -0
  20. data/lib/steep/interface/method_type.rb +40 -13
  21. data/lib/steep/parser.rb +1098 -1043
  22. data/lib/steep/parser.y +94 -36
  23. data/lib/steep/source.rb +5 -6
  24. data/lib/steep/subtyping/check.rb +162 -47
  25. data/lib/steep/subtyping/variable_occurrence.rb +2 -2
  26. data/lib/steep/subtyping/variable_variance.rb +3 -3
  27. data/lib/steep/type_construction.rb +630 -300
  28. data/lib/steep/type_inference/block_params.rb +186 -35
  29. data/lib/steep/type_inference/send_args.rb +12 -3
  30. data/lib/steep/type_inference/type_env.rb +10 -4
  31. data/lib/steep/type_name.rb +6 -0
  32. data/lib/steep/typing.rb +21 -2
  33. data/lib/steep/version.rb +1 -1
  34. data/lib/steep.rb +2 -0
  35. data/smoke/alias/a.rb +19 -0
  36. data/smoke/alias/a.rbi +10 -0
  37. data/smoke/alias/b.rb +7 -0
  38. data/smoke/alias/c.rb +10 -0
  39. data/smoke/array/c.rb +7 -0
  40. data/smoke/block/c.rb +10 -0
  41. data/smoke/block/c.rbi +3 -0
  42. data/smoke/block/d.rb +15 -0
  43. data/smoke/class/c.rb +1 -1
  44. data/smoke/class/e.rb +1 -1
  45. data/smoke/class/h.rb +15 -0
  46. data/smoke/class/h.rbi +7 -0
  47. data/smoke/class/i.rb +17 -0
  48. data/smoke/class/i.rbi +9 -0
  49. data/smoke/extension/a.rbi +4 -0
  50. data/smoke/extension/d.rb +2 -0
  51. data/smoke/hash/a.rb +17 -0
  52. data/smoke/hash/b.rb +7 -0
  53. data/smoke/implements/a.rb +2 -2
  54. data/smoke/initialize/a.rb +1 -1
  55. data/smoke/lambda/a.rb +11 -0
  56. data/smoke/literal/b.rb +9 -0
  57. data/smoke/literal/literal_methods.rbi +4 -0
  58. data/smoke/method/c.rb +5 -0
  59. data/smoke/regression/array.rb +7 -0
  60. data/smoke/regression/hash.rb +7 -0
  61. data/smoke/regression/set_divide.rb +16 -0
  62. data/smoke/self/a.rb +2 -2
  63. data/stdlib/builtin.rbi +151 -1
  64. data/steep.gemspec +1 -0
  65. metadata +30 -4
@@ -0,0 +1,9 @@
1
+ l = LiteralMethods.new
2
+
3
+ l.foo(3)
4
+ # !expects ArgumentTypeMismatch: receiver=::LiteralMethods, expected=3, actual=::Integer
5
+ l.foo(4)
6
+
7
+ l.bar(foo: :foo)
8
+ # !expects ArgumentTypeMismatch: receiver=::LiteralMethods, expected=:foo, actual=::Symbol
9
+ l.bar(foo: :bar)
@@ -0,0 +1,4 @@
1
+ class LiteralMethods
2
+ def foo: (3) -> 4
3
+ def bar: (foo: :foo) -> 5
4
+ end
data/smoke/method/c.rb ADDED
@@ -0,0 +1,5 @@
1
+ a = 123
2
+
3
+ a = -a
4
+ b = !a
5
+ c = a.nil?
@@ -0,0 +1,7 @@
1
+ class Foo
2
+ # @type method foo: (Array<String>) -> void
3
+ def array(x)
4
+ # @type ivar @y: Array<String>>
5
+ @y = x
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class Foo
2
+ # @type method foo: (Hash<String, any>) -> void
3
+ def foo(x)
4
+ # @type ivar @y: Hash<String, any>
5
+ @y = x
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ d = Set.new([1,2,3], &:to_s)
2
+ # !expects NoMethodError: type=::Set<::String>, method=ffffffff
3
+ d.ffffffff
4
+
5
+ d.divide do |x, y|
6
+ # !expects NoMethodError: type=::String, method=ggggg
7
+ x.ggggg
8
+
9
+ # !expects NoMethodError: type=::String, method=ggggg
10
+ y.ggggg
11
+ end
12
+
13
+ d.divide do |x|
14
+ # !expects NoMethodError: type=::String, method=ggggg
15
+ x.ggggg
16
+ end
data/smoke/self/a.rb CHANGED
@@ -13,11 +13,11 @@ end
13
13
  def bar
14
14
  # @type self: Object
15
15
 
16
- # !expects NoMethodError: type=Object, method=baz
16
+ # !expects NoMethodError: type=::Object, method=baz
17
17
  baz
18
18
 
19
19
  tap do
20
- # !expects NoMethodError: type=Object, method=baz
20
+ # !expects NoMethodError: type=::Object, method=baz
21
21
  baz
22
22
  end
23
23
  end
data/stdlib/builtin.rbi CHANGED
@@ -20,7 +20,12 @@ class Object <: BasicObject
20
20
  def yield_self: <'a>{ (self) -> 'a } -> 'a
21
21
  def dup: -> self
22
22
  def send: (Symbol, *any) -> any
23
+ def __send__: (Symbol, *any) -> any
23
24
  def instance_variable_get: (Symbol) -> any
25
+ def nil?: -> bool
26
+ def !: -> bool
27
+ def Array: (any) -> Array<any>
28
+ def Hash: (any) -> Hash<any, any>
24
29
  end
25
30
 
26
31
  class Module
@@ -73,6 +78,7 @@ class Array<'a>
73
78
 
74
79
  def []: (Integer) -> 'a
75
80
  | (Range<Integer>) -> self?
81
+ | (0, Integer) -> self
76
82
  | (Integer, Integer) -> self?
77
83
  def at: (Integer) -> 'a
78
84
  | (Range<Integer>) -> self?
@@ -102,7 +108,7 @@ class Array<'a>
102
108
  def concat: (*Array<'a>) -> self
103
109
  | (*'a) -> self
104
110
  def delete: ('a) -> 'a?
105
- | <'x> ('a) { ('a) -> any } -> ('a | 'x)
111
+ | <'x> ('a) { () -> 'x } -> ('a | 'x)
106
112
  def delete_at: (Integer) -> 'a?
107
113
  def delete_if: { ('a) -> any } -> self
108
114
  | -> Enumerator<'a, self>
@@ -225,6 +231,12 @@ class Hash<'key, 'value>
225
231
  | -> Enumerator<'a, self>
226
232
  def self.[]: (Array<any>) -> Hash<'key, 'value>
227
233
  def keys: () -> Array<'key>
234
+ def each: { (['key, 'value]) -> any } -> self
235
+ | -> Enumerator<['key, 'value], self>
236
+ def key?: ('key) -> bool
237
+ def merge: (Hash<'key, 'value>) -> Hash<'key, 'value>
238
+
239
+ include Enumerable<['key, 'value], self>
228
240
  end
229
241
 
230
242
  class Symbol
@@ -253,6 +265,7 @@ class Numeric
253
265
  def >=: (any) -> bool
254
266
  def < : (any) -> bool
255
267
  def >: (any) -> bool
268
+ def -@: -> self
256
269
  end
257
270
 
258
271
  class Integer <: Numeric
@@ -321,6 +334,7 @@ end
321
334
 
322
335
  class String
323
336
  def []: (Range<Integer>) -> String
337
+ | (Integer, Integer) -> String
324
338
  def to_sym: -> Symbol
325
339
  def +: (String) -> String
326
340
  def to_str: -> String
@@ -352,6 +366,13 @@ class String
352
366
  def *: (Integer) -> String
353
367
  def scan: (Regexp) { (Array<String>) -> void } -> String
354
368
  | (Regexp) -> Array<String>
369
+ def lines: -> Array<String>
370
+ def bytesize: -> Integer
371
+ def start_with?: (String) -> bool
372
+ def byteslice: (Integer, Integer) -> String
373
+ def empty?: -> bool
374
+ def length: -> Integer
375
+ def force_encoding: (any) -> self
355
376
  end
356
377
 
357
378
  interface _Iteratable<'a, 'b>
@@ -507,6 +528,9 @@ module Enumerable<'a, 'b> : _Iteratable<'a, 'b>
507
528
  def sort_by: { ('a) -> any } -> Array<'a>
508
529
  | -> Enumerator<'a, Array<'a>>
509
530
 
531
+ def sort_by!: { ('a) -> any } -> self
532
+ | -> Enumerator<'a, self>
533
+
510
534
  def sum: () -> Numeric
511
535
  | (Numeric) -> Numeric
512
536
  | (any) -> any
@@ -529,16 +553,25 @@ class Enumerator<'a, 'b>
529
553
  def each: { ('a) -> any } -> 'b
530
554
  def with_object: <'x> ('x) { ('a, 'x) -> any } -> 'x
531
555
  def with_index: { ('a, Integer) -> any } -> 'b
556
+ | -> Enumerator<['a, Integer], 'b>
532
557
  end
533
558
 
534
559
  class Regexp
560
+ def self.compile: (String, *any) -> Regexp
561
+ def self.escape: (String) -> String
562
+ def source: -> String
535
563
  end
536
564
 
537
565
  class IO
538
566
  def gets: -> String?
539
567
  def puts: (*any) -> void
568
+ def read: (Integer) -> String
569
+ def write: (String) -> Integer
570
+ def flush: () -> void
540
571
  end
541
572
 
573
+ File::FNM_DOTMATCH: Integer
574
+
542
575
  class File <: IO
543
576
  def self.binread: (String) -> String
544
577
  def self.extname: (String) -> String
@@ -547,6 +580,25 @@ class File <: IO
547
580
  def self.binwrite: (String, String) -> void
548
581
  def self.read: (String) -> String
549
582
  | (String, Integer?) -> String?
583
+ def self.fnmatch: (String, String, Integer) -> bool
584
+ def path: -> String
585
+ def self.write: (String, String) -> void
586
+ def self.chmod: (Integer, String) -> void
587
+ end
588
+
589
+ class Proc
590
+ def []: (*any) -> any
591
+ def call: (*any) -> any
592
+ def ===: (*any) -> any
593
+ def yield: (*any) -> any
594
+ def arity: -> Integer
595
+ def binding: -> any
596
+ def curry: -> Proc
597
+ | (Integer) -> Proc
598
+ def lambda?: -> bool
599
+ def parameters: -> Array<[(:req | :opt | :rest | :keyreq | :key | :keyrest | :block), Symbol]>
600
+ def source_location: -> [String, Integer]?
601
+ def to_proc: -> self
550
602
  end
551
603
 
552
604
  STDOUT: IO
@@ -555,3 +607,101 @@ class StringIO
555
607
  def initialize: (?String, ?String) -> any
556
608
  def puts: (*any) -> void
557
609
  end
610
+
611
+ class Process::Status
612
+ def &: (Integer) -> Integer
613
+ def >>: (Integer) -> Integer
614
+ def coredump: -> bool
615
+ def exited?: -> bool
616
+ def exitstatus: -> Integer?
617
+ def pid: -> Integer
618
+ def signaled?: -> bool
619
+ def stopsig: -> Integer?
620
+ def success?: -> bool
621
+ def termsig: -> Integer?
622
+ def to_i: -> Integer
623
+ def to_int: -> Integer
624
+ end
625
+
626
+ module Marshal
627
+ def self.load: (String) -> any
628
+ def self.dump: (any) -> String
629
+ end
630
+
631
+ class Set<'a>
632
+ def self.[]: <'x> (*'x) -> Set<'x>
633
+
634
+ def initialize: (_Iteratable<'a, any>) -> any
635
+ | <'x> (_Iteratable<'x, any>) { ('x) -> 'a } -> any
636
+ | (?nil) -> any
637
+
638
+ def intersection: (_Iteratable<'a, any>) -> self
639
+ def &: (_Iteratable<'a, any>) -> self
640
+
641
+ def union: (_Iteratable<'a, any>) -> self
642
+ def +: (_Iteratable<'a, any>) -> self
643
+ def |: (_Iteratable<'a, any>) -> self
644
+
645
+ def difference: (_Iteratable<'a, any>) -> self
646
+ def -: (_Iteratable<'a, any>) -> self
647
+
648
+ def add: ('a) -> self
649
+ def <<: ('a) -> self
650
+ def add?: ('a) -> self?
651
+
652
+ def member?: (any) -> bool
653
+ def include?: (any) -> bool
654
+
655
+ def ^: (_Iteratable<'a, any>) -> self
656
+
657
+ def classify: <'x> { ('a) -> 'x } -> Hash<'x, self>
658
+
659
+ def clear: -> self
660
+
661
+ def collect!: { ('a) -> 'a } -> self
662
+ def map!: { ('a) -> 'a } -> self
663
+
664
+ def delete: (any) -> self
665
+ def delete?: (any) -> self?
666
+
667
+ def delete_if: { ('a) -> any } -> self
668
+ def reject!: { ('a) -> any } -> self
669
+
670
+ def disjoint?: (self) -> bool
671
+
672
+ def divide: { ('a, 'a) -> any } -> Set<self>
673
+ | { ('a) -> any } -> Set<self>
674
+
675
+ def each: { ('a) -> void } -> self
676
+
677
+ def empty?: -> bool
678
+
679
+ def flatten: -> Set<any>
680
+
681
+ def intersect?: -> bool
682
+
683
+ def keep_if: { ('a) -> any } -> self
684
+
685
+ def size: -> Integer
686
+ def length: -> Integer
687
+
688
+ def merge: (_Iteratable<'a, any>) -> self
689
+
690
+ def subset?: (self) -> bool
691
+ def proper_subst?: (self) -> bool
692
+
693
+ def superset?: (self) -> bool
694
+ def proper_superset?: (self) -> bool
695
+
696
+ def replace: (_Iteratable<'a, any>) -> self
697
+
698
+ def reset: -> self
699
+
700
+ def select!: { ('a) -> any } -> self?
701
+
702
+ def subtract: (_Iteratable<'a, any>) -> self
703
+
704
+ def to_a: -> Array<'a>
705
+
706
+ include Enumerable<'a, self>
707
+ end
data/steep.gemspec CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.summary = %q{Gradual Typing for Ruby}
13
13
  spec.description = %q{Gradual Typing for Ruby}
14
14
  spec.homepage = "https://github.com/soutaro/steep"
15
+ spec.license = 'MIT'
15
16
 
16
17
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
18
  f.match(%r{^(test|spec|features)/})
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.0
4
+ version: 0.5.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: 2018-06-14 00:00:00.000000000 Z
11
+ date: 2018-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -134,6 +134,7 @@ files:
134
134
  - ".travis.yml"
135
135
  - CHANGELOG.md
136
136
  - Gemfile
137
+ - LICENSE
137
138
  - README.md
138
139
  - Rakefile
139
140
  - bin/console
@@ -146,6 +147,7 @@ files:
146
147
  - lib/steep/ast/buffer.rb
147
148
  - lib/steep/ast/location.rb
148
149
  - lib/steep/ast/method_type.rb
150
+ - lib/steep/ast/signature/alias.rb
149
151
  - lib/steep/ast/signature/class.rb
150
152
  - lib/steep/ast/signature/const.rb
151
153
  - lib/steep/ast/signature/env.rb
@@ -165,6 +167,7 @@ files:
165
167
  - lib/steep/ast/types/literal.rb
166
168
  - lib/steep/ast/types/name.rb
167
169
  - lib/steep/ast/types/nil.rb
170
+ - lib/steep/ast/types/proc.rb
168
171
  - lib/steep/ast/types/self.rb
169
172
  - lib/steep/ast/types/top.rb
170
173
  - lib/steep/ast/types/tuple.rb
@@ -211,12 +214,20 @@ files:
211
214
  - manual/annotations.md
212
215
  - sig/signature.rbi
213
216
  - sig/types.rbi
217
+ - smoke/alias/a.rb
218
+ - smoke/alias/a.rbi
219
+ - smoke/alias/b.rb
220
+ - smoke/alias/c.rb
214
221
  - smoke/and/a.rb
215
222
  - smoke/array/a.rb
216
223
  - smoke/array/b.rb
224
+ - smoke/array/c.rb
217
225
  - smoke/block/a.rb
218
226
  - smoke/block/a.rbi
219
227
  - smoke/block/b.rb
228
+ - smoke/block/c.rb
229
+ - smoke/block/c.rbi
230
+ - smoke/block/d.rb
220
231
  - smoke/case/a.rb
221
232
  - smoke/class/a.rb
222
233
  - smoke/class/a.rbi
@@ -226,6 +237,10 @@ files:
226
237
  - smoke/class/e.rb
227
238
  - smoke/class/f.rb
228
239
  - smoke/class/g.rb
240
+ - smoke/class/h.rb
241
+ - smoke/class/h.rbi
242
+ - smoke/class/i.rb
243
+ - smoke/class/i.rbi
229
244
  - smoke/const/a.rb
230
245
  - smoke/dstr/a.rb
231
246
  - smoke/ensure/a.rb
@@ -235,6 +250,9 @@ files:
235
250
  - smoke/extension/a.rbi
236
251
  - smoke/extension/b.rb
237
252
  - smoke/extension/c.rb
253
+ - smoke/extension/d.rb
254
+ - smoke/hash/a.rb
255
+ - smoke/hash/b.rb
238
256
  - smoke/hello/hello.rb
239
257
  - smoke/hello/hello.rbi
240
258
  - smoke/if/a.rb
@@ -243,11 +261,15 @@ files:
243
261
  - smoke/initialize/a.rb
244
262
  - smoke/initialize/a.rbi
245
263
  - smoke/kwbegin/a.rb
264
+ - smoke/lambda/a.rb
246
265
  - smoke/literal/a.rb
266
+ - smoke/literal/b.rb
267
+ - smoke/literal/literal_methods.rbi
247
268
  - smoke/map/a.rb
248
269
  - smoke/method/a.rb
249
270
  - smoke/method/a.rbi
250
271
  - smoke/method/b.rb
272
+ - smoke/method/c.rb
251
273
  - smoke/module/a.rb
252
274
  - smoke/module/a.rbi
253
275
  - smoke/module/b.rb
@@ -255,6 +277,9 @@ files:
255
277
  - smoke/module/d.rb
256
278
  - smoke/module/e.rb
257
279
  - smoke/module/f.rb
280
+ - smoke/regression/array.rb
281
+ - smoke/regression/hash.rb
282
+ - smoke/regression/set_divide.rb
258
283
  - smoke/rescue/a.rb
259
284
  - smoke/self/a.rb
260
285
  - smoke/self/a.rbi
@@ -267,7 +292,8 @@ files:
267
292
  - stdlib/builtin.rbi
268
293
  - steep.gemspec
269
294
  homepage: https://github.com/soutaro/steep
270
- licenses: []
295
+ licenses:
296
+ - MIT
271
297
  metadata: {}
272
298
  post_install_message:
273
299
  rdoc_options: []
@@ -285,7 +311,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
285
311
  version: '0'
286
312
  requirements: []
287
313
  rubyforge_project:
288
- rubygems_version: 2.7.3
314
+ rubygems_version: 2.7.6
289
315
  signing_key:
290
316
  specification_version: 4
291
317
  summary: Gradual Typing for Ruby