rbs 3.5.3 → 3.6.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/dependabot.yml +5 -1
  3. data/.github/workflows/ruby.yml +2 -18
  4. data/.github/workflows/windows.yml +26 -0
  5. data/.rubocop.yml +28 -1
  6. data/CHANGELOG.md +58 -0
  7. data/Rakefile +8 -2
  8. data/core/array.rbs +10 -10
  9. data/core/basic_object.rbs +4 -4
  10. data/core/builtin.rbs +4 -4
  11. data/core/dir.rbs +1 -1
  12. data/core/enumerable.rbs +17 -11
  13. data/core/enumerator/product.rbs +1 -1
  14. data/core/enumerator.rbs +9 -2
  15. data/core/errors.rbs +1 -1
  16. data/core/exception.rbs +1 -1
  17. data/core/fiber.rbs +1 -1
  18. data/core/file.rbs +1 -1
  19. data/core/global_variables.rbs +2 -2
  20. data/core/integer.rbs +4 -4
  21. data/core/kernel.rbs +69 -40
  22. data/core/method.rbs +98 -7
  23. data/core/module.rbs +3 -3
  24. data/core/proc.rbs +184 -23
  25. data/core/ractor.rbs +1 -1
  26. data/core/random.rbs +1 -1
  27. data/core/range.rbs +30 -0
  28. data/core/rbs/unnamed/env_class.rbs +7 -7
  29. data/core/rbs/unnamed/random.rbs +14 -14
  30. data/core/refinement.rbs +16 -26
  31. data/core/regexp.rbs +2 -2
  32. data/core/symbol.rbs +34 -26
  33. data/core/thread.rbs +8 -7
  34. data/core/trace_point.rbs +12 -12
  35. data/core/unbound_method.rbs +1 -1
  36. data/docs/syntax.md +26 -12
  37. data/ext/rbs_extension/lexer.c +1 -1
  38. data/ext/rbs_extension/lexer.h +5 -0
  39. data/ext/rbs_extension/lexer.re +1 -1
  40. data/ext/rbs_extension/lexstate.c +16 -0
  41. data/ext/rbs_extension/location.c +27 -39
  42. data/ext/rbs_extension/location.h +7 -2
  43. data/ext/rbs_extension/parser.c +119 -51
  44. data/ext/rbs_extension/ruby_objs.c +2 -1
  45. data/ext/rbs_extension/ruby_objs.h +1 -1
  46. data/lib/rbs/ast/declarations.rb +36 -0
  47. data/lib/rbs/ast/type_param.rb +71 -15
  48. data/lib/rbs/ast/visitor.rb +137 -0
  49. data/lib/rbs/buffer.rb +5 -0
  50. data/lib/rbs/cli/validate.rb +81 -7
  51. data/lib/rbs/cli.rb +3 -3
  52. data/lib/rbs/definition.rb +2 -1
  53. data/lib/rbs/definition_builder/ancestor_builder.rb +30 -4
  54. data/lib/rbs/definition_builder.rb +21 -6
  55. data/lib/rbs/environment_loader.rb +1 -1
  56. data/lib/rbs/errors.rb +8 -3
  57. data/lib/rbs/file_finder.rb +9 -12
  58. data/lib/rbs/location_aux.rb +2 -6
  59. data/lib/rbs/locator.rb +8 -5
  60. data/lib/rbs/prototype/rbi.rb +2 -1
  61. data/lib/rbs/prototype/runtime.rb +3 -2
  62. data/lib/rbs/sorter.rb +9 -6
  63. data/lib/rbs/test/type_check.rb +13 -0
  64. data/lib/rbs/types.rb +11 -0
  65. data/lib/rbs/validator.rb +2 -2
  66. data/lib/rbs/vendorer.rb +3 -3
  67. data/lib/rbs/version.rb +1 -1
  68. data/lib/rbs.rb +1 -0
  69. data/sig/declarations.rbs +6 -0
  70. data/sig/definition.rbs +1 -1
  71. data/sig/definition_builder.rbs +3 -1
  72. data/sig/errors.rbs +3 -2
  73. data/sig/file_finder.rbs +24 -2
  74. data/sig/location.rbs +0 -3
  75. data/sig/method_types.rbs +1 -1
  76. data/sig/sorter.rbs +1 -1
  77. data/sig/type_param.rbs +41 -9
  78. data/sig/types.rbs +12 -0
  79. data/sig/visitor.rbs +47 -0
  80. data/stdlib/csv/0/csv.rbs +44 -6
  81. data/stdlib/digest/0/digest.rbs +22 -28
  82. data/stdlib/ipaddr/0/ipaddr.rbs +1 -1
  83. data/stdlib/kconv/0/kconv.rbs +166 -0
  84. data/stdlib/net-http/0/net-http.rbs +2 -2
  85. data/stdlib/psych/0/store.rbs +1 -1
  86. data/stdlib/uri/0/ldap.rbs +1 -1
  87. data/stdlib/zlib/0/deflate.rbs +1 -1
  88. data/stdlib/zlib/0/gzip_reader.rbs +5 -1
  89. metadata +6 -2
