rbs 3.0.2 → 3.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9649673f547b364e4d635ab3f65b32a6edbf4e27c066672d07fbcd448c5d4117
4
- data.tar.gz: fdc3a315e87664045ac17752441f387626125645e9f1919d5bf7b6f1e74268d8
3
+ metadata.gz: be4870f9cbfced10b6cbfe578fc38429fa9c4232fe687a4a4e075a3970db2a0c
4
+ data.tar.gz: 837608d29d1541864457f307dbb52c9809bdc92325d8c255414c6034ba6f3b77
5
5
  SHA512:
6
- metadata.gz: 9f918e0459212a3c8d4b405955e62e14f21e99eb6fb71215feb22353ebb1aa1f2f1863bc7acb8b216ae7db5f98c975001dc45e45bc069354b2362f0a0f9064be
7
- data.tar.gz: 18f89a600eefa6de24f4daa699f101fa773ae116ea68c2924b2e2eac52d3b4b373018bf14c33c8fed2bb97e291d3cb998b42ca1d3355c5be92e50414662f9d20
6
+ metadata.gz: c3cb35ee898cfe7da1dedac7ff448a201391da32fab7aef37ef0547fb0bdfbf887b8c72fdb2351357501811bfbe6c14f018de92f4ccb81d21833be03b243bcf4
7
+ data.tar.gz: 838ef9460abf1ba9e59ae8b5a70a704b1a3b931f83ef86f111f6729434e28680e26df3f2dc5ee367a9b28019fdd542272873eac44a200bf7f70438371582494b
data/CHANGELOG.md CHANGED
@@ -2,6 +2,26 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 3.0.4 (2023-03-13)
6
+
7
+ ### Library changes
8
+
9
+ * Add missing implementation to support class/module alias ([#1271](https://github.com/ruby/rbs/pull/1271))
10
+
11
+ ## 3.0.3 (2023-03-07)
12
+
13
+ ### Library changes
14
+
15
+ * Fix `DefinitionBuilder` ([\#1268](https://github.com/ruby/rbs/pull/1268))
16
+
17
+ #### rbs collection
18
+
19
+ * Skip dependencies not included in `Gemfile.lock` ([\#1266](https://github.com/ruby/rbs/pull/1266))
20
+
21
+ ### Miscellaneous
22
+
23
+ * Skip RBS validation on Ruby CI ([\#1264](https://github.com/ruby/rbs/pull/1264), [\#1263](https://github.com/ruby/rbs/pull/1263))
24
+
5
25
  ## 3.0.2 (2023-03-01)
6
26
 
7
27
  ### Library changes
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbs (3.0.2)
4
+ rbs (3.0.4)
5
5
 
6
6
  PATH
7
7
  remote: test/assets/test-gem
@@ -115,4 +115,4 @@ DEPENDENCIES
115
115
  test-unit
116
116
 
117
117
  BUNDLED WITH
118
- 2.4.6
118
+ 2.4.7
data/Rakefile CHANGED
@@ -59,7 +59,17 @@ task :validate => :compile do
59
59
  sh "#{ruby} #{rbs} validate --silent"
60
60
 
61
61
  libs = FileList["stdlib/*"].map {|path| File.basename(path).to_s }
62
- libs << "rbs"
62
+
63
+ # Skip RBS validation because Ruby CI runs without rubygems
64
+ case skip_rbs_validation = ENV["SKIP_RBS_VALIDATION"]
65
+ when nil
66
+ libs << "rbs"
67
+ when "true"
68
+ # Skip
69
+ else
70
+ STDERR.puts "🚨🚨🚨🚨 SKIP_RBS_VALIDATION is expected to be `true` or unset, given `#{skip_rbs_validation}` 🚨🚨🚨🚨"
71
+ libs << "rbs"
72
+ end
63
73
 
64
74
  libs.each do |lib|
65
75
  sh "#{ruby} #{rbs} -r #{lib} validate --silent"
data/lib/rbs/cli.rb CHANGED
@@ -230,6 +230,19 @@ EOB
230
230
  end
231
231
  end
232
232
  end
233
+
234
+ env.class_alias_decls.each do |name, entry|
235
+ case entry
236
+ when Environment::ModuleAliasEntry
237
+ if list.include?(:module)
238
+ stdout.puts "#{name} (module alias)"
239
+ end
240
+ when Environment::ClassAliasEntry
241
+ if list.include?(:class)
242
+ stdout.puts "#{name} (class alias)"
243
+ end
244
+ end
245
+ end
233
246
  end
234
247
 
235
248
  if list.include?(:interface)
@@ -272,7 +285,10 @@ EOU
272
285
  builder = DefinitionBuilder::AncestorBuilder.new(env: env)
273
286
  type_name = TypeName(args[0]).absolute!
274
287
 
275
- if env.class_decls.key?(type_name)
288
+ case env.constant_entry(type_name)
289
+ when Environment::ClassEntry, Environment::ModuleEntry, Environment::ClassAliasEntry, Environment::ModuleAliasEntry
290
+ type_name = env.normalize_module_name(type_name)
291
+
276
292
  ancestors = case kind
277
293
  when :instance
278
294
  builder.instance_ancestors(type_name)
@@ -334,7 +350,7 @@ EOU
334
350
  builder = DefinitionBuilder.new(env: env)
335
351
  type_name = TypeName(args[0]).absolute!
336
352
 
337
- if env.class_decls.key?(type_name)
353
+ if env.module_name?(type_name)
338
354
  definition = case kind
339
355
  when :instance
340
356
  builder.build_instance(type_name)
@@ -388,7 +404,7 @@ EOU
388
404
  type_name = TypeName(args[0]).absolute!
389
405
  method_name = args[1].to_sym
390
406
 
391
- unless env.class_decls.key?(type_name)
407
+ unless env.module_name?(type_name)
392
408
  stdout.puts "Cannot find class: #{type_name}"
393
409
  return
394
410
  end
@@ -75,8 +75,9 @@ module RBS
75
75
  next
76
76
  end
77
77
 
78
- spec = gem_hash[dep.name] or raise "Cannot find `#{dep.name}` in bundler context"
79
- assign_gem(name: dep.name, version: spec.version, ignored_gems: ignored_gems, src_data: nil)
78
+ if spec = gem_hash[dep.name]
79
+ assign_gem(name: dep.name, version: spec.version, ignored_gems: ignored_gems, src_data: nil)
80
+ end
80
81
  end
81
82
 
82
83
  lockfile.lockfile_path.write(YAML.dump(lockfile.to_lockfile))
@@ -131,8 +132,9 @@ module RBS
131
132
  end
132
133
 
133
134
  gem_hash[name].dependencies.each do |dep|
134
- spec = gem_hash[dep.name]
135
- assign_gem(name: dep.name, version: spec.version, src_data: nil, ignored_gems: ignored_gems)
135
+ if spec = gem_hash[dep.name]
136
+ assign_gem(name: dep.name, version: spec.version, src_data: nil, ignored_gems: ignored_gems)
137
+ end
136
138
  end
137
139
  end
138
140
 
@@ -432,8 +432,9 @@ module RBS
432
432
  super_name = super_class.name
433
433
  super_args = super_class.args
434
434
 
435
- super_ancestors = instance_ancestors(super_name, building_ancestors: building_ancestors)
436
- ancestors.unshift(*super_ancestors.apply(super_args, location: entry.primary.decl.location))
435
+ super_ancestors = instance_ancestors(super_name, building_ancestors: building_ancestors).apply(super_args, location: entry.primary.decl.location)
436
+ super_ancestors.map! {|ancestor| fill_ancestor_source(ancestor, name: super_name, source: :super) }
437
+ ancestors.unshift(*super_ancestors)
437
438
  end
438
439
  end
439
440
 
@@ -450,8 +451,9 @@ module RBS
450
451
  included_modules.each do |mod|
451
452
  name = mod.name
452
453
  arg_types = mod.args
453
- mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors)
454
- ancestors.unshift(*mod_ancestors.apply(arg_types, location: entry.primary.decl.location))
454
+ mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors).apply(arg_types, location: entry.primary.decl.location)
455
+ mod_ancestors.map! {|ancestor| fill_ancestor_source(ancestor, name: name, source: mod.source) }
456
+ ancestors.unshift(*mod_ancestors)
455
457
  end
456
458
  end
457
459
 
@@ -461,8 +463,9 @@ module RBS
461
463
  prepended_modules.each do |mod|
462
464
  name = mod.name
463
465
  arg_types = mod.args
464
- mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors)
465
- ancestors.unshift(*mod_ancestors.apply(arg_types, location: entry.primary.decl.location))
466
+ mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors).apply(arg_types, location: entry.primary.decl.location)
467
+ mod_ancestors.map! {|ancestor| fill_ancestor_source(ancestor, name: name, source: mod.source) }
468
+ ancestors.unshift(*mod_ancestors)
466
469
  end
467
470
  end
468
471
 
@@ -495,8 +498,9 @@ module RBS
495
498
  super_name = super_class.name
496
499
  super_args = super_class.args
497
500
 
498
- super_ancestors = instance_ancestors(super_name, building_ancestors: building_ancestors)
499
- ancestors.unshift(*super_ancestors.apply(super_args, location: entry.primary.decl.location))
501
+ super_ancestors = instance_ancestors(super_name, building_ancestors: building_ancestors).apply(super_args, location: entry.primary.decl.location)
502
+ super_ancestors.map! {|ancestor| fill_ancestor_source(ancestor, name: super_name, source: :super) }
503
+ ancestors.unshift(*super_ancestors)
500
504
 
501
505
  when Definition::Ancestor::Singleton
502
506
  super_name = super_class.name
@@ -509,8 +513,9 @@ module RBS
509
513
  extended_modules.each do |mod|
510
514
  name = mod.name
511
515
  args = mod.args
512
- mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors)
513
- ancestors.unshift(*mod_ancestors.apply(args, location: entry.primary.decl.location))
516
+ mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors).apply(args, location: entry.primary.decl.location)
517
+ mod_ancestors.map! {|ancestor| fill_ancestor_source(ancestor, name: name, source: mod.source) }
518
+ ancestors.unshift(*mod_ancestors)
514
519
  end
515
520
 
516
521
  ancestors.unshift(self_ancestor)
@@ -541,9 +546,9 @@ module RBS
541
546
 
542
547
  included_interfaces = one_ancestors.included_interfaces or raise
543
548
  included_interfaces.each do |a|
544
- included_ancestors = interface_ancestors(a.name, building_ancestors: building_ancestors)
545
-
546
- ancestors.unshift(*included_ancestors.apply(a.args, location: entry.decl.location))
549
+ included_ancestors = interface_ancestors(a.name, building_ancestors: building_ancestors).apply(a.args, location: entry.decl.location)
550
+ included_ancestors.map! {|ancestor| fill_ancestor_source(ancestor, name: a.name, source: a.source) }
551
+ ancestors.unshift(*included_ancestors)
547
552
  end
548
553
 
549
554
  ancestors.unshift(self_ancestor)
@@ -555,6 +560,19 @@ module RBS
555
560
  ancestors: ancestors
556
561
  )
557
562
  end
563
+
564
+ def fill_ancestor_source(ancestor, name:, source:, &block)
565
+ case ancestor
566
+ when Definition::Ancestor::Instance
567
+ if ancestor.name == name && !ancestor.source
568
+ Definition::Ancestor::Instance.new(name: ancestor.name, args: ancestor.args, source: source)
569
+ else
570
+ ancestor
571
+ end
572
+ else
573
+ ancestor
574
+ end
575
+ end
558
576
  end
559
577
  end
560
578
  end
@@ -31,9 +31,10 @@ module RBS
31
31
  end
32
32
 
33
33
  def define_interface(definition, type_name, subst)
34
- included_interfaces = ancestor_builder.one_interface_ancestors(type_name).included_interfaces or raise
35
- interface_methods = interface_methods(included_interfaces)
34
+ included_interfaces = ancestor_builder.interface_ancestors(type_name).ancestors #: Array[Definition::Ancestor::Instance]
35
+ included_interfaces = included_interfaces.reject {|ancestor| ancestor.source == nil }
36
36
 
37
+ interface_methods = interface_methods(included_interfaces)
37
38
  methods = method_builder.build_interface(type_name)
38
39
 
39
40
  import_methods(definition, type_name, methods, interface_methods, subst)
@@ -55,7 +56,6 @@ module RBS
55
56
  Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
56
57
  methods = method_builder.build_interface(type_name)
57
58
  one_ancestors = ancestor_builder.one_interface_ancestors(type_name)
58
-
59
59
  validate_type_params(definition, methods: methods, ancestors: one_ancestors)
60
60
 
61
61
  define_interface(definition, type_name, subst)
@@ -94,7 +94,12 @@ module RBS
94
94
  define_instance(definition, mod.name, subst + tapp_subst(mod.name, mod.args))
95
95
  end
96
96
 
97
- interface_methods = interface_methods(one_ancestors.each_included_interface.to_a)
97
+ all_interfaces = one_ancestors.each_included_interface.flat_map do |interface|
98
+ other_interfaces = ancestor_builder.interface_ancestors(interface.name).ancestors #: Array[Definition::Ancestor::Instance]
99
+ other_interfaces = other_interfaces.select {|ancestor| ancestor.source }
100
+ [interface, *other_interfaces]
101
+ end
102
+ interface_methods = interface_methods(all_interfaces)
98
103
  import_methods(definition, type_name, methods, interface_methods, subst)
99
104
 
100
105
  one_ancestors.each_prepended_module do |mod|
@@ -219,6 +224,7 @@ module RBS
219
224
 
220
225
  Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
221
226
  one_ancestors = ancestor_builder.one_singleton_ancestors(type_name)
227
+ methods = method_builder.build_singleton(type_name)
222
228
 
223
229
  if super_class = one_ancestors.super_class
224
230
  case super_class
@@ -233,8 +239,13 @@ module RBS
233
239
  definition.class_variables.merge!(defn.class_variables)
234
240
  end
235
241
 
236
- one_ancestors = ancestor_builder.one_singleton_ancestors(type_name)
237
- methods = method_builder.build_singleton(type_name)
242
+ all_interfaces = one_ancestors.each_extended_interface.flat_map do |interface|
243
+ other_interfaces = ancestor_builder.interface_ancestors(interface.name).ancestors #: Array[Definition::Ancestor::Instance]
244
+ other_interfaces = other_interfaces.select {|ancestor| ancestor.source }
245
+ [interface, *other_interfaces]
246
+ end
247
+ interface_methods = interface_methods(all_interfaces)
248
+ import_methods(definition, type_name, methods, interface_methods, Substitution.new)
238
249
 
239
250
  one_ancestors.each_extended_module do |mod|
240
251
  mod.args.each do |arg|
@@ -279,7 +290,7 @@ module RBS
279
290
 
280
291
  def build_singleton(type_name)
281
292
  type_name = env.normalize_module_name(type_name)
282
-
293
+
283
294
  try_cache type_name, cache: singleton_cache do
284
295
  entry = env.class_decls[type_name] or raise "Unknown name for build_singleton: #{type_name}"
285
296
  ensure_namespace!(type_name.namespace, location: entry.decls[0].decl.location)
@@ -683,8 +694,8 @@ module RBS
683
694
  Definition::Method::TypeDef.new(
684
695
  type: method_type,
685
696
  member: original,
686
- defined_in: definition.type_name,
687
- implemented_in: definition.type_name
697
+ defined_in: defined_in,
698
+ implemented_in: implemented_in
688
699
  )
689
700
  ],
