rbs 2.6.0 → 2.7.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +5 -0
  4. data/CHANGELOG.md +48 -1
  5. data/Gemfile.lock +10 -9
  6. data/Rakefile +0 -5
  7. data/Steepfile +1 -0
  8. data/core/basic_object.rbs +2 -2
  9. data/core/fiber.rbs +304 -14
  10. data/core/float.rbs +2 -0
  11. data/core/io.rbs +95 -1
  12. data/core/kernel.rbs +1 -1
  13. data/core/module.rbs +1 -1
  14. data/core/regexp.rbs +1 -1
  15. data/core/string_io.rbs +1 -1
  16. data/core/warning.rbs +1 -1
  17. data/ext/rbs_extension/parser.c +36 -10
  18. data/ext/rbs_extension/ruby_objs.c +4 -2
  19. data/ext/rbs_extension/ruby_objs.h +2 -2
  20. data/lib/rbs/ancestor_graph.rb +2 -0
  21. data/lib/rbs/annotate/annotations.rb +2 -0
  22. data/lib/rbs/annotate/formatter.rb +4 -2
  23. data/lib/rbs/annotate/rdoc_annotator.rb +2 -0
  24. data/lib/rbs/annotate/rdoc_source.rb +2 -0
  25. data/lib/rbs/annotate.rb +2 -0
  26. data/lib/rbs/ast/annotation.rb +2 -0
  27. data/lib/rbs/ast/comment.rb +2 -0
  28. data/lib/rbs/ast/declarations.rb +2 -0
  29. data/lib/rbs/ast/members.rb +2 -0
  30. data/lib/rbs/ast/type_param.rb +3 -1
  31. data/lib/rbs/buffer.rb +2 -0
  32. data/lib/rbs/builtin_names.rb +2 -0
  33. data/lib/rbs/cli.rb +39 -2
  34. data/lib/rbs/collection/cleaner.rb +2 -0
  35. data/lib/rbs/collection/config/lockfile_generator.rb +8 -3
  36. data/lib/rbs/collection/config.rb +2 -0
  37. data/lib/rbs/collection/installer.rb +2 -0
  38. data/lib/rbs/collection/sources/base.rb +14 -0
  39. data/lib/rbs/collection/sources/git.rb +3 -0
  40. data/lib/rbs/collection/sources/rubygems.rb +3 -0
  41. data/lib/rbs/collection/sources/stdlib.rb +12 -7
  42. data/lib/rbs/collection/sources.rb +3 -0
  43. data/lib/rbs/collection.rb +2 -0
  44. data/lib/rbs/constant.rb +2 -0
  45. data/lib/rbs/constant_table.rb +5 -3
  46. data/lib/rbs/definition.rb +13 -1
  47. data/lib/rbs/definition_builder/ancestor_builder.rb +2 -0
  48. data/lib/rbs/definition_builder/method_builder.rb +2 -0
  49. data/lib/rbs/definition_builder.rb +75 -13
  50. data/lib/rbs/environment.rb +2 -0
  51. data/lib/rbs/environment_loader.rb +25 -5
  52. data/lib/rbs/environment_walker.rb +2 -0
  53. data/lib/rbs/errors.rb +3 -1
  54. data/lib/rbs/factory.rb +2 -0
  55. data/lib/rbs/location_aux.rb +3 -1
  56. data/lib/rbs/locator.rb +2 -0
  57. data/lib/rbs/method_type.rb +7 -5
  58. data/lib/rbs/namespace.rb +9 -5
  59. data/lib/rbs/parser_aux.rb +2 -0
  60. data/lib/rbs/parser_compat/lexer_error.rb +2 -0
  61. data/lib/rbs/parser_compat/located_value.rb +2 -0
  62. data/lib/rbs/parser_compat/semantics_error.rb +2 -0
  63. data/lib/rbs/parser_compat/syntax_error.rb +2 -0
  64. data/lib/rbs/prototype/helpers.rb +13 -8
  65. data/lib/rbs/prototype/rb.rb +2 -0
  66. data/lib/rbs/prototype/rbi.rb +11 -6
  67. data/lib/rbs/prototype/runtime.rb +13 -4
  68. data/lib/rbs/repository.rb +4 -4
  69. data/lib/rbs/resolver/constant_resolver.rb +2 -0
  70. data/lib/rbs/resolver/type_name_resolver.rb +2 -0
  71. data/lib/rbs/sorter.rb +168 -0
  72. data/lib/rbs/substitution.rb +2 -0
  73. data/lib/rbs/test/errors.rb +2 -0
  74. data/lib/rbs/test/hook.rb +2 -0
  75. data/lib/rbs/test/observer.rb +2 -0
  76. data/lib/rbs/test/setup.rb +2 -0
  77. data/lib/rbs/test/setup_helper.rb +2 -0
  78. data/lib/rbs/test/spy.rb +2 -0
  79. data/lib/rbs/test/tester.rb +2 -0
  80. data/lib/rbs/test/type_check.rb +2 -0
  81. data/lib/rbs/test.rb +2 -0
  82. data/lib/rbs/type_alias_dependency.rb +2 -0
  83. data/lib/rbs/type_alias_regularity.rb +2 -0
  84. data/lib/rbs/type_name.rb +2 -0
  85. data/lib/rbs/type_name_resolver.rb +4 -2
  86. data/lib/rbs/types.rb +68 -18
  87. data/lib/rbs/validator.rb +2 -0
  88. data/lib/rbs/variance_calculator.rb +2 -0
  89. data/lib/rbs/vendorer.rb +2 -0
  90. data/lib/rbs/version.rb +3 -1
  91. data/lib/rbs/writer.rb +3 -1
  92. data/lib/rbs.rb +4 -2
  93. data/lib/rdoc/discover.rb +20 -0
  94. data/lib/rdoc_plugin/parser.rb +163 -0
  95. data/schema/methodType.json +7 -1
  96. data/schema/types.json +13 -1
  97. data/sig/ancestor_builder.rbs +66 -7
  98. data/sig/annotation.rbs +7 -6
  99. data/sig/builtin_names.rbs +2 -0
  100. data/sig/cli.rbs +8 -0
  101. data/sig/collection/config.rbs +13 -4
  102. data/sig/collection/installer.rbs +2 -0
  103. data/sig/collection/sources.rbs +23 -4
  104. data/sig/definition.rbs +8 -0
  105. data/sig/definition_builder.rbs +64 -7
  106. data/sig/environment.rbs +4 -0
  107. data/sig/environment_loader.rbs +4 -2
  108. data/sig/location.rbs +8 -4
  109. data/sig/manifest.yaml +1 -0
  110. data/sig/members.rbs +1 -1
  111. data/sig/method_builder.rbs +10 -0
  112. data/sig/namespace.rbs +54 -31
  113. data/sig/prototype/rb.rbs +4 -0
  114. data/sig/rbs.rbs +8 -6
  115. data/sig/rdoc/rbs.rbs +63 -0
  116. data/sig/{polyfill.rbs → shims.rbs} +1 -31
  117. data/sig/sorter.rbs +23 -0
  118. data/sig/types.rbs +14 -2
  119. data/sig/vendorer.rbs +32 -25
  120. data/stdlib/bigdecimal/0/big_decimal.rbs +250 -0
  121. data/stdlib/erb/0/erb.rbs +107 -0
  122. data/stdlib/logger/0/logger.rbs +2 -2
  123. data/stdlib/rdoc/0/rdoc.rbs +758 -0
  124. data/steep/Gemfile.lock +8 -8
  125. metadata +12 -6
  126. data/stdlib/fiber/0/fiber.rbs +0 -99
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  class DefinitionBuilder
3
5
  attr_reader :env