data/lib/rbs/errors.rb CHANGED
@@ -35,7 +35,7 @@ module RBS
35
35
  return msg unless location.start_line == location.end_line
36
36
 
37
37
  indent = " " * location.start_column
38
- marker = "^" * (location.end_column - location.start_column)
38
+ marker = "^" * ([location.end_column - location.start_column, 1].max or raise)
39
39
 
40
40
  io = StringIO.new
41
41
  io.puts msg
@@ -68,18 +68,23 @@ module RBS
68
68
  attr_reader :type_name
69
69
  attr_reader :args
70
70
  attr_reader :params
71
+ attr_reader :type_params
71
72
  attr_reader :location
72
73
 
73
74
  def initialize(type_name:, args:, params:, location:)
74
75
  @type_name = type_name
75
76
  @args = args
76
- @params = params
77
+ @type_params = params
78
+ @params = params.map(&:name)
77
79
  @location = location
78
80
  super "#{Location.to_string location}: #{type_name} expects parameters [#{params.join(", ")}], but given args [#{args.join(", ")}]"
79
81
  end
80
82
 
81
83
  def self.check!(type_name:, args:, params:, location:)
82
- unless args.size == params.size
84
+ min_arity = params.count { _1.default_type.nil? }
85
+ max_arity = params.size
86
+
87
+ unless min_arity <= args.size && args.size <= max_arity
83
88
  raise new(type_name: type_name, args: args, params: params, location: location)
84
89
  end
85
90
  end
@@ -4,27 +4,24 @@ module RBS
4
4
  module FileFinder
5
5
  module_function
6
6
 
7
- def self.each_file(path, immediate:, skip_hidden:, &block)
7
+ def self.each_file(path, immediate: nil, skip_hidden:, &block)
8
8
  return enum_for((__method__ or raise), path, immediate: immediate, skip_hidden: skip_hidden) unless block
9
9
 
10
10
  case
11
11
  when path.file?
12
- if path.extname == ".rbs" || immediate
13
- yield path
14
- end
12
+ yield path
15
13
 
16
14
  when path.directory?
17
- if path.basename.to_s.start_with?("_")
18
- if skip_hidden
19
- unless immediate
20
- return
21
- end
15
+ paths = Pathname.glob("#{path}/**/*.rbs")
16
+
17
+ if skip_hidden
18
+ paths.select! do |child|
19
+ child.relative_path_from(path).ascend.drop(1).none? { _1.basename.to_s.start_with?("_") }
22
20
  end
23
21
  end
22
+ paths.sort_by!(&:to_s)
24
23
 
25
- path.children.sort.each do |child|
26
- each_file(child, immediate: false, skip_hidden: skip_hidden, &block)
27
- end
24
+ paths.each(&block)
28
25
  end
29
26
  end
30
27
  end
