rbs 0.17.0 → 0.20.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f458be96f0cfc3e45e51bb77f4d42aafba7f1fee62e0ed8695eb6a95b85189b2
4
- data.tar.gz: 9b84c8860182155f4e5979e668a953d1b8191754f01c6443d549fc14b5be1908
3
+ metadata.gz: 7d0358484cf9cfd6a58aba4115025628e9af481fbeb11079ba189e387486bd85
4
+ data.tar.gz: 01fa1f2883a0faa043d5116118e6d4bbebb33dc3290d32d9404935817e589643
5
5
  SHA512:
6
- metadata.gz: f0c7616abdb3a3d4e08212014aebad858e113acf265641e4f657b2d48b9e20ec8ac7744a18f90459086be39953eb7ebef9d32acd3b22362e31d6e12e83251baf
7
- data.tar.gz: ee12553e0611d2b8826d9687ab63fcc38bfb67435bcf537950b31ef6070c26d85fcf8d956ccc1285072e6513facdbd43521935ae9372a11cae6f100e16691084
6
+ metadata.gz: 7a16ce63cf0d28ba0834f7a702767aa5dcb7440a0ef83d00f443e6877977abdb751c6e7816266d45af44cbe21b3eafc7a563edfdf678662a8412f4d8b758d80c
7
+ data.tar.gz: 45e237d7de22114e7f6d22f138b2850645067993c9577581842464bec7d06937a7427d13d9821d93088008f0ea838b6e475b43725d3b16b60c0e3c821b7fef93
@@ -2,6 +2,34 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.20.1 (2020-12-06)
6
+
7
+ * Make the order of RBS load reproducible ([#508](https://github.com/ruby/rbs/pull/508))
8
+
9
+ ## 0.20.0 (2020-12-06)
10
+
11
+ * Signature updates for `TSort`, `DBM`, `Time`, and `Hash` ([#496](https://github.com/ruby/rbs/pull/496), [#497](https://github.com/ruby/rbs/pull/497), [#499](https://github.com/ruby/rbs/pull/499), [#507](https://github.com/ruby/rbs/pull/507))
12
+ * Add _singleton attribute_ syntax ([#502](https://github.com/ruby/rbs/pull/502), [#506](https://github.com/ruby/rbs/pull/506), [#505](https://github.com/ruby/rbs/pull/505))
13
+ * Proc types with blocks ([#503](https://github.com/ruby/rbs/pull/503))
14
+ * Add support for escape sequences in string literal types ([#501](https://github.com/ruby/rbs/pull/501))
15
+ * Fix runtime type checking of blocks with keyword args ([#500](https://github.com/ruby/rbs/pull/500))
16
+
17
+ ## 0.19.0 (2020-12-02)
18
+
19
+ * Signature updates for `Monitor` and File ([#485](https://github.com/ruby/rbs/pull/485), [#495](https://github.com/ruby/rbs/pull/495))
20
+
21
+ ## 0.18.1 (2020-12-01)
22
+
23
+ * Fix `EnvironmentWalker#each_type_name` ([#494](https://github.com/ruby/rbs/pull/494))
24
+
25
+ ## 0.18.0 (2020-12-01)
26
+
27
+ * Signature updates for `YAML`, `ObjectSpace`, and `Singleton` ([#408](https://github.com/ruby/rbs/pull/408), [#477](https://github.com/ruby/rbs/pull/477), [#482](https://github.com/ruby/rbs/pull/482))
28
+ * `prototype rb` improvements ([#492](https://github.com/ruby/rbs/pull/492), [#487](https://github.com/ruby/rbs/pull/487), [#486](https://github.com/ruby/rbs/pull/486), [#481](https://github.com/ruby/rbs/pull/481))
29
+ * Runtime type checker improvements ([#488](https://github.com/ruby/rbs/pull/488), [#489](https://github.com/ruby/rbs/pull/489), [#490](https://github.com/ruby/rbs/pull/490))
30
+ * Update `DependencyWalker` API to receive _Node_ objects instead of `TypeName` ([#484](https://github.com/ruby/rbs/pull/484))
31
+ * Assume encoding of RBS files to be UTF-8 ([#493](https://github.com/ruby/rbs/pull/493))
32
+
5
33
  ## 0.17.0 (2020-11-14)
6
34
 
7
35
  * Signature updates for `Enumerable`, `Hash`, and `TSort` ([#462](https://github.com/ruby/rbs/pull/462), [#468](https://github.com/ruby/rbs/pull/468), [#471](https://github.com/ruby/rbs/pull/471), [#472](https://github.com/ruby/rbs/pull/472), [#473](https://github.com/ruby/rbs/pull/473), [#474](https://github.com/ruby/rbs/pull/474))
data/Rakefile CHANGED
@@ -36,6 +36,11 @@ task :validate => :parser do
36
36
  lib << "bigdecimal"
37
37
  end
38
38
 
39
+ if lib == ["yaml"]
40
+ lib << "dbm"
41
+ lib << "pstore"
42
+ end
43
+
39
44
  sh "#{ruby} #{rbs} #{lib.map {|l| "-r #{l}"}.join(" ")} validate --silent"
40
45
  end
41
46
  end
@@ -192,10 +192,6 @@ class File < IO
192
192
  #
193
193
  def self.exist?: (string | _ToPath | IO file_name) -> bool
194
194
 
195
- # Deprecated method. Don't use.
196
- #
197
- alias self.exists? self.exist?
198
-
199
195
  # Converts a pathname to an absolute pathname. Relative paths are referenced
200
196
  # from the current working directory of the process unless `dir_string` is
201
197
  # given, in which case it will be used as the starting point. The given pathname
@@ -563,8 +563,6 @@ class Hash[unchecked out K, unchecked out V] < Object
563
563
  #
564
564
  alias include? has_key?
565
565
 
566
- def index: (V) -> K?
567
-
568
566
  # Return the contents of this hash as a string.
569
567
  #
570
568
  # h = { "c" => 300, "a" => 100, "d" => 400, "c" => 300 }
@@ -615,7 +613,7 @@ class Hash[unchecked out K, unchecked out V] < Object
615
613
  # h.key(300) #=> "c"
616
614
  # h.key(999) #=> nil
617
615
  #
618
- alias key index
616
+ def key: (V) -> K?
619
617
 
620
618
  # Returns `true` if the given key is present in *hsh*.
621
619
  #
@@ -0,0 +1,98 @@
1
+ # The ObjectSpace module contains a number of routines that interact with the
2
+ # garbage collection facility and allow you to traverse all living objects with
3
+ # an iterator.
4
+ #
5
+ # ObjectSpace also provides support for object finalizers, procs that will be
6
+ # called when a specific object is about to be destroyed by garbage collection.
7
+ #
8
+ # require 'objspace'
9
+ #
10
+ # a = "A"
11
+ # b = "B"
12
+ #
13
+ # ObjectSpace.define_finalizer(a, proc {|id| puts "Finalizer one on #{id}" })
14
+ # ObjectSpace.define_finalizer(b, proc {|id| puts "Finalizer two on #{id}" })
15
+ #
16
+ # *produces:*
17
+ #
18
+ # Finalizer two on 537763470
19
+ # Finalizer one on 537763480
20
+ module ObjectSpace
21
+ def self._id2ref: (Integer id) -> untyped
22
+
23
+ # Counts all objects grouped by type.
24
+ #
25
+ # It returns a hash, such as:
26
+ # {
27
+ # :TOTAL=>10000,
28
+ # :FREE=>3011,
29
+ # :T_OBJECT=>6,
30
+ # :T_CLASS=>404,
31
+ # # ...
32
+ # }
33
+ #
34
+ # The contents of the returned hash are implementation specific. It may be
35
+ # changed in future.
36
+ #
37
+ # The keys starting with `:T_` means live objects. For example, `:T_ARRAY` is
38
+ # the number of arrays. `:FREE` means object slots which is not used now.
39
+ # `:TOTAL` means sum of above.
40
+ #
41
+ # If the optional argument `result_hash` is given, it is overwritten and
42
+ # returned. This is intended to avoid probe effect.
43
+ #
44
+ # h = {}
45
+ # ObjectSpace.count_objects(h)
46
+ # puts h
47
+ # # => { :TOTAL=>10000, :T_CLASS=>158280, :T_MODULE=>20672, :T_STRING=>527249 }
48
+ #
49
+ # This method is only expected to work on C Ruby.
50
+ #
51
+ def self.count_objects: (?Hash[Symbol, Integer] result_hash) -> Hash[Symbol, Integer]
52
+
53
+ # Adds *aProc* as a finalizer, to be called after *obj* was destroyed. The
54
+ # object ID of the *obj* will be passed as an argument to *aProc*. If *aProc* is
55
+ # a lambda or method, make sure it can be called with a single argument.
56
+ #
57
+ def self.define_finalizer: (untyped obj, ^(Integer id) -> void aProc) -> [ Integer, Proc ]
58
+ | (untyped obj) { (Integer id) -> void } -> [ Integer, Proc ]
59
+
60
+ # Calls the block once for each living, nonimmediate object in this Ruby
61
+ # process. If *module* is specified, calls the block for only those classes or
62
+ # modules that match (or are a subclass of) *module*. Returns the number of
63
+ # objects found. Immediate objects (`Fixnum`s, `Symbol`s `true`, `false`, and
64
+ # `nil`) are never returned. In the example below, #each_object returns both the
65
+ # numbers we defined and several constants defined in the Math module.
66
+ #
67
+ # If no block is given, an enumerator is returned instead.
68
+ #
69
+ # a = 102.7
70
+ # b = 95 # Won't be returned
71
+ # c = 12345678987654321
72
+ # count = ObjectSpace.each_object(Numeric) {|x| p x }
73
+ # puts "Total count: #{count}"
74
+ #
75
+ # *produces:*
76
+ #
77
+ # 12345678987654321
78
+ # 102.7
79
+ # 2.71828182845905
80
+ # 3.14159265358979
81
+ # 2.22044604925031e-16
82
+ # 1.7976931348623157e+308
83
+ # 2.2250738585072e-308
84
+ # Total count: 7
85
+ #
86
+ def self.each_object: (?Module `module`) -> Enumerator[untyped, Integer]
87
+ | (?Module `module`) { (untyped obj) -> void } -> Integer
88
+
89
+ def self.garbage_collect: (?full_mark: bool, ?immediate_mark: bool, ?immediate_sweep: bool) -> void
90
+
91
+ # Removes all finalizers for *obj*.
92
+ #
93
+ def self.undefine_finalizer: [X] (X obj) -> X
94
+
95
+ private
96
+
97
+ def garbage_collect: (?full_mark: bool, ?immediate_mark: bool, ?immediate_sweep: bool) -> void
98
+ end
@@ -757,18 +757,6 @@ class Time < Object
757
757
  #
758
758
  def subsec: () -> Numeric
759
759
 
760
- # Returns a new Time object, one second later than *time*. Time#succ is obsolete
761
- # since 1.9.2 for time is not a discrete value.
762
- #
763
- # t = Time.now #=> 2007-11-19 08:23:57 -0600
764
- # t.succ #=> 2007-11-19 08:23:58 -0600
765
- #
766
- # Use instead `time + 1`
767
- #
768
- # t + 1 #=> 2007-11-19 08:23:58 -0600
769
- #
770
- def succ: () -> Time
771
-
772
760
  # Returns `true` if *time* represents Sunday.
773
761
  #
774
762
  # t = Time.local(1990, 4, 1) #=> 1990-04-01 00:00:00 -0600
@@ -216,31 +216,34 @@ module RBS
216
216
  module Attribute
217
217
  attr_reader :name
218
218
  attr_reader :type
219
+ attr_reader :kind
219
220
  attr_reader :ivar_name
220
221
  attr_reader :annotations
221
222
  attr_reader :location
222
223
  attr_reader :comment
223
224
 
224
- def initialize(name:, type:, ivar_name:, annotations:, location:, comment:)
225
+ def initialize(name:, type:, ivar_name:, kind:, annotations:, location:, comment:)
225
226
  @name = name
226
227
  @type = type
227
228
  @ivar_name = ivar_name
228
229
  @annotations = annotations
229
230
  @location = location
230
231
  @comment = comment
232
+ @kind = kind
231
233
  end
232
234
 
233
235
  def ==(other)
234
236
  other.is_a?(self.class) &&
235
237
  other.name == name &&
236
238
  other.type == type &&
237
- other.ivar_name == ivar_name
239
+ other.ivar_name == ivar_name &&
240
+ other.kind == kind
238
241
  end
239
242
 
240
243
  alias eql? ==
241
244
 
242
245
  def hash
243
- self.class.hash ^ name.hash ^ type.hash ^ ivar_name.hash
246
+ self.class.hash ^ name.hash ^ type.hash ^ ivar_name.hash ^ kind.hash
244
247
  end
245
248
  end
246
249
 
@@ -253,6 +256,7 @@ module RBS
253
256
  name: name,
254
257
  type: type,
255
258
  ivar_name: ivar_name,
259
+ kind: kind,
256
260
  annotations: annotations,
257
261
  location: location,
258
262
  comment: comment
@@ -269,6 +273,7 @@ module RBS
269
273
  name: name,
270
274
  type: type,
271
275
  ivar_name: ivar_name,
276
+ kind: kind,
272
277
  annotations: annotations,
273
278
  location: location,
274
279
  comment: comment
@@ -285,6 +290,7 @@ module RBS
285
290
  name: name,
286
291
  type: type,
287
292
  ivar_name: ivar_name,
293
+ kind: kind,
288
294
  annotations: annotations,
289
295
  location: location,
290
296
  comment: comment
@@ -558,7 +558,7 @@ module RBS
558
558
  )
559
559
  end
560
560
 
561
- unless array.all? {|pair| pair[1] == :public}
561
+ unless array.all? {|pair| pair[1] == :public }
562
562
  raise InconsistentMethodVisibilityError.new(
563
563
  type_name: type_name,
564
564
  method_name: method_name,
@@ -658,65 +658,12 @@ module RBS
658
658
  each_member_with_accessibility(d.decl.members) do |member, accessibility|
659
659
  case member
660
660
  when AST::Members::AttrReader, AST::Members::AttrAccessor, AST::Members::AttrWriter
661
- name = member.name
662
- type = member.type
663
-
664
- ivar_name = case member.ivar_name
665
- when false
666
- nil
667
- else
668
- member.ivar_name || :"@#{member.name}"
669
- end
670
-
671
- if member.is_a?(AST::Members::AttrReader) || member.is_a?(AST::Members::AttrAccessor)
672
- definition.methods[name] = Definition::Method.new(
673
- super_method: nil,
674
- defs: [
675
- Definition::Method::TypeDef.new(
676
- type: MethodType.new(
677
- type_params: [],
678
- type: Types::Function.empty(type),
679
- block: nil,
680
- location: nil
681
- ),
682
- member: member,
683
- defined_in: type_name,
684
- implemented_in: type_name
685
- )
686
- ],
687
- accessibility: accessibility,
688
- alias_of: nil
689
- )
690
- end
691
-
692
- if member.is_a?(AST::Members::AttrWriter) || member.is_a?(AST::Members::AttrAccessor)
693
- definition.methods[:"#{name}="] = Definition::Method.new(
694
- super_method: nil,
695
- defs: [
696
- Definition::Method::TypeDef.new(
697
- type: MethodType.new(
698
- type_params: [],
699
- type: Types::Function.empty(type).update(
700
- required_positionals: [Types::Function::Param.new(name: name, type: type)]
701
- ),
702
- block: nil,
703
- location: nil
704
- ),
705
- member: member,
706
- defined_in: type_name,
707
- implemented_in: type_name
708
- ),
709
- ],
710
- accessibility: accessibility,
711
- alias_of: nil
712
- )
713
- end
714
-
715
- if ivar_name
716
- definition.instance_variables[ivar_name] = Definition::Variable.new(
717
- parent_variable: nil,
718
- type: type,
719
- declared_in: type_name
661
+ if member.kind == :instance
662
+ build_attribute(
663
+ type_name: type_name,
664
+ definition: definition,
665
+ member: member,
666
+ accessibility: accessibility
720
667
  )
721
668
  end
722
669
 
@@ -982,8 +929,16 @@ module RBS
982
929
  end
983
930
 
984
931
  entry.decls.each do |d|
985
- each_member_with_accessibility(d.decl.members) do |member, _|
932
+ each_member_with_accessibility(d.decl.members) do |member, accessibility|
986
933
  case member
934
+ when AST::Members::AttrReader, AST::Members::AttrAccessor, AST::Members::AttrWriter
935
+ if member.kind == :singleton
936
+ build_attribute(type_name: type_name,
937
+ definition: definition,
938
+ member: member,
939
+ accessibility: accessibility)
940
+ end
941
+
987
942
  when AST::Members::ClassInstanceVariable
988
943
  definition.instance_variables[member.name] = Definition::Variable.new(
989
944
  parent_variable: nil,
@@ -1004,6 +959,70 @@ module RBS
1004
959
  end
1005
960
  end
1006
961
 
962
+ def build_attribute(type_name:, definition:, member:, accessibility:)
963
+ name = member.name
964
+ type = member.type
965
+
966
+ ivar_name = case member.ivar_name
967
+ when false
968
+ nil
969
+ else
970
+ member.ivar_name || :"@#{member.name}"
971
+ end
972
+
973
+ if member.is_a?(AST::Members::AttrReader) || member.is_a?(AST::Members::AttrAccessor)
974
+ definition.methods[name] = Definition::Method.new(
975
+ super_method: nil,
976
+ defs: [
977
+ Definition::Method::TypeDef.new(
978
+ type: MethodType.new(
979
+ type_params: [],
980
+ type: Types::Function.empty(type),
981
+ block: nil,
982
+ location: nil
983
+ ),
984
+ member: member,
985
+ defined_in: type_name,
986
+ implemented_in: type_name
987
+ )
988
+ ],
989
+ accessibility: accessibility,
990
+ alias_of: nil
991
+ )
992
+ end
993
+
994
+ if member.is_a?(AST::Members::AttrWriter) || member.is_a?(AST::Members::AttrAccessor)
995
+ definition.methods[:"#{name}="] = Definition::Method.new(
996
+ super_method: nil,
997
+ defs: [
998
+ Definition::Method::TypeDef.new(
999
+ type: MethodType.new(
1000
+ type_params: [],
1001
+ type: Types::Function.empty(type).update(
1002
+ required_positionals: [Types::Function::Param.new(name: name, type: type)]
1003
+ ),
1004
+ block: nil,
1005
+ location: nil
1006
+ ),
1007
+ member: member,
1008
+ defined_in: type_name,
1009
+ implemented_in: type_name
1010
+ ),
1011
+ ],
1012
+ accessibility: accessibility,
1013
+ alias_of: nil
1014
+ )
1015
+ end
1016
+
1017
+ if ivar_name
1018
+ definition.instance_variables[ivar_name] = Definition::Variable.new(
1019
+ parent_variable: nil,
1020
+ type: type,
1021
+ declared_in: type_name
1022
+ )
1023
+ end
1024
+ end
1025
+
1007
1026
  def merge_definitions(type_name, pairs, entry:, self_type:, ancestors:)
1008
1027
  Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
1009
1028
  pairs.reverse_each do |ancestor, current_definition|
@@ -349,6 +349,7 @@ module RBS
349
349
  AST::Members::AttrAccessor.new(
350
350
  name: member.name,
351
351
  type: absolute_type(resolver, member.type, context: context),
352
+ kind: member.kind,
352
353
  annotations: member.annotations,
353
354
  comment: member.comment,
354
355
  location: member.location,
@@ -358,6 +359,7 @@ module RBS
358
359
  AST::Members::AttrReader.new(
359
360
  name: member.name,
360
361
  type: absolute_type(resolver, member.type, context: context),
362
+ kind: member.kind,
361
363
  annotations: member.annotations,
362
364
  comment: member.comment,
363
365
  location: member.location,
@@ -367,6 +369,7 @@ module RBS
367
369
  AST::Members::AttrWriter.new(
368
370
  name: member.name,
369
371
  type: absolute_type(resolver, member.type, context: context),
372
+ kind: member.kind,
370
373
  annotations: member.annotations,
371
374
  comment: member.comment,
372
375
  location: member.location,