archspec 1.2.0 → 1.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb5f7cda6a11326fedead006aa062155c7fdb2e1a3ea6e374d5cd1bca45d17e9
4
- data.tar.gz: 417ad99fbfc27aa871fcb0bd4ce3ced72d8c1aad3810d35f51722586a151bf81
3
+ metadata.gz: 3730b633403300a38b3b8e610337842c108e1bb50fb4a85818049e6ffbc2f267
4
+ data.tar.gz: a0e721961262e498e616db17571a44b8873bfbd0ecbf639011c0918949d1f3b4
5
5
  SHA512:
6
- metadata.gz: 2dc335e5f43af785346921ca4b57e699a5b748d80e09441ac3abe6123ba7b17a730dba2a7c0f7c4c0c11b6288dc7e79ee87e95d8f9454a167df7d98a98de88d5
7
- data.tar.gz: 8b5736b3d23a1c053f8e158636a8582184c9c924ce478e1019818b527960ada6c8d5d7ab4e581849564978ae4c4f05d4238c0a571bf8d78ef479fb6242bc3868
6
+ metadata.gz: 0a54940cfe0e889668c1aa55783b7b9eafb443dfbb7e3f87b1c0827fd0a64bc7d0987398f678fa6fae0a80ae7e8048b42fddf1b43791e6a7b672c1aa8bbf3fdf
7
+ data.tar.gz: 5777a22a99b1614a9856d51b4af7d42366312d987c4973f315b4c5efba59f04e5626b8905c6917dd50956318c1e7f6db884c40f46b8323d2d8765beb4481decc
@@ -162,7 +162,7 @@ module ArchSpec
162
162
  :dynamic_superclass
163
163
  )
164
164
  MethodFallback = Data.define(:path, :owner, :name, :scope, :location, :visibility, :signatures)
165
- MixinFallback = Data.define(:path, :owner, :message, :target, :location, :nesting)
165
+ MixinFallback = Data.define(:path, :owner, :receiver, :message, :target, :location, :nesting)
166
166
 