@@ -49,15 +49,11 @@ module RBS
49
49
  end
50
50
 
51
51
  def start_loc
52
- @start_loc ||= begin
53
- _start_loc || buffer.pos_to_loc(start_pos)
54
- end
52
+ @start_loc ||= buffer.pos_to_loc(start_pos)
55
53
  end
56
54
 
57
55
  def end_loc
58
- @end_loc ||= begin
59
- _end_loc || buffer.pos_to_loc(end_pos)
60
- end
56
+ @end_loc ||= buffer.pos_to_loc(end_pos)
61
57
  end
62
58
 
63
59
  def range
data/lib/rbs/locator.rb CHANGED
@@ -171,13 +171,16 @@ module RBS
171
171
  if test_loc(pos, location: type_param.location)
172
172
  array.unshift(type_param)
173
173
 
174
- if upper_bound = type_param.upper_bound
175
- find_in_type(pos, type: upper_bound, array: array) or
176
- find_in_loc(pos, location: type_param.location, array: array)
177
- else
178
- find_in_loc(pos, location: type_param.location, array: array)
174
+ if upper_bound = type_param.upper_bound_type
175
+ find_in_type(pos, type: upper_bound, array: array) and return true
179
176
  end
180
177
 
178
+ if default_type = type_param.default_type
179
+ find_in_type(pos, type: default_type, array: array) and return true
180
+ end
181
+
182
+ find_in_loc(pos, location: type_param.location, array: array)
183
+
181
184
  true
182
185
  else
183
186
  false
@@ -236,7 +236,8 @@ module RBS
236
236
  name: node.children[0],
237
237
  variance: variance || :invariant,
238
238
  location: nil,
239
- upper_bound: nil
239
+ upper_bound: nil,
240
+ default_type: nil
240
241
  )
241
242
  end
242
243
  else
@@ -332,8 +332,6 @@ module RBS
332
332
 
333
333
  public_instance_methods = mod.public_instance_methods.select {|name| target_method?(mod, instance: name) }
334
334
  unless public_instance_methods.empty?
335
- members << AST::Members::Public.new(location: nil)
336
-
337
335
  public_instance_methods.sort.each do |name|
338
336
  method = mod.instance_method(name)
339
337
  next if todo_object&.skip_instance_method?(module_name: module_name_absolute, method: method, accessibility: :public)
@@ -656,6 +654,9 @@ module RBS
656
654
  ast = RubyVM::AbstractSyntaxTree.of(method)
657
655
  rescue ArgumentError
658
656
  return # When the method is defined in eval
657
+ rescue RuntimeError => error
658
+ raise unless error.message.include?("prism")
659
+ return # When the method was compiled by prism
659
660
  end
660
661
 
661
662
  if ast && ast.type == :SCOPE
data/lib/rbs/sorter.rb CHANGED
@@ -17,18 +17,18 @@ module RBS
17
17
  buffer = Buffer.new(name: path, content: path.read)
18
18
  _, _, sigs = Parser.parse_signature(buffer)
19
19
 
20
- sigs.each do |m|
21
- sort_decl! m
20
+ sigs = sigs.map do |m|
21
+ sort_decl m
22
22
  end
23
23
 
24
24
  stdout.puts "Writing #{path}..."
25
25
  path.open('w') do |out|
26
26
  writer = RBS::Writer.new(out: out)
27
- writer.write sigs
27
+ writer.write _ = sigs
28
28
  end
29
29
  end
30
30
 
31
- def sort_decl!(decl)
31
+ def sort_decl(decl)
32
32
  case decl
33
33
  when Declarations::Class, Declarations::Module, Declarations::Interface
34
34
  partitioned = {
@@ -52,7 +52,8 @@ module RBS
52
52
  private_instance_methods: [],
53
53
  } #: partitioned
54
54
 
55
- decl.members.each { |m| sort_decl! m }
55
+ members = decl.members.map { |m| sort_decl m }
56
+ decl = decl.update(members: _ = members)
56
57
 