@@ -173,11 +175,15 @@ module RBS
173
175
  end
174
176
 
175
177
  # Successor interface method overwrites.
176
- merge_definition(src: defn,
177
- dest: definition,
178
- subst: Substitution.build(defn.type_params, ans.args),
179
- keep_super: true)
178
+ merge_definition(
179
+ src: defn,
180
+ dest: definition,
181
+ subst: Substitution.build(defn.type_params, ans.args),
182
+ keep_super: true
183
+ )
180
184
  end
185
+ else
186
+ methods_with_self = build_instance(type_name, no_self_types: false).methods
181
187
  end
182
188
  end
183
189
 
@@ -211,10 +217,16 @@ module RBS
211
217
  end
212
218
  end
213
219
 
214
- define_methods(definition,
215
- interface_methods: interface_methods,
216
- methods: methods,
217
- super_interface_method: entry.is_a?(Environment::ModuleEntry))
220
+ if entry.is_a?(Environment::ModuleEntry)
221
+ define_methods_module_instance(
222
+ definition,
223
+ methods: methods,
224
+ interface_methods: interface_methods,
225
+ module_self_methods: methods_with_self
226
+ )
227
+ else
228
+ define_methods_instance(definition, methods: methods, interface_methods: interface_methods)
229
+ end
218
230
 