167
167
  DYNAMIC_MESSAGES = %i[
168
168
  class_eval
@@ -272,7 +272,7 @@ module ArchSpec
272
272
  apply_generated_methods(graph)
273
273
  @extra_edges.each { |edge| graph.add_edge(**edge) }
274
274
  call_sites.each do |site|
275
- resolution = call_resolutions[site]
275
+ resolution = call_resolutions[site] || undeclared_receiver(graph, site)
276
276
  resolved_method = graph.resolve_method_alias(resolution.receiver, site.name, resolution.scope) if resolution
277
277
  graph.add_edge(
278
278
  type: :calls_named_method,
@@ -288,6 +288,18 @@ module ArchSpec
288
288
  end
289
289
  end
290
290
 
291
+ # A constant the index can't resolve, such as a gem's, is still the
292
+ # receiver its name says: a nested constant of that name if the graph has
293
+ # one, otherwise the name as written.
294
+ def undeclared_receiver(graph, site)
295
+ return unless site.receiver_name
296
+
297
+ name = site.receiver_name
298
+ receiver = name.start_with?('::') ? name.delete_prefix('::') :
299
+ graph.resolve_constant_reference(name, site.owner, lexical_nesting: site.nesting)
300
+ CallResolution.new(receiver, :class)
301
+ end
302
+
291
303
  def declaration_kind(name, path)
292
304
  @declaration_kinds[[normalize(name), path]]
293
305
  end
@@ -755,11 +767,17 @@ module ArchSpec
755
767
  @generated_methods << GeneratedMethod.new(path, owner, message, node, location, visibility, scope)
756
768
  end
757
769
 
770
+ # Worker.prepend(Poller) mixes Poller into Worker, not into the class
771
+ # whose body makes the call. A receiver that isn't a constant, such as
772
+ # tool.class.prepend(Guard), names nothing we can record it on.
758
773
  def record_mixin_fallback(path, node, message, owner, location, nesting)
759
774
  return unless MIXIN_EDGE_TYPES.key?(message)
760
775
 
776
+ receiver = constant_reference_name(node.receiver)
777
+ return unless receiver_kind(node) == :none || receiver
778
+
761
779
  constant_arguments(node).each do |target|
762
- @mixin_fallbacks << MixinFallback.new(path, owner, message, target, location, nesting)
780
+ @mixin_fallbacks << MixinFallback.new(path, owner, receiver, message, target, location, nesting)
763
781
  end
764
782
  end
765
783
 
@@ -826,17 +844,20 @@ module ArchSpec
826
844
  def apply_mixin_fallbacks(graph)
827
845
  @mixin_fallbacks.each do |fallback|
828
846
  type = MIXIN_EDGE_TYPES.fetch(fallback.message)
847
+ owner = mixin_owner(graph, fallback)
829
848
  next if graph.edges.any? do |edge|
830
- edge.type == type && edge.from_path == fallback.path && edge.from_constant == fallback.owner &&
849
+ edge.type == type && edge.from_path == fallback.path && edge.from_constant == owner &&
831
850
  edge.to == fallback.target
832
851
  end
833
852
 
834
- constant = graph.constants_named(fallback.owner).find { |candidate| candidate.path == fallback.path }
835
- constant&.add_mixin(fallback.message, fallback.target)
853
+ nodes = graph.constants_named(owner)
854
+ constant = nodes.find { |candidate| candidate.path == fallback.path } ||
855
+ (nodes.find { |candidate| !candidate.namespace_only } if fallback.receiver)
856
+ constant&.add_mixin(fallback.message, mixin_target(graph, fallback))
836
857
  graph.add_edge(
837
858
  type: type,
838
859
  from_path: fallback.path,
839
- from_constant: fallback.owner,
860
+ from_constant: owner,
840
861
  to: fallback.target,
841
862
  location: fallback.location,
842
863
  lexical_nesting: fallback.nesting
@@ -844,6 +865,21 @@ module ArchSpec
844
865
  end
845
866
  end
846
867
 
868
+ def mixin_owner(graph, fallback)
869
+ return fallback.owner unless fallback.receiver
870
+
871
+ graph.resolve_constant_reference(fallback.receiver, fallback.owner, lexical_nesting: fallback.nesting)
872
+ end
873
+
874
+ # The receiver's own node resolves its mixins from its own scope, so a
875
+ # module named from another class's body is recorded by its full name.
876
+ def mixin_target(graph, fallback)
877
+ return fallback.target unless fallback.receiver
878
+
879
+ resolved = graph.resolve_constant_reference(fallback.target, fallback.owner, lexical_nesting: fallback.nesting)
880
+ graph.constants_named(resolved).any? ? "::#{resolved}" : fallback.target
881
+ end
882
+
847
883
  def set_fallback_visibility(path, owner, names, scope, visibility)
848
884
  method_names = names.map { |name| name.unescaped.to_sym }
849
885
  @method_fallbacks.map! do |fallback|
@@ -35,9 +35,7 @@ module ArchSpec
35
35
  next if consumers.empty?
36
36
 
37
37
  target = graph.resolve_edge_constant(edge)
38
- owner = [edge.from_constant, *consumers]
39
- .select { |namespace| within_namespace?(target, namespace) }
40
- .max_by(&:length)
38
+ owner = definer(graph, target)
41
39
  next unless consumers.include?(owner)
42
40
 
43
41
  Diagnostic.new(
@@ -51,8 +49,16 @@ module ArchSpec
51
49
 
52
50
  private
53
51
 
54
- def within_namespace?(constant, namespace)
55
- constant == namespace || constant.start_with?("#{namespace}::")
52
+ # The class or module a reference reaches: the constant itself when it
53
+ # names one, or the namespace whose body defines a value constant.
54
+ # Chat::Interruptions::GRACE belongs to the concern Chat::Interruptions,
55
+ # and Chat::Closure is a class of its own, so neither names the includer
56
+ # Chat; Chat::LIMIT does.
57
+ def definer(graph, constant)
58
+ return constant if graph.constants_named(constant).any? { |node| node.class? || node.module? }
59
+
60
+ namespace, separator, = constant.rpartition('::')
61
+ separator.empty? ? constant : namespace
56
62
  end
57
63
 
58
64
  # Maps each mixed-in module to the set of constants that mix it in.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ArchSpec
4
- VERSION = '1.2.0'
4
+ VERSION = '1.2.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: archspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carmine Paolino
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-01 00:00:00.000000000 Z
11
+ date: 2026-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: herb