57
58
  visibility_annotated_members = [] #: Array[member]
58
59
 
@@ -188,7 +189,9 @@ module RBS
188
189
 
189
190
  members.push(*partitioned[:other_decls])
190
191
 
191
- decl.members.replace(_ = members)
192
+ decl.update(members: _ = members)
193
+ else
194
+ decl
192
195
  end
193
196
  end
194
197
  end
@@ -59,6 +59,8 @@ module RBS
59
59
  end
60
60
 
61
61
  def method_call(method_name, method_type, call, errors:)
62
+ return errors if method_type.type.is_a?(Types::UntypedFunction)
63
+
62
64
  args(method_name, method_type, method_type.type, call.method_call, errors, type_error: Errors::ArgumentTypeError, argument_error: Errors::ArgumentError)
63
65
  self.return(method_name, method_type, method_type.type, call.method_call, errors, return_error: Errors::ReturnTypeError)
64
66
 
@@ -150,6 +152,8 @@ module RBS
150
152
  end
151
153
 
152
154
  def zip_args(args, fun, &block)
155
+ return true if fun.is_a?(Types::UntypedFunction)
156
+
153
157
  case
154
158
  when args.empty?
155
159
  if fun.required_positionals.empty? && fun.trailing_positionals.empty? && fun.required_keywords.empty?
@@ -256,6 +260,13 @@ module RBS
256
260
  Test.call(val, IS_AP, instance_class)
257
261
  when Types::ClassInstance
258
262
  klass = get_class(type.name) or return false
263
+ if params = builder.env.normalized_module_class_entry(type.name.absolute!)&.type_params
264
+ args = AST::TypeParam.normalize_args(params, type.args)
265
+ unless args == type.args
266
+ type = Types::ClassInstance.new(name: type.name, args: args, location: type.location)
267
+ end
268
+ end
269
+
259
270
  case
260
271
  when klass == ::Array
261
272
  Test.call(val, IS_AP, klass) && each_sample(val).all? {|v| value(v, type.args[0]) }
@@ -355,6 +366,8 @@ module RBS
355
366
  fun = method_type.type
356
367
  take_has_rest = !!parameters.find { |(op, _)| op == :rest }
357
368
 
369
+ return true if fun.is_a?(Types::UntypedFunction)
370
+
358
371
  fun.required_positionals.each do
359
372
  op, _ = parameters.first
360
373
  return false if op.nil? || op == :keyreq || op == :key || op == :keyrest
data/lib/rbs/types.rb CHANGED
@@ -1278,6 +1278,17 @@ module RBS
1278
1278
  def return_to_s
1279
1279
  return_type.to_s(1)
1280
1280
  end
1281
+
1282
+ def ==(other)
1283
+ other.is_a?(UntypedFunction) && other.return_type == return_type
1284
+ end
1285
+
1286
+ alias eql? ==
1287
+
1288
+ def hash
1289
+ self.class.hash ^ return_type.hash
1290
+ end
1291
+
1281
1292
  end
1282
1293
 
1283
1294
  class Block
data/lib/rbs/validator.rb CHANGED
@@ -43,7 +43,7 @@ module RBS
43
43
  InvalidTypeApplicationError.check!(
44
44
  type_name: type.name,
45
45
  args: type.args,
46
- params: type_params.each.map(&:name),
46
+ params: type_params,
47
47
  location: type.location
48
48
  )
49
49
  end
@@ -125,7 +125,7 @@ module RBS
125
125
  # @type var each_child: ^(Symbol) { (Symbol) -> void } -> void
126
126
  each_child = -> (name, &block) do
127
127
  if param = params.find {|p| p.name == name }
128
- if b = param.upper_bound
128
+ if b = param.upper_bound_type
129
129
  b.free_variables.each do |tv|
130
130
  block[tv]
131
131
  end
data/lib/rbs/vendorer.rb CHANGED
@@ -31,7 +31,7 @@ module RBS
31
31
 
32
32
  if core_root = loader.core_root