690
701
  accessibility: method.accessibility,
@@ -713,7 +724,7 @@ module RBS
713
724
  method_definition = Definition::Method.new(
714
725
  super_method: super_method,
715
726
  defs: existing_method.defs.map do |defn|
716
- defn.update(implemented_in: definition.type_name)
727
+ defn.update(implemented_in: implemented_in)
717
728
  end,
718
729
  accessibility: existing_method.accessibility,
719
730
  alias_of: existing_method.alias_of
@@ -725,8 +736,8 @@ module RBS
725
736
  type_def = Definition::Method::TypeDef.new(
726
737
  type: subst.empty? ? overload.method_type : overload.method_type.sub(subst),
727
738
  member: overloading_def,
728
- defined_in: definition.type_name,
729
- implemented_in: definition.type_name
739
+ defined_in: defined_in,
740
+ implemented_in: implemented_in
730
741
  )
731
742
 
732
743
  method_definition.defs.unshift(type_def)
@@ -135,7 +135,7 @@ module RBS
135
135
 
136
136
  type_params = case type
137
137
  when Types::ClassInstance
138
- env.class_decls[type.name].type_params
138
+ env.class_decls[env.normalize_module_name(type.name)].type_params
139
139
  when Types::Interface
140
140
  env.interface_decls[type.name].decl.type_params
141
141
  when Types::Alias
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.0.2"
4
+ VERSION = "3.0.4"
5
5
  end
@@ -154,6 +154,10 @@ module RBS
154
154
  prepended_modules: Array[Definition::Ancestor::Instance]?,
155
155
  extended_modules: Array[Definition::Ancestor::Instance]?,
156
156
  extended_interfaces: Array[Definition::Ancestor::Instance]?) -> void
