rbs 3.8.0 → 3.9.0.dev.1

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.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +3 -3
  3. data/.github/workflows/dependabot.yml +1 -1
  4. data/.github/workflows/ruby.yml +7 -7
  5. data/.github/workflows/typecheck.yml +2 -0
  6. data/.github/workflows/windows.yml +15 -0
  7. data/.rubocop.yml +20 -1
  8. data/CHANGELOG.md +14 -0
  9. data/Rakefile +5 -2
  10. data/config.yml +6 -0
  11. data/core/data.rbs +1 -1
  12. data/core/enumerator.rbs +14 -2
  13. data/core/exception.rbs +148 -39
  14. data/core/gc.rbs +2 -2
  15. data/core/io.rbs +7 -3
  16. data/core/kernel.rbs +58 -16
  17. data/core/method.rbs +2 -2
  18. data/core/module.rbs +3 -3
  19. data/core/proc.rbs +2 -2
  20. data/core/ractor.rbs +4 -1
  21. data/core/rbs/unnamed/argf.rbs +3 -3
  22. data/core/regexp.rbs +4 -2
  23. data/core/ruby_vm.rbs +8 -8
  24. data/core/rubygems/version.rbs +2 -2
  25. data/core/string.rbs +1 -1
  26. data/core/time.rbs +1 -1
  27. data/core/unbound_method.rbs +1 -1
  28. data/docs/syntax.md +10 -5
  29. data/ext/rbs_extension/extconf.rb +2 -1
  30. data/ext/rbs_extension/location.c +32 -10
  31. data/ext/rbs_extension/location.h +4 -3
  32. data/ext/rbs_extension/main.c +22 -1
  33. data/ext/rbs_extension/parser.c +144 -136
  34. data/ext/rbs_extension/parserstate.c +40 -9
  35. data/ext/rbs_extension/parserstate.h +6 -4
  36. data/include/rbs/ruby_objs.h +6 -6
  37. data/include/rbs/util/rbs_constant_pool.h +219 -0
  38. data/lib/rbs/ast/declarations.rb +9 -4
  39. data/lib/rbs/ast/directives.rb +10 -0
  40. data/lib/rbs/ast/members.rb +2 -0
  41. data/lib/rbs/ast/type_param.rb +2 -2
  42. data/lib/rbs/cli/validate.rb +1 -0
  43. data/lib/rbs/cli.rb +3 -3
  44. data/lib/rbs/collection/config/lockfile_generator.rb +28 -7
  45. data/lib/rbs/collection/sources/rubygems.rb +1 -1
  46. data/lib/rbs/definition.rb +46 -31
  47. data/lib/rbs/definition_builder/ancestor_builder.rb +2 -0
  48. data/lib/rbs/definition_builder.rb +86 -30
  49. data/lib/rbs/environment.rb +33 -18
  50. data/lib/rbs/errors.rb +23 -0
  51. data/lib/rbs/locator.rb +2 -0
  52. data/lib/rbs/method_type.rb +2 -0
  53. data/lib/rbs/parser_aux.rb +38 -1
  54. data/lib/rbs/subtractor.rb +3 -3
  55. data/lib/rbs/test/hook.rb +2 -2
  56. data/lib/rbs/test/type_check.rb +7 -5
  57. data/lib/rbs/types.rb +44 -5
  58. data/lib/rbs/unit_test/spy.rb +4 -2
  59. data/lib/rbs/unit_test/type_assertions.rb +17 -11
  60. data/lib/rbs/validator.rb +4 -0
  61. data/lib/rbs/version.rb +1 -1
  62. data/lib/rbs/writer.rb +10 -5
  63. data/lib/rbs.rb +1 -0
  64. data/rbs.gemspec +1 -1
  65. data/sig/collection/config/lockfile_generator.rbs +1 -1
  66. data/sig/declarations.rbs +10 -3
  67. data/sig/definition.rbs +67 -14
  68. data/sig/definition_builder.rbs +17 -3
  69. data/sig/directives.rbs +17 -1
  70. data/sig/environment.rbs +2 -0
  71. data/sig/errors.rbs +16 -0
  72. data/sig/parser.rbs +5 -1
  73. data/sig/subtractor.rbs +1 -1
  74. data/sig/test/type_check.rbs +2 -2
  75. data/sig/type_param.rbs +1 -1
  76. data/sig/types.rbs +3 -0
  77. data/sig/unit_test/spy.rbs +2 -0
  78. data/sig/unit_test/type_assertions.rbs +2 -0
  79. data/sig/validator.rbs +4 -0
  80. data/sig/writer.rbs +1 -1
  81. data/src/ruby_objs.c +12 -6
  82. data/src/util/rbs_constant_pool.c +342 -0
  83. data/stdlib/cgi/0/core.rbs +10 -0
  84. data/stdlib/json/0/json.rbs +52 -50
  85. data/stdlib/monitor/0/monitor.rbs +13 -4
  86. data/stdlib/net-http/0/net-http.rbs +2 -2
  87. data/stdlib/openssl/0/openssl.rbs +73 -73
  88. data/stdlib/resolv/0/resolv.rbs +8 -8
  89. data/stdlib/socket/0/addrinfo.rbs +1 -1
  90. data/stdlib/socket/0/unix_socket.rbs +4 -2
  91. data/stdlib/stringio/0/stringio.rbs +1 -1
  92. data/stdlib/uri/0/common.rbs +17 -0
  93. metadata +4 -7
  94. data/templates/include/rbs/constants.h.erb +0 -20
  95. data/templates/include/rbs/ruby_objs.h.erb +0 -10
  96. data/templates/src/constants.c.erb +0 -36
  97. data/templates/src/ruby_objs.c.erb +0 -27
  98. data/templates/template.rb +0 -122