33
33
  RBS.logger.info "Vendoring core RBSs in #{vendor_dir + "core"}..."
34
- FileFinder.each_file(core_root, immediate: false, skip_hidden: true) do |file_path|
34
+ FileFinder.each_file(core_root, skip_hidden: true) do |file_path|
35
35
  paths << [file_path, Pathname("core") + file_path.relative_path_from(core_root)]
36
36
  end
37
37
  end
@@ -43,7 +43,7 @@ module RBS
43
43
 
44
44
  RBS.logger.info "Vendoring #{lib.name}(#{spec.version}) RBSs in #{vendor_dir + dest_dir}..."
45
45
 
46
- FileFinder.each_file(path, skip_hidden: true, immediate: false) do |file_path|
46
+ FileFinder.each_file(path, skip_hidden: true) do |file_path|
47
47
  paths << [file_path, dest_dir + file_path.relative_path_from(path)]
48
48
  end
49
49
 
@@ -52,7 +52,7 @@ module RBS
52
52
 
53
53
  RBS.logger.info "Vendoring #{lib.name}(#{path.version}) RBSs in #{vendor_dir + dest_dir}..."
54
54
 
55
- FileFinder.each_file(path.path, skip_hidden: true, immediate: false) do |file_path|
55
+ FileFinder.each_file(path.path, skip_hidden: true) do |file_path|
56
56
  paths << [file_path, dest_dir + file_path.relative_path_from(path.path)]
57
57
  end
58
58
  else
data/lib/rbs/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RBS
4
- VERSION = "3.5.3"
4
+ VERSION = "3.6.0.pre.1"
5
5
  end
data/lib/rbs.rb CHANGED
@@ -22,6 +22,7 @@ require "rbs/ast/directives"
22
22
  require "rbs/ast/declarations"
23
23
  require "rbs/ast/members"
24
24
  require "rbs/ast/annotation"
25
+ require "rbs/ast/visitor"
25
26
  require "rbs/environment"
26
27
  require "rbs/environment/use_map"
27
28
  require "rbs/environment_loader"
data/sig/declarations.rbs CHANGED
@@ -77,6 +77,8 @@ module RBS
77
77
 
78
78
  def initialize: (name: TypeName, type_params: Array[TypeParam], members: Array[member], super_class: Super?, annotations: Array[Annotation], location: loc?, comment: Comment?) -> void
79
79
 
80
+ def update: (?name: TypeName, ?type_params: Array[TypeParam], ?members: Array[member], ?super_class: Super?, ?annotations: Array[Annotation], ?location: loc?, ?comment: Comment?) -> Declarations::Class
81
+
80
82
  include _HashEqual
81
83
  include _ToJson
82
84
  end
@@ -131,6 +133,8 @@ module RBS
131
133
 
132
134
  def initialize: (name: TypeName, type_params: Array[TypeParam], members: Array[member], location: loc?, annotations: Array[Annotation], self_types: Array[Self], comment: Comment?) -> void
133
135
 
136
+ def update: (?name: TypeName, ?type_params: Array[TypeParam], ?members: Array[member], ?location: loc?, ?annotations: Array[Annotation], ?self_types: Array[Self], ?comment: Comment?) -> Declarations::Module
137
+
134
138
  include _HashEqual
135
139
  include _ToJson
136
140
  end
@@ -160,6 +164,8 @@ module RBS
160
164
 
161
165
  def initialize: (name: TypeName, type_params: Array[TypeParam], members: Array[member], annotations: Array[Annotation], location: loc?, comment: Comment?) -> void
162
166
 
167
+ def update: (?name: TypeName, ?type_params: Array[TypeParam], ?members: Array[member], ?annotations: Array[Annotation], ?location: loc?, ?comment: Comment?) -> Declarations::Interface
168
+
163
169
  include MixinHelper
164
170
 
165
171
  include _HashEqual
data/sig/definition.rbs CHANGED
@@ -66,7 +66,7 @@ module RBS
66
66
  #