219
231
  entry.decls.each do |d|
220
232
  subst = Substitution.build(d.decl.type_params.each.map(&:name), args)
@@ -328,7 +340,7 @@ module RBS
328
340
  end
329
341
 
330
342
  methods = method_builder.build_singleton(type_name)
331
- define_methods(definition, interface_methods: interface_methods, methods: methods, super_interface_method: false)
343
+ define_methods_singleton(definition, methods: methods, interface_methods: interface_methods)
332
344
 
333
345
  entry.decls.each do |d|
334
346
  d.decl.members.each do |member|
@@ -379,6 +391,18 @@ module RBS
379
391
  if entry.is_a?(Environment::ClassEntry)
380
392
  new_method = definition.methods[:new]
381
393
  if new_method.defs.all? {|d| d.defined_in == BuiltinNames::Class.name }
394
+ alias_methods = definition.methods.each.with_object([]) do |entry, array|
395
+ # @type var method: Definition::Method?
396
+ name, method = entry
397
+ while method
398
+ if method.alias_of == new_method
399
+ array << name
400
+ break
401
+ end
402
+ method = method.alias_of
403
+ end
404
+ end
405
+
382
406
  # The method is _untyped new_.
383
407
 
384
408
  instance = build_instance(type_name)
@@ -389,7 +413,7 @@ module RBS
389
413
 
390
414
  # Inject a virtual _typed new_.
391
415
  initialize_defs = initialize.defs
392
- definition.methods[:new] = Definition::Method.new(
416
+ typed_new = Definition::Method.new(
393
417
  super_method: new_method,
394
418
  defs: initialize_defs.map do |initialize_def|
395
419
  method_type = initialize_def.type
@@ -442,6 +466,15 @@ module RBS
442
466
  annotations: [],
443
467
  alias_of: nil
444
468
  )
469
+
470
+ definition.methods[:new] = typed_new
471
+
472
+ alias_methods.each do |alias_name|
473
+ definition.methods[alias_name] = definition.methods[alias_name].update(
474
+ alias_of: typed_new,
475
+ defs: typed_new.defs
476
+ )
477
+ end
445
478
  end
446
479
  end
447
480
  end
@@ -564,14 +597,41 @@ module RBS
564
597
  )
565
598
  end
566
599
 