157
+
158
+ # Fill `#source` of instance ancestor if `ancestor.name == name` and its `source` is `nil`
159
+ #
160
+ def fill_ancestor_source: (Definition::Ancestor::t, name: TypeName, source: Definition::Ancestor::Instance::source) -> Definition::Ancestor::t
157
161
  end
158
162
  end
159
163
  end
data/sig/definition.rbs CHANGED
@@ -83,8 +83,9 @@ module RBS
83
83
  type t = Instance | Singleton
84
84
 
85
85
  class Instance
86
- type source = :super | nil
87
- | AST::Members::Include | AST::Members::Extend | AST::Members::Prepend
86
+ type source = :super # Inheritance
87
+ | nil # Itself
88
+ | AST::Members::Include | AST::Members::Extend | AST::Members::Prepend # AST
88
89
  | AST::Declarations::Module::Self
89
90
 
90
91
  attr_reader name: TypeName
@@ -142,6 +142,10 @@ module RBS
142
142
  #
143
143
  def define_instance: (Definition definition, TypeName type_name, Substitution subst) -> void
144
144
 
145
+ # Updates `definition` with methods defined in an interface `type_name`
146
+ #
147
+ # It processes includes recursively
148
+ #
145
149
  def define_interface: (Definition definition, TypeName type_name, Substitution subst) -> void
146
150
 
147
151
  # Returns a substitution that corresponds to type application
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-01 00:00:00.000000000 Z
11
+ date: 2023-03-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: RBS is the language for type signatures for Ruby and standard library
14
14
  definitions.