67
67
  def map_type: () { (Types::t) -> Types::t } -> Method
68
68
 
69
- def map_type_bound: () { (AST::TypeParam::bound) -> AST::TypeParam::bound } -> Method
69
+ def map_type_bound: () { (Types::t) -> Types::t } -> Method
70
70
 
71
71
  def map_method_type: () { (MethodType) -> MethodType } -> Method
72
72
 
@@ -116,6 +116,7 @@ module RBS
116
116
  Definition class_definition,
117
117
  MethodBuilder::Methods::Definition method_definition,
118
118
  Substitution subst,
119
+ Hash[Symbol, Definition::Method]? self_type_methods,
119
120
  defined_in: TypeName,
120
121
  ?implemented_in: TypeName?
121
122
  ) -> void
@@ -137,7 +138,8 @@ module RBS
137
138
  TypeName module_name,
138
139
  MethodBuilder::Methods module_methods,
139
140
  interface_methods interface_methods,
140
- Substitution subst
141
+ Substitution subst,
142
+ Hash[Symbol, Definition::Method]? self_type_methods,
141
143
  ) -> void
142
144
 
143
145
  # Updates `definition` with methods and variables of `type_name` that can be a module or a class
data/sig/errors.rbs CHANGED
@@ -60,11 +60,12 @@ module RBS
60
60
  attr_reader type_name: TypeName
61
61
  attr_reader args: Array[Types::t]
62
62
  attr_reader params: Array[Symbol]
63
+ attr_reader type_params: Array[AST::TypeParam]
63
64
  attr_reader location: Location[untyped, untyped]?
64
65
 
65
- def initialize: (type_name: TypeName, args: Array[Types::t], params: Array[Symbol], location: Location[untyped, untyped]?) -> void
66
+ def initialize: (type_name: TypeName, args: Array[Types::t], params: Array[AST::TypeParam], location: Location[untyped, untyped]?) -> void
66
67
 
67
- def self.check!: (type_name: TypeName, args: Array[Types::t], params: Array[Symbol], location: Location[untyped, untyped]?) -> void
68
+ def self.check!: (type_name: TypeName, args: Array[Types::t], params: Array[AST::TypeParam], location: Location[untyped, untyped]?) -> void
68
69
  end
69
70
 
70
71
  class RecursiveAncestorError < DefinitionError
data/sig/file_finder.rbs CHANGED
@@ -1,6 +1,28 @@
1
1
  module RBS
2
2
  module FileFinder
3
- def self?.each_file: (Pathname path, immediate: boolish, skip_hidden: boolish) { (Pathname) -> void } -> void
4
- | (Pathname path, immediate: boolish, skip_hidden: boolish) -> Enumerator[Pathname, void]
3
+ # Enumerate RBS files under path
4
+ #
5
+ # When `path` is a file, it yields the path.
6
+ #
7
+ # ```rb
8
+ # FileFinder.each_file(Pathname("foo.rbs")) {} # => yields `foo.rbs`
9
+ # ```
10
+ #
11
+ # When `path` is a directory, it yields all `.rbs` files under the directory, recursively.
12
+ #
13
+ # * Skips files under directory starting with `_`, if `skip_hidden` is `true`
14
+ # * Yields files under directory starting with `_` even if `skip_hidden` is true, when the `_` directory is given explicitly, and `immediate:` is `true`
15
+ #
16
+ # ```rb
17
+ # FileFinder.each_file(Pathname("sig"), skip_hidden: false) {} # => yields all `.rbs` files under `sig`
18
+ # FileFinder.each_file(Pathname("sig"), skip_hidden: true) {} # => yields all `.rbs` files under `sig`, skips `_` directories
19
+ #
20
+ # FileFinder.each_file(Pathname("_hidden"), skip_hidden: true) {} # => yields all `.rbs` files under `_hidden`, skips other `_` directories
21
+ # ```
22
+ #
23
+ # `immediate` keyword is unused and left for API compatibility.
24
+ #
25
+ def self?.each_file: (Pathname path, ?immediate: top, skip_hidden: boolish) { (Pathname) -> void } -> void
26
+ | (Pathname path, ?immediate: top, skip_hidden: boolish) -> Enumerator[Pathname, void]
5
27
  end