567
- def define_methods(definition, interface_methods:, methods:, super_interface_method:)
600
+ def define_methods_instance(definition, methods:, interface_methods:)
601
+ define_methods(
602
+ definition,
603
+ methods: methods,
604
+ interface_methods: interface_methods,
605
+ methods_with_self: nil,
606
+ super_interface_method: false
607
+ )
608
+ end
609
+
610
+ def define_methods_module_instance(definition, methods:, interface_methods:, module_self_methods:)
611
+ define_methods(definition, methods: methods, interface_methods: interface_methods, methods_with_self: module_self_methods, super_interface_method: true)
612
+ end
613
+
614
+ def define_methods_singleton(definition, methods:, interface_methods:)
615
+ define_methods(
616
+ definition,
617
+ methods: methods,
618
+ interface_methods: interface_methods,
619
+ methods_with_self: nil,
620
+ super_interface_method: false
621
+ )
622
+ end
623
+
624
+ def define_methods(definition, methods:, interface_methods:, methods_with_self:, super_interface_method:)
568
625
  methods.each do |method_def|
569
626
  method_name = method_def.name
570
627
  original = method_def.original
571
628
 
572
629
  if original.is_a?(AST::Members::Alias)
573
630
  existing_method = interface_methods[method_name] || definition.methods[method_name]
574
- original_method = interface_methods[original.old_name] || definition.methods[original.old_name]
631
+ original_method =
632
+ interface_methods[original.old_name] ||
633
+ methods_with_self&.[](original.old_name) ||
634
+ definition.methods[original.old_name]
575
635
 
576
636
  unless original_method