@@ -22,8 +22,8 @@ module RBS
22
22
  end
23
23
 
24
24
  def overloaded_call(method, method_name, call, errors:)
25
- es = method.method_types.map do |method_type|
26
- es = method_call(method_name, method_type, call, errors: [])
25
+ es = method.defs.map do |type_def|
26
+ es = method_call(method_name, type_def.type, call, errors: [], annotations: type_def.annotations)
27
27
 
28
28
  if es.empty?
29
29
  return errors
@@ -58,11 +58,11 @@ module RBS
58
58
  errors
59
59
  end
60
60
 
61
- def method_call(method_name, method_type, call, errors:)
61
+ def method_call(method_name, method_type, call, errors:, annotations: [])
62
62
  return errors if method_type.type.is_a?(Types::UntypedFunction)
63
63
 
64
64
  args(method_name, method_type, method_type.type, call.method_call, errors, type_error: Errors::ArgumentTypeError, argument_error: Errors::ArgumentError)
65
- self.return(method_name, method_type, method_type.type, call.method_call, errors, return_error: Errors::ReturnTypeError)
65
+ self.return(method_name, method_type, method_type.type, call.method_call, errors, return_error: Errors::ReturnTypeError, annotations:)
66
66
 
67
67
  if method_type.block
68
68
  case
@@ -106,8 +106,10 @@ module RBS
106
106
  end
107
107
  end
108
108
 
109
- def return(method_name, method_type, fun, call, errors, return_error:)
109
+ def return(method_name, method_type, fun, call, errors, return_error:, annotations: [])
110
110
  if call.return?
111
+ return if Test.call(call.return_value, IS_AP, NilClass) && annotations.find { |a| a.string == "implicitly-returns-nil" }
112
+
111
113
  unless value(call.return_value, fun.return_type)