6
28
  end
data/sig/location.rbs CHANGED
@@ -99,9 +99,6 @@ module RBS
99
99
 
100
100
  private
101
101
 
102
- def _start_loc: () -> Buffer::loc?
103
- def _end_loc: () -> Buffer::loc?
104
-
105
102
  def _add_required_child: (RequiredChildKeys name, Integer start_pos, Integer end_pos) -> void
106
103
  def _add_optional_child: (OptionalChildKeys name, Integer start_pos, Integer end_pos) -> void
107
104
  def _add_optional_no_child: (OptionalChildKeys name) -> void
data/sig/method_types.rbs CHANGED
@@ -40,7 +40,7 @@ module RBS
40
40
  #
41
41
  def map_type: () { (Types::t) -> Types::t } -> MethodType
42
42
 
43
- def map_type_bound: () { (AST::TypeParam::bound) -> AST::TypeParam::bound } -> MethodType
43
+ def map_type_bound: () { (Types::t) -> Types::t } -> MethodType
44
44
 
45
45
  def each_type: () { (Types::t) -> void } -> void
46
46
  | () -> Enumerator[Types::t, void]
data/sig/sorter.rbs CHANGED
@@ -36,6 +36,6 @@ module RBS
36
36
  other_decls: Array[member]
37
37
  }
38
38
 
39
- def sort_decl!: (member decl) -> void
39
+ def sort_decl: (member decl) -> member
40
40
  end
41
41
  end
data/sig/type_param.rbs CHANGED
@@ -4,12 +4,13 @@ module RBS
4
4
  # Key
5
5
  # ^^^ name
6
6
  #
7
- # unchecked out Elem < _ToJson
8
- # ^^^^^^^^^ unchecked
9
- # ^^^ variance
10
- # ^^^^ name
11
- # ^^^^^^^^^ upper_bound
12
- type loc = Location[:name, :variance | :unchecked | :upper_bound]
7
+ # unchecked out Elem < _ToJson = untyped
8
+ # ^^^^^^^^^ unchecked
9
+ # ^^^ variance
10
+ # ^^^^ name
11
+ # ^^^^^^^^^ upper_bound
12
+ # ^^^^^^^^^ default
13
+ type loc = Location[:name, :variance | :unchecked | :upper_bound | :default]
13
14
 
14
15
  type variance = :invariant | :covariant | :contravariant
15
16
 
@@ -19,9 +20,13 @@ module RBS
19
20
  attr_reader variance: variance
20
21
  attr_reader location: loc?
21
22
 
22
- attr_reader upper_bound: bound?
23
+ %a{pure} def upper_bound: () -> bound?
23
24
 
24
- def initialize: (name: Symbol, variance: variance, upper_bound: bound?, location: loc?) -> void
25
+ attr_reader upper_bound_type: Types::t?
26
+
27
+ attr_reader default_type: Types::t?
28
+
29
+ def initialize: (name: Symbol, variance: variance, upper_bound: Types::t?, location: loc?, ?default_type: Types::t?) -> void
25
30
 
26
31
  include _ToJson
27
32
 
@@ -37,7 +42,7 @@ module RBS
37
42
 
38
43
  def unchecked?: () -> bool
39
44
 
40
- def map_type: () { (bound) -> bound } -> TypeParam
45
+ def map_type: () { (Types::t) -> Types::t } -> TypeParam
41
46
 
42
47
  # Helper function to resolve _class instance types_ to _type variables_.
43
48
  #
@@ -69,6 +74,33 @@ module RBS
69
74
  def self.rename: (Array[TypeParam], new_names: Array[Symbol]) -> Array[TypeParam]
70
75
 
71
76
  def to_s: () -> String