577
637
  raise UnknownMethodAliasError.new(
@@ -791,8 +851,10 @@ module RBS
791
851
  end
792
852
  end
793
853
 
794
- def try_cache(type_name, cache:, key: type_name)
854
+ def try_cache(type_name, cache:, key: nil)
795
855
  # @type var cc: Hash[untyped, Definition | nil]
856
+ # @type var key: untyped
857
+ key ||= type_name
796
858
  cc = _ = cache
797
859
 
798
860
  cc[key] ||= yield
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  class Environment
3
5
  attr_reader :declarations
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  class EnvironmentLoader
3
5
  class UnknownLibraryError < StandardError
@@ -21,7 +23,9 @@ module RBS
21
23
  DEFAULT_CORE_ROOT = Pathname(_ = __dir__) + "../../core"
22
24
 
23
25
  def self.gem_sig_path(name, version)
24
- spec = Gem::Specification.find_by_name(name, version)
26
+ requirements = []
27
+ requirements << version if version
28
+ spec = Gem::Specification.find_by_name(name, *requirements)
25
29
  path = Pathname(spec.gem_dir) + "sig"
26
30
  if path.directory?
27
31
  [spec, path]
@@ -34,16 +38,32 @@ module RBS
34
38
  @core_root = core_root
35
39
  @repository = repository
36
40
 
37
- @libs = []
41
+ @libs = Set.new
38
42
  @dirs = []
39
43
  end
40
44
 
41
- def add(path: nil, library: nil, version: nil)
45
+ def add(path: nil, library: nil, version: nil, resolve_dependencies: true)
42
46
  case
43
47
  when path
44
48
  dirs << path
45
49
  when library
46
- libs << Library.new(name: library, version: version)
50
+ if libs.add?(Library.new(name: library, version: version)) && resolve_dependencies
51
+ resolve_dependencies(library: library, version: version)
52
+ end
53
+ end
54
+ end
55
+
56
+ def resolve_dependencies(library:, version:)
57
+ [Collection::Sources::Rubygems.instance, Collection::Sources::Stdlib.instance].each do |source|
58
+ # @type var gem: { 'name' => String, 'version' => String? }
59
+ gem = { 'name' => library, 'version' => version }
60
+ next unless source.has?(gem)
61
+
62
+ gem['version'] ||= source.versions(gem).last
63
+ source.dependencies_of(gem)&.each do |dep|
64
+ add(library: dep['name'], version: nil)
65
+ end
66
+ return
47
67
  end
48
68
  end
49
69
 
@@ -53,7 +73,7 @@ module RBS
53
73
  repository.add(collection_config.repo_path)
54
74
 
55
75
  collection_config.gems.each do |gem|
56
- add(library: gem['name'], version: gem['version'])
76
+ add(library: gem['name'], version: gem['version'], resolve_dependencies: false)
57
77
  end
58
78
  end
59
79
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  class EnvironmentWalker
3
5
  InstanceNode = _ = Struct.new(:type_name, keyword_init: true)
data/lib/rbs/errors.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  module MethodNameHelper
3
5
  def method_name_string()
@@ -216,7 +218,7 @@ module RBS
216
218
  @method_name = method_name
217
219
  @members = members
218
220
 
219
- message = "#{Location.to_string location}: #{qualified_method_name} has duplicated definitions"
221
+ message = +"#{Location.to_string location}: #{qualified_method_name} has duplicated definitions"
220
222
  if members.size > 1
221
223
  message << " in #{other_locations.map { |loc| Location.to_string loc }.join(', ')}"
222
224
  end
data/lib/rbs/factory.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  class Factory
3
5
  def type_name(string)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  class Location
3
5
  def inspect
@@ -58,7 +60,7 @@ module RBS
58
60
  end
59
61
 
60
62
  def source
61
- @source ||= buffer.content[range] or raise
63
+ @source ||= (buffer.content[range] || raise)
62
64
  end
63
65
 
64
66
  def to_s
data/lib/rbs/locator.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  class Locator
3
5
  attr_reader :decls
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  class MethodType
3
5
  attr_reader :type_params
@@ -62,9 +64,7 @@ module RBS
62
64
  self.class.new(
63
65
  type_params: type_params,
64
66
  type: type.map_type(&block),
65
- block: self.block&.yield_self do |b|
66
- Types::Block.new(type: b.type.map_type(&block), required: b.required)
67
- end,
67
+ block: self.block&.map_type(&block),
68
68
  location: location
69
69
  )
70
70
  end
@@ -93,11 +93,13 @@ module RBS
93
93
  end
94
94
 
95
95
  def to_s
96
+ block_self_binding = Types::SelfTypeBindingHelper.self_type_binding_to_s(block&.self_type)
97
+
96
98
  s = case
97
99
  when (b = block) && b.required
98
- "(#{type.param_to_s}) { (#{b.type.param_to_s}) -> #{b.type.return_to_s} } -> #{type.return_to_s}"
100
+ "(#{type.param_to_s}) { (#{b.type.param_to_s}) #{block_self_binding}-> #{b.type.return_to_s} } -> #{type.return_to_s}"
99
101
  when b = block
100
- "(#{type.param_to_s}) ?{ (#{b.type.param_to_s}) -> #{b.type.return_to_s} } -> #{type.return_to_s}"
102
+ "(#{type.param_to_s}) ?{ (#{b.type.param_to_s}) #{block_self_binding}-> #{b.type.return_to_s} } -> #{type.return_to_s}"
101
103
  else
102
104
  "(#{type.param_to_s}) -> #{type.return_to_s}"
103
105
  end
data/lib/rbs/namespace.rb CHANGED
@@ -1,18 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  class Namespace
3
5
  attr_reader :path
4
6
 
5
7
  def initialize(path:, absolute:)
6
8
  @path = path
7
- @absolute = absolute
9
+ @absolute = absolute ? true : false
8
10
  end
9
11
 
10
12
  def self.empty
11
- new(path: [], absolute: false)
13
+ @empty ||= new(path: [], absolute: false)
12
14
  end
13
15
 
14
16
  def self.root
15
- new(path: [], absolute: true)
17
+ @root ||= new(path: [], absolute: true)
16
18
  end
17
19
 
18
20
  def +(other)
@@ -28,8 +30,10 @@ module RBS
28
30
  end
29
31
 
30
32
  def parent
31
- raise "Parent with empty namespace" if empty?
32
- self.class.new(path: path.take(path.size - 1), absolute: absolute?)
33
+ @parent ||= begin
34
+ raise "Parent with empty namespace" if empty?
35
+ self.class.new(path: path.take(path.size - 1), absolute: absolute?)
36
+ end
33
37
  end
34
38
 
35
39
  def absolute?
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  class Parser
3
5
  def self.parse_type(source, line: 1, column: 0, variables: [])
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RBS.print_warning {
2
4
  "RBS::Parser::LexerError is deprecated and will be deleted in RBS 2.0."
3
5
  }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RBS.print_warning {
2
4
  "RBS::Parser::LocatedValue is deprecated and will be deleted in RBS 2.0."
3
5
  }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RBS.print_warning {
2
4
  "RBS::Parser::SemanticsError is deprecated and will be deleted in RBS 2.0."
3
5
  }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RBS.print_warning {
2
4
  "RBS::Parser::SyntaxError is deprecated and will be deleted in RBS 2.0."
3
5
  }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  module Prototype
3
5
  module Helpers
@@ -13,7 +15,8 @@ module RBS
13
15
  if block
14
16
  method_block = Types::Block.new(
15
17
  required: false,
16
- type: Types::Function.empty(untyped)
18
+ type: Types::Function.empty(untyped),
19
+ self_type: nil
17
20
  )
18
21
  end
19
22
 
@@ -21,12 +24,14 @@ module RBS
21
24
  if (yields = any_node?(body_node) {|n| n.type == :YIELD })
22
25
  method_block = Types::Block.new(
23
26
  required: true,
24
- type: Types::Function.empty(untyped)
27
+ type: Types::Function.empty(untyped),
28
+ self_type: nil
25
29
  )
26
30
 
27
31
  yields.each do |yield_node|
28
32
  array_content = yield_node.children[0]&.children&.compact || []
29
33
 
34
+ # @type var keywords: node?
30
35
  positionals, keywords = if keyword_hash?(array_content.last)
31
36
  [array_content.take(array_content.size - 1), array_content.last]
32
37
  else
@@ -86,12 +91,12 @@ module RBS
86
91
  end
87
92
 
88
93
  def keyword_hash?(node)
89
- if node
90
- if node.type == :HASH
91
- node.children[0].children.compact.each_slice(2).all? {|key, _|
92
- key.type == :LIT && key.children[0].is_a?(Symbol)
93
- }
94
- end
94
+ if node && node.type == :HASH
95
+ node.children[0].children.compact.each_slice(2).all? {|key, _|
96
+ key.type == :LIT && key.children[0].is_a?(Symbol)
97
+ }
98
+ else
99
+ false
95
100
  end
96
101
  end
97
102
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  module Prototype
3
5
  class RB
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  module Prototype
3
5
  class RBI
@@ -410,28 +412,31 @@ module RBS
410
412
  if block
411
413
  if (type = vars[block])
412
414
  if type.is_a?(Types::Proc)
413
- method_block = Types::Block.new(required: true, type: type.type)
415
+ method_block = Types::Block.new(required: true, type: type.type, self_type: nil)
414
416
  elsif type.is_a?(Types::Bases::Any)
415
417
  method_block = Types::Block.new(
416
418
  required: true,
417
- type: Types::Function.empty(Types::Bases::Any.new(location: nil))
419
+ type: Types::Function.empty(Types::Bases::Any.new(location: nil)),
420
+ self_type: nil
418
421
  )
419
422
  # Handle an optional block like `T.nilable(T.proc.void)`.
420
423
  elsif type.is_a?(Types::Optional) && (proc_type = type.type).is_a?(Types::Proc)
421
- method_block = Types::Block.new(required: false, type: proc_type.type)
424
+ method_block = Types::Block.new(required: false, type: proc_type.type, self_type: nil)
422
425
  else
423
426
  STDERR.puts "Unexpected block type: #{type}"
424
427
  PP.pp args_node, STDERR
425
428
  method_block = Types::Block.new(
426
429
  required: true,
427
- type: Types::Function.empty(Types::Bases::Any.new(location: nil))
430
+ type: Types::Function.empty(Types::Bases::Any.new(location: nil)),
431
+ self_type: nil
428
432
  )
429
433
  end
430
434
  else
431
435
  if overloads == 1
432
436
  method_block = Types::Block.new(
433
437
  required: false,
434
- type: Types::Function.empty(Types::Bases::Any.new(location: nil))
438
+ type: Types::Function.empty(Types::Bases::Any.new(location: nil)),
439
+ self_type: nil
435
440
  )
436
441
  end
437
442
  end
@@ -519,7 +524,7 @@ module RBS
519
524
  else
520
525
  if proc_type?(type_node)
521
526
  method_type = method_type(nil, type_node, variables: variables, overloads: 1) or raise
522
- Types::Proc.new(type: method_type.type, block: nil, location: nil)
527
+ Types::Proc.new(type: method_type.type, block: nil, location: nil, self_type: nil)
523
528
  else
524
529
  STDERR.puts "Unexpected type_node:"
525
530
  PP.pp type_node, STDERR
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  module Prototype
3
5
  class Runtime
@@ -21,6 +23,7 @@ module RBS
21
23
 
22
24
  def target?(const)
23
25
  name = const_name(const)
26
+ return false unless name
24
27
 
25
28
  patterns.any? do |pattern|
26
29
  if pattern.end_with?("*")
@@ -77,7 +80,7 @@ module RBS
77
80
  supers.merge(mix.included_modules)
78
81
  end
79
82
 
80
- if mod.is_a?(Class)
83
+ if mod.is_a?(Class) && mod.superclass
81
84
  mod.superclass.included_modules.each do |mix|
82
85
  supers << mix
83
86
  supers.merge(mix.included_modules)
@@ -135,7 +138,8 @@ module RBS
135
138
  when :block
136
139
  block = Types::Block.new(
137
140
  type: Types::Function.empty(untyped).update(rest_positionals: Types::Function::Param.new(name: nil, type: untyped)),
138
- required: true
141
+ required: true,
142
+ self_type: nil
139
143
  )
140
144
  end
141
145
  end
@@ -318,7 +322,12 @@ module RBS
318
322
 
319
323
  def generate_constants(mod, decls)
320
324
  mod.constants(false).sort.each do |name|
321
- value = mod.const_get(name)
325
+ begin
326
+ value = mod.const_get(name)
327
+ rescue StandardError, LoadError => e
328
+ RBS.logger.warn("Skipping constant #{name} of #{mod} since #{e}")
329
+ next
330
+ end
322
331
 
323
332
  next if value.is_a?(Class) || value.is_a?(Module)
324
333
  unless value.class.name
@@ -350,7 +359,7 @@ module RBS
350
359
  end
351
360
 
352
361
  def generate_super_class(mod)
353
- if mod.superclass == ::Object
362
+ if mod.superclass.nil? || mod.superclass == ::Object
354
363
  nil
355
364
  elsif const_name(mod.superclass).nil?
356
365
  RBS.logger.warn("Skipping anonymous superclass #{mod.superclass} of #{mod}")
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  class Repository
3
5
  DEFAULT_STDLIB_ROOT = Pathname(_ = __dir__) + "../../stdlib"
@@ -79,9 +81,7 @@ module RBS
79
81
  end
80
82
 
81
83
  def self.default
82
- new().tap do |repo|
83
- repo.add(DEFAULT_STDLIB_ROOT)
84
- end
84
+ new()
85
85
  end
86
86
 
87
87
  def self.find_best_version(version, candidates)
@@ -113,7 +113,7 @@ module RBS
113
113
  def lookup_path(gem, version)
114
114
  if gem_rbs = gems[gem]
115
115
  unless gem_rbs.empty?
116
- set = if v = Gem::Version.create(version)&.release
116
+ set = if version and v = Gem::Version.create(version)&.release
117
117
  gem_rbs.find_best_version(v)
118
118
  else
119
119
  gem_rbs.latest_version
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  module Resolver
3
5
  class ConstantResolver
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RBS
2
4
  module Resolver
3
5
  class TypeNameResolver