112
114
  errors << return_error.new(klass: self_class,
113
115
  method_name: method_name,
data/lib/rbs/types.rb CHANGED
@@ -15,7 +15,7 @@ module RBS
15
15
  end
16
16
 
17
17
  module NoTypeName
18
- def map_type_name
18
+ def map_type_name(&)
19
19
  self
20
20
  end
21
21
  end
@@ -107,10 +107,16 @@ module RBS
107
107
  class Bool < Base; end
108
108
  class Void < Base; end
109
109
  class Any < Base
110
+ def initialize(location:, todo: false)
111
+ super(location: location)
112
+ todo! if todo
113
+ end
114
+
110
115
  def to_s(level=0)
111
116
  @string || "untyped"
112
117
  end
113
118
 
119
+ # @deprecated: this method is now called from the constructor, do not call it from outside
114
120
  def todo!
115
121
  @string = '__todo__'
116
122
  self
@@ -229,7 +235,7 @@ module RBS
229
235
 
230
236
  include EmptyEachType
231
237
 
232
- def map_type_name
238
+ def map_type_name(&)
233
239
  ClassSingleton.new(
234
240
  name: yield(name, location, self),
235
241
  location: location
@@ -323,6 +329,8 @@ module RBS
323
329
  end
324
330
 
325
331
  def sub(s)
332
+ return self if s.empty?
333
+
326
334
  self.class.new(name: name,
327
335
  args: args.map {|ty| ty.sub(s) },
328
336
  location: location)
@@ -365,6 +373,8 @@ module RBS
365
373
  end
366
374
 
367
375
  def sub(s)
376
+ return self if s.empty?
377
+
368
378
  self.class.new(name: name,
369
379
  args: args.map {|ty| ty.sub(s) },
370
380
  location: location)
@@ -407,6 +417,8 @@ module RBS
407
417
  end
408
418
 
409
419
  def sub(s)
420
+ return self if s.empty?
421
+
410
422
  Alias.new(name: name, args: args.map {|ty| ty.sub(s) }, location: location)
411
423
  end
412
424
 
@@ -463,6 +475,8 @@ module RBS
463
475
  end
464
476
 
465
477
  def sub(s)
478
+ return self if s.empty?
479
+
466
480
  self.class.new(types: types.map {|ty| ty.sub(s) },
467
481
  location: location)
468
482
  end
@@ -536,7 +550,7 @@ module RBS
536
550
  end
537
551
  end
538
552
  else
539
- raise ArgumentError, "only one of `:fields` or `:all_fields` is requireds"
553
+ raise ArgumentError, "only one of `:fields` or `:all_fields` is required"
540
554
  end
541
555
 
542
556
  @location = location
@@ -568,6 +582,8 @@ module RBS
568
582
  end
569
583
 
570
584
  def sub(s)
585
+ return self if s.empty?
586
+
571
587
  self.class.new(
572
588
  all_fields: all_fields.transform_values {|ty, required| [ty.sub(s), required] },
573
589
  location: location
@@ -658,6 +674,8 @@ module RBS
658
674
  end
659
675
 
660
676
  def sub(s)
677
+ return self if s.empty?
678
+
661
679
  self.class.new(type: type.sub(s), location: location)
662
680
  end
663
681
 
@@ -746,15 +764,26 @@ module RBS
746
764
  end
747
765
 
748
766
  def sub(s)
767
+ return self if s.empty?
768
+
749
769
  self.class.new(types: types.map {|ty| ty.sub(s) },
750
770
  location: location)
751
771
  end
752
772
 
753
773
  def to_s(level = 0)
774
+ strs = types.map do |ty|
775
+ case ty
776
+ when Intersection
777
+ ty.to_s([1, level].max)
778
+ else
779
+ ty.to_s
780
+ end
781
+ end
782
+
754
783
  if level > 0
755
- "(#{types.join(" | ")})"
784
+ "(#{strs.join(" | ")})"
756
785
  else
757
- types.join(" | ")
786
+ strs.join(" | ")
758
787
  end
759
788
  end
760
789
 
@@ -826,6 +855,8 @@ module RBS
826
855
  end
827
856
 
828
857
  def sub(s)
858
+ return self if s.empty?
859
+
829
860
  self.class.new(types: types.map {|ty| ty.sub(s) },
830
861
  location: location)
831
862
  end
@@ -1078,6 +1109,8 @@ module RBS
1078
1109
  end
1079
1110
 
1080
1111
  def sub(s)
1112
+ return self if s.empty?
1113
+
1081
1114
  map_type {|ty| ty.sub(s) }
1082
1115
  end
1083
1116
 
@@ -1257,6 +1290,8 @@ module RBS
1257
1290
  end
1258
1291
 
1259
1292
  def sub(subst)
1293
+ return self if subst.empty?
1294
+
1260
1295
  map_type { _1.sub(subst) }
1261
1296
  end
1262
1297
 
@@ -1331,6 +1366,8 @@ module RBS
1331
1366
  end
1332
1367
 
1333
1368
  def sub(s)
1369
+ return self if s.empty?
1370
+
1334
1371
  self.class.new(
1335
1372
  type: type.sub(s),
1336
1373
  required: required,
@@ -1400,6 +1437,8 @@ module RBS
1400
1437
  end
1401
1438
 
1402
1439
  def sub(s)
1440
+ return self if s.empty?
1441
+
1403
1442
  self.class.new(
1404
1443
  type: type.sub(s),
1405
1444
  block: block&.sub(s),
@@ -20,6 +20,8 @@ module RBS
20
20
  attr_reader :object
21
21
  attr_reader :method_name
22
22
 
23
+ NO_RETURN = Object.new
24
+
23
25
  def initialize(object:, method_name:)
24
26
  @callback = -> (_) { }
25
27
  @object = object
@@ -39,7 +41,7 @@ module RBS
39
41
  define_method(
40
42
  spy.method_name,
41
43
  _ = -> (*args, &block) do
42
- return_value = nil
44
+ return_value = NO_RETURN
43
45
  exception = nil
44
46
  block_calls = [] #: Array[Test::ArgumentsReturn]
45
47
 
@@ -105,7 +107,7 @@ module RBS
105
107
  arguments: args,
106
108
  exception: exception
107
109
  )
108
- when return_value
110
+ when ::RBS::UnitTest::Spy::WrapSpy::NO_RETURN != return_value
109
111
  Test::ArgumentsReturn.return(
110
112
  arguments: args,
111
113
  value: return_value
@@ -163,7 +163,7 @@ module RBS
163
163
  end
164
164
  end
165
165
 
166
- last_trace = trace.last or raise
166
+ last_trace = trace.last or raise "empty trace"
167
167
 
168
168
  yield(mt, last_trace, result, exception)
169
169
  end
@@ -182,9 +182,9 @@ module RBS
182
182
 
183
183
  assert_empty errors.map {|x| RBS::Test::Errors.to_string(x) }, "Call trace does not match with given method type: #{trace.inspect}"
184
184
 
185
- method_types = method_types(method)
186
- all_errors = method_types.map {|t| typecheck.method_call(method, t, trace, errors: []) }
187
- assert all_errors.any? {|es| es.empty? }, "Call trace does not match one of method definitions:\n #{trace.inspect}\n #{method_types.join(" | ")}"
185
+ method_defs = method_defs(method)
186
+ all_errors = method_defs.map {|t| typecheck.method_call(method, t.type, trace, errors: [], annotations: t.each_annotation.to_a) }
187
+ assert all_errors.any? {|es| es.empty? }, "Call trace does not match one of method definitions:\n #{trace.inspect}\n #{method_defs.map(&:type).join(" | ")}"
188
188
 
189
189
  raise exception if exception
190
190
 
@@ -219,30 +219,36 @@ module RBS
219
219
  assert_operator exception, :is_a?, ::Exception
220
220
  assert_empty errors.map {|x| RBS::Test::Errors.to_string(x) }
221
221
 
222
- method_types = method_types(method)
223
- all_errors = method_types.map {|t| typecheck.method_call(method, t, trace, errors: []) }
224
- assert all_errors.all? {|es| es.size > 0 }, "Call trace unexpectedly matches one of method definitions:\n #{trace.inspect}\n #{method_types.join(" | ")}"
222
+ method_defs = method_defs(method)
223
+ all_errors = method_defs.map {|t| typecheck.method_call(method, t.type, trace, errors: [], annotations: t.each_annotation.to_a) }
224
+ assert all_errors.all? {|es| es.size > 0 }, "Call trace unexpectedly matches one of method definitions:\n #{trace.inspect}\n #{method_defs.map(&:type).join(" | ")}"
225
225
 
226
226
  result
227
227
  end
228
228
  end
229
229
 
230
- def method_types(method)
230
+ def method_defs(method)
231
231
  type, definition = target
232
232
 
233
233
  case type
234
234
  when Types::ClassInstance
235
235
  subst = RBS::Substitution.build(definition.type_params, type.args)
236
- definition.methods[method].method_types.map do |method_type|
237
- method_type.sub(subst)
236
+ definition.methods[method].defs.map do |type_def|
237
+ type_def.update(
238
+ type: type_def.type.sub(subst)
239
+ )
238
240
  end
239
241
  when Types::ClassSingleton
240
- definition.methods[method].method_types
242
+ definition.methods[method].defs
241
243
  else
242
244
  raise
243
245
  end
244
246
  end
245
247
 
248
+ def method_types(method)
249
+ method_defs(method).map(&:type)
250
+ end
251
+
246
252
  def allows_error(*errors)
247
253
  yield
248
254
  rescue *errors => exn
data/lib/rbs/validator.rb CHANGED
@@ -151,6 +151,10 @@ module RBS
151
151
  end
152
152
  end
153
153
 
154
+ def validate_variable(var)
155
+ validate_type(var.type, context: nil)
156
+ end
157
+
154
158
  def validate_class_alias(entry:)
155
159
  case env.normalize_module_name?(entry.decl.new_name)
156
160
  when nil
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.8.0"
4
+ VERSION = "3.9.0.dev.1"
5
5
  end
data/lib/rbs/writer.rb CHANGED
@@ -77,14 +77,19 @@ module RBS
77
77
  end
78
78
 
79
79
  def write(contents)
80
- dirs = contents.select {|c| c.is_a?(AST::Directives::Base) } #: Array[AST::Directives::t]
80
+ resolves = contents.select { _1.is_a?(AST::Directives::ResolveTypeNames) } #: Array[AST::Directives::ResolveTypeNames]
81
+ uses = contents.select {|c| c.is_a?(AST::Directives::Use) } #: Array[AST::Directives::Use]
81
82
  decls = contents.select {|c| c.is_a?(AST::Declarations::Base) } #: Array[AST::Declarations::t]
82
83
 
83
- dirs.each do |dir|
84
- write_directive(dir)
84
+ if first_resolves = resolves.first
85
+ puts "# resolve-type-names: #{first_resolves.value}"
86
+ puts
85
87
  end
86
88
 
87
- puts unless dirs.empty?
89
+ uses.each do |dir|
90
+ write_use_directive(dir)
91
+ end
92
+ puts unless uses.empty?
88
93
 
89
94
  [nil, *decls].each_cons(2) do |prev, decl|
90
95
  raise unless decl
@@ -94,7 +99,7 @@ module RBS
94
99
  end
95
100
  end
96
101
 
97
- def write_directive(dir)
102
+ def write_use_directive(dir)
98
103
  clauses = dir.clauses.map do |clause|
99
104
  case clause
100
105
  when AST::Directives::Use::SingleClause
data/lib/rbs.rb CHANGED
@@ -9,6 +9,7 @@ require "pp"
9
9
  require "ripper"
10
10
  require "logger"
11
11
  require "tsort"
12
+ require "strscan"
12
13
 
13
14
  require "rbs/errors"
14
15
  require "rbs/buffer"
data/rbs.gemspec CHANGED
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
31
  `git ls-files -z`.split("\x0").reject do |f|
32
32
  [
33
- %r{^(test|spec|features|bin|steep|benchmark)/},
33
+ %r{^(test|spec|features|bin|steep|benchmark|templates)/},
34
34
  /Gemfile/
35
35
  ].any? {|r| f.match(r) }
36
36
  end
@@ -4,7 +4,7 @@ module RBS
4
4
  class LockfileGenerator
5
5
  # Name of stdlibs that was rbs-bundled stdlib but is now a gem.
6
6
  #
7
- ALUMNI_STDLIBS: Hash[String, String]
7
+ ALUMNI_STDLIBS: Hash[String, String?]
8
8
 
9
9
  class GemfileLockMismatchError < StandardError
10
10
  @expected: Pathname
data/sig/declarations.rbs CHANGED
@@ -205,8 +205,10 @@ module RBS
205
205
  attr_reader type: Types::t
206
206
  attr_reader location: loc?
207
207
  attr_reader comment: Comment?
208
+ attr_reader annotations: Array[Annotation]
208
209
 
209
- def initialize: (name: TypeName, type: Types::t, location: loc?, comment: Comment?) -> void
210
+ def initialize: (name: TypeName, type: Types::t, location: loc?, comment: Comment?, annotations: Array[Annotation]) -> void
211
+ | %a{deprecated} (name: TypeName, type: Types::t, location: loc?, comment: Comment?) -> void
210
212
 
211
213
  include _HashEqual
212
214
  include _ToJson
@@ -223,8 +225,10 @@ module RBS
223
225
  attr_reader type: Types::t
224
226
  attr_reader location: loc?
225
227
  attr_reader comment: Comment?
228
+ attr_reader annotations: Array[Annotation]
226
229
 
227
- def initialize: (name: Symbol, type: Types::t, location: loc?, comment: Comment?) -> void
230
+ def initialize: (name: Symbol, type: Types::t, location: loc?, comment: Comment?, annotations: Array[Annotation]) -> void
231
+ | %a{deprecated} (name: Symbol, type: Types::t, location: loc?, comment: Comment?) -> void
228
232
 
229
233
  include _HashEqual
230
234
  include _ToJson
@@ -250,7 +254,10 @@ module RBS
250
254
 
251
255
  attr_reader comment: Comment?
252
256
 
253
- def initialize: (new_name: TypeName, old_name: TypeName, location: loc?, comment: Comment?) -> void
257
+ attr_reader annotations: Array[Annotation]
258
+
259
+ def initialize: (new_name: TypeName, old_name: TypeName, location: loc?, comment: Comment?, annotations: Array[Annotation]) -> void
260
+ | %a{deprecated} (new_name: TypeName, old_name: TypeName, location: loc?, comment: Comment?) -> void
254
261
 
255
262
  include _HashEqual
256
263
  end
data/sig/definition.rbs CHANGED
@@ -6,8 +6,15 @@ module RBS
6
6
  attr_reader parent_variable: Variable?
7
7
  attr_reader type: Types::t
8
8
  attr_reader declared_in: TypeName
9
+ type source = AST::Members::AttrAccessor
10
+ | AST::Members::AttrReader
11
+ | AST::Members::AttrWriter
12
+ | AST::Members::InstanceVariable
13
+ | AST::Members::ClassVariable
14
+ | AST::Members::ClassInstanceVariable
15
+ attr_reader source: source
9
16
 
10
- def initialize: (parent_variable: Variable?, type: Types::t, declared_in: TypeName) -> void
17
+ def initialize: (parent_variable: Variable?, type: Types::t, declared_in: TypeName, source: source) -> void
11
18
 
12
19
  def sub: (Substitution) -> Variable
13
20
  end
@@ -21,22 +28,50 @@ module RBS
21
28
  attr_reader defined_in: TypeName
22
29
  attr_reader implemented_in: TypeName?
23
30
 
24
- # Annotations given to `#member`
31
+ # Annotations given to the method definition syntax
32
+ #
33
+ # If the method have multiple syntaxes, union of the annotations to the member will be included, without dedup.
34
+ #
35
+ # The value should be updated during setup.
36
+ #
25
37
  attr_reader member_annotations: Array[AST::Annotation]
26
38
 
27
39
  # Annotations given to the overload associated to the method type
40
+ #
41
+ # The value should be updated during setup.
42
+ #
28
43
  attr_reader overload_annotations: Array[AST::Annotation]
29
44
 
30
- # Concatenation of `member_annotations` and `overload_annotations`
31
- attr_reader annotations: Array[AST::Annotation]
32
-
33
- def initialize: (type: MethodType, member: method_member, defined_in: TypeName, implemented_in: TypeName?, ?overload_annotations: Array[AST::Annotation]) -> void
45
+ # Always returns an empty array
46
+ %a{deprecated} attr_reader annotations: Array[AST::Annotation]
47
+
48
+ # `overload_annotations` is ignored.
49
+ def initialize: (
50
+ type: MethodType,
51
+ member: method_member,
52
+ defined_in: TypeName,
53
+ implemented_in: TypeName?
54
+ ) -> void
55
+ | %a{deprecated} (
56
+ type: MethodType,
57
+ member: method_member,
58
+ defined_in: TypeName,
59
+ implemented_in: TypeName?,
60
+ overload_annotations: nil
61
+ ) -> void
34
62
 
35
63
  def comment: () -> AST::Comment?
36
64
 
37
65
  def update: (?type: MethodType, ?member: method_member, ?defined_in: TypeName, ?implemented_in: TypeName?) -> TypeDef
38
66
 
39
67
  def overload?: () -> bool
68
+
69
+ # Yields member and overload annotations, without dedup
70
+ #
71
+ # Member annotation yields first.
72
+ #
73
+ def each_annotation: () { (AST::Annotation) -> void } -> void
74
+ | () -> Enumerator[AST::Annotation]
40
75
  end
41
76
 
42
77
  attr_reader super_method: Method?
@@ -49,21 +84,38 @@ module RBS
49
84
  attr_reader comments: Array[AST::Comment]
50
85
 
51
86
  attr_reader members: Array[method_member]
87
+
88
+ # The original method when the method is defined with `alias` syntax
52
89
  attr_reader alias_of: Method?
53
90
 
91
+ # Present if the method is defined with `alias` syntax
92
+ attr_reader alias_member: AST::Members::Alias?
93
+
54
94
  # Unused, always returns empty array
55
- attr_reader extra_annotations: Array[AST::Annotation]
95
+ %a{deprecated} attr_reader extra_annotations: Array[AST::Annotation]
56
96
 
57
- # Union of annotations given to `defs`, not contains annotations given to each overload
97
+ # Union of annotations given to `def`s and `alias`, not contains annotations given to each overload
98
+ #
99
+ # The elements will be updated during `Method` object setup.
100
+ #
58
101
  attr_reader annotations: Array[AST::Annotation]
59
102
 
60
103
  # Note that the annotations given through `annotations:` keyword is ignored.
61
104
  #
62
- def initialize: (super_method: Method?,
63
- defs: Array[TypeDef],
64
- accessibility: accessibility,
65
- alias_of: Method?,
66
- ?annotations: Array[AST::Annotation]) -> void
105
+ def initialize: (
106
+ super_method: Method?,
107
+ defs: Array[TypeDef],
108
+ accessibility: accessibility,
109
+ alias_of: Method?,
110
+ alias_member: AST::Members::Alias?
111
+ ) -> void
112
+ | %a{deprecated} (
113
+ super_method: Method?,
114
+ defs: Array[TypeDef],
115
+ accessibility: accessibility,
116
+ alias_of: Method?,
117
+ annotations: Array[AST::Annotation]
118
+ ) -> void
67
119
 
68
120
  def public?: () -> bool
69
121
 
@@ -90,7 +142,8 @@ module RBS
90
142
  ?defs: Array[TypeDef],
91
143
  ?accessibility: accessibility,
92
144
  ?alias_of: Method?,
93
- ?annotations: Array[AST::Annotation]
145
+ ?annotations: Array[AST::Annotation],
146
+ ?alias_member: AST::Members::Alias?
94
147
  ) -> Method
95
148
  end
96
149
 
@@ -105,7 +105,15 @@ module RBS
105
105
 
106
106
  def source_location: (Definition::Ancestor::Instance::source, AST::Declarations::t) -> Location[untyped, untyped]?
107
107
 
108
- def insert_variable: (TypeName, Hash[Symbol, Definition::Variable], name: Symbol, type: Types::t) -> void
108
+ def validate_variable: (Definition::Variable) -> void
109
+
110
+ def insert_variable: (
111
+ TypeName,
112
+ Hash[Symbol, Definition::Variable],
113
+ name: Symbol,
114
+ type: Types::t,
115
+ source: Definition::Variable::source
116
+ ) -> void
109
117
 
110
118
  # Add method definition to `methods`, which will be merged to `class_definition` after defining all methods at this *level* -- class, module, or interface
111
119
  #
@@ -142,11 +150,17 @@ module RBS
142
150
  Hash[Symbol, Definition::Method]? self_type_methods,
143
151
  ) -> void
144
152
 
145
- # Updates `definition` with methods and variables of `type_name` that can be a module or a class
153
+ # Updates `definition` with methods and instance variables of `type_name` that can be a module or a class
146
154
  #
147
155
  # It processes includes and prepends recursively.
156
+ # If `define_class_vars:` is falsy, it skips inserting class variables.
148
157
  #
149
- def define_instance: (Definition definition, TypeName type_name, Substitution subst) -> void
158
+ def define_instance: (
159
+ Definition definition,
160
+ TypeName type_name,
161
+ Substitution subst,
162
+ define_class_vars: bool
163
+ ) -> void
150
164
 
151
165
  # Updates `definition` with methods defined in an interface `type_name`
152
166
  #
data/sig/directives.rbs CHANGED
@@ -1,7 +1,7 @@
1
1
  module RBS
2
2
  module AST
3
3
  module Directives
4
- type t = Use
4
+ type t = Use | ResolveTypeNames
5
5
 
6
6
  class Base
7
7
  end
@@ -56,6 +56,22 @@ module RBS
56
56
 
57
57
  def initialize: (clauses: Array[clause], location: loc?) -> void
58
58
  end
59
+
60
+ class ResolveTypeNames < Base
61
+ # ```
62
+ # # resolve-type-names: false
63
+ # ^^^^^^^^^^^^^^^^^^ keyword
64
+ # ^ colon
65
+ # ^^^^^ value
66
+ # ```
67
+ type loc = Location[:keyword | :colon | :value, bot]
68
+
69
+ attr_reader location: loc?
70
+
71
+ attr_reader value: bool
72
+
73
+ def initialize: (value: bool, location: loc?) -> void
74
+ end
59
75
  end
60
76
  end
61
77
  end
data/sig/environment.rbs CHANGED
@@ -141,6 +141,8 @@ module RBS
141
141
  #
142
142
  def resolve_type_names: (?only: Set[AST::Declarations::t]?) -> Environment
143
143
 
144
+ def resolve_signature: (Resolver::TypeNameResolver, UseMap::Table, Array[AST::Directives::t], Array[AST::Declarations::t], ?only: Set[AST::Declarations::t]?) -> [Array[AST::Directives::t], Array[AST::Declarations::t]]
145
+
144
146
  def inspect: () -> String
145
147
 
146
148
  def buffers: () -> Array[Buffer]
data/sig/errors.rbs CHANGED
@@ -182,6 +182,22 @@ module RBS
182
182
  def location: () -> AST::Members::Mixin::loc?
183
183
  end
184
184
 
185
+ class VariableDuplicationError < DefinitionError
186
+ include DetailedMessageable
187
+
188
+ attr_reader member: AST::Members::Var
189
+
190
+ def initialize: (member: AST::Members::Var) -> void
191
+
192
+ def location: () -> Location[bot, bot]
193
+ end
194
+
195
+ class InstanceVariableDuplicationError < VariableDuplicationError
196
+ end
197
+
198
+ class ClassInstanceVariableDuplicationError < VariableDuplicationError
199
+ end
200
+
185
201
  # The `alias` member declares an alias from unknown method
186
202
  #
187
203
  class UnknownMethodAliasError < DefinitionError
data/sig/parser.rbs CHANGED
@@ -68,6 +68,10 @@ module RBS
68
68
  #
69
69
  def self.parse_signature: (Buffer | String) -> [Buffer, Array[AST::Directives::t], Array[AST::Declarations::t]]
70
70
 
71
+ # Returns the magic comment from the buffer
72
+ #
73
+ def self.magic_comment: (Buffer) -> AST::Directives::ResolveTypeNames?
74
+
71
75
  # Parse whole RBS file and return result.
72
76
  #
73
77
  # ```ruby
@@ -86,7 +90,7 @@ module RBS
86
90
 
87
91
  def self._parse_method_type: (Buffer, Integer start_pos, Integer end_pos, Array[Symbol] variables, bool require_eof) -> MethodType?
88
92
 
89
- def self._parse_signature: (Buffer, Integer end_pos) -> [Array[AST::Directives::t], Array[AST::Declarations::t]]
93
+ def self._parse_signature: (Buffer, Integer start_pos, Integer end_pos) -> [Array[AST::Directives::t], Array[AST::Declarations::t]]
90
94
 
91
95
  def self._lex: (Buffer, Integer end_pos) -> Array[[Symbol, Location[untyped, untyped]]]
92
96
 
data/sig/subtractor.rbs CHANGED
@@ -24,7 +24,7 @@ module RBS
24
24
 
25
25
  private def mixin_exist?: (TypeName owner, AST::Members::Include | AST::Members::Extend | AST::Members::Prepend, context: Resolver::context) -> boolish
26
26
 
27
- private def filter_redundunt_access_modifiers: (Array[AST::Declarations::t | AST::Members::t]) -> Array[AST::Declarations::t | AST::Members::t]
27
+ private def filter_redundant_access_modifiers: (Array[AST::Declarations::t | AST::Members::t]) -> Array[AST::Declarations::t | AST::Members::t]
28
28
 
29
29
  private def access_modifier?: (AST::Declarations::t | AST::Members::t?) -> bool
30
30