Skip to content

Commit 4381edb

Browse files
pvcresincursoragent
andcommitted
Fix superclass path rendering to add :: prefix when needed
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 79fc821 commit 4381edb

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

lib/typeprof/core/service.rb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,30 @@ def format_declared_const_path(cpath, stack)
429429
rel_cpath.empty? ? cpath.join("::") : rel_cpath.join("::")
430430
end
431431

432+
def format_superclass_path(node, superclass)
433+
sc_path = superclass.show_cpath
434+
435+
if node.is_a?(AST::ClassNode) && node.superclass_cpath
436+
sc_node = node.superclass_cpath
437+
if superclass_source_is_toplevel?(sc_node)
438+
return "::#{ sc_path }"
439+
end
440+
441+
if node.static_cpath && node.static_cpath.size > 1 &&
442+
superclass.cpath == [node.static_cpath.last]
443+
return "::#{ sc_path }"
444+
end
445+
end
446+
447+
sc_path
448+
end
449+
450+
def superclass_source_is_toplevel?(const_node)
451+
return false unless const_node.is_a?(AST::ConstantReadNode)
452+
return true if const_node.toplevel
453+
const_node.cbase ? superclass_source_is_toplevel?(const_node.cbase) : false
454+
end
455+
432456
def dump_declarations(path)
433457
stack = []
434458
out = []
@@ -459,7 +483,7 @@ def dump_declarations(path)
459483
if superclass == nil
460484
s << " # failed to identify its superclass"
461485
elsif superclass.cpath != []
462-
s << " < #{ superclass.show_cpath }"
486+
s << " < #{ format_superclass_path(node, superclass) }"
463487
end
464488
if stack == [:toplevel]
465489
out << "end"
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class Bar < ::Foo::Bar
1818
end
1919
end
2020
end
21-
2221
module Foo
2322
class Bar
2423
end
@@ -36,7 +35,6 @@ class Foo < Foo
3635
## assert: test.rb
3736
class Foo
3837
end
39-
4038
module Bar
4139
class Foo < ::Foo
4240
end

0 commit comments

Comments
 (0)