77
+
78
+ # Returns an application with respect to type params` default
79
+ #
80
+ def self.application: (Array[TypeParam], Array[Types::t]) -> Substitution?
81
+
82
+ # Returns an array of type args, that fills ommited types with the defaults
83
+ #
84
+ # ```rbs
85
+ # interface _Foo[T, S = untyped]
86
+ # end
87
+ # ```
88
+ #
89
+ # Normalizing type args with `_Foo` works as following:
90
+ #
91
+ # ```rbs
92
+ # _Foo[String] # => _Foo[String, untyped]
93
+ # _Foo[String, Integer] # => _Foo[String, Integer]
94
+ # _Foo # => _Foo (Omitting missing args)
95
+ # _Foo[String, Integer, untyped] # => _Foo[String, Integer, untyped] (Keeping extra args)
96
+ # ```
97
+ #
98
+ # Note that it allows iinvalid arities.
99
+ #
100
+ # * Missing args will be omitted
101
+ # * Extra args will be keeped
102
+ #
103
+ def self.normalize_args: (Array[TypeParam], Array[Types::t]) -> Array[Types::t]
72
104
  end
73
105
  end
74
106
  end
data/sig/types.rbs CHANGED
@@ -446,6 +446,12 @@ module RBS
446
446
  def has_classish_type?: () -> bool
447
447
 
448
448
  def with_nonreturn_void?: () -> bool
449
+
450
+ def ==: (untyped) -> bool
451
+
452
+ alias eql? ==
453
+
454
+ def hash: () -> Integer
449
455
  end
450
456
 
451
457
  # Function type without type checking arguments
@@ -489,6 +495,12 @@ module RBS
489
495
 
490
496
  # Returns `return_type.to_s(1)`
491
497
  def return_to_s: () -> String
498
+
499
+ def ==: (untyped) -> bool
500
+
501
+ alias eql? ==
502
+
503
+ def hash: () -> Integer
492
504
  end
493
505
 
494
506
  type function = Types::Function | Types::UntypedFunction
data/sig/visitor.rbs ADDED
@@ -0,0 +1,47 @@
1
+ module RBS
2
+ module AST
3
+ class Visitor
4
+ def visit_all: (Enumerable[(Members::Base | Declarations::Base)] nodes) -> void
5
+
6
+ def visit: ((Members::Base | Declarations::Base) node) -> void
7
+
8
+ def visit_declaration_global: (Declarations::Global node) -> void
9
+
10
+ def visit_declaration_class: (Declarations::Class node) -> void
11
+
12
+ def visit_declaration_module: (Declarations::Module node) -> void
13
+
14
+ def visit_declaration_constant: (Declarations::Constant node) -> void
15
+
16
+ def visit_declaration_type_alias: (Declarations::TypeAlias node) -> void
17
+
18
+ def visit_declaration_interface: (Declarations::Interface node) -> void
19
+
20
+ def visit_member_alias: (Members::Alias node) -> void
21
+
22
+ def visit_member_class_instance_variable: (Members::ClassInstanceVariable node) -> void
23
+
24
+ def visit_member_class_variable: (Members::ClassVariable node) -> void
25
+
26
+ def visit_member_instance_variable: (Members::InstanceVariable node) -> void
27
+
28
+ def visit_member_private: (Members::Private node) -> void
29
+
30
+ def visit_member_public: (Members::Public node) -> void
31
+
32
+ def visit_member_method_definition: (Members::MethodDefinition node) -> void
33
+
34
+ def visit_member_attr_reader: (Members::AttrReader node) -> void
35
+
36
+ def visit_member_attr_writer: (Members::AttrWriter node) -> void
37
+
38
+ def visit_member_attr_accessor: (Members::AttrAccessor node) -> void
39
+
40
+ def visit_member_include: (Members::Include node) -> void
41
+
42
+ def visit_member_prepend: (Members::Prepend node) -> void
43
+
44
+ def visit_member_extend: (Members::Extend node) -> void
45
+ end
46
+ end
47
+ end