diff --git a/lib/typeprof/core/service.rb b/lib/typeprof/core/service.rb index f0fa098e..ce5ffd60 100644 --- a/lib/typeprof/core/service.rb +++ b/lib/typeprof/core/service.rb @@ -456,6 +456,7 @@ def superclass_source_is_toplevel?(const_node) def dump_declarations(path) stack = [] out = [] + seen_consts = Set.empty @rb_text_nodes[path]&.traverse do |event, node| case node when AST::ModuleNode @@ -508,7 +509,14 @@ def dump_declarations(path) when AST::ConstantWriteNode if node.static_cpath if event == :enter - out << " " * stack.size + "#{ format_declared_const_path(node.static_cpath, stack) }: #{ node.ret.show }" + unless seen_consts.include?(node.static_cpath) + seen_consts << node.static_cpath + cdef = @genv.resolve_const(node.static_cpath) + # Use the assigned value for a single write so a same-named class + # or module (e.g. declared in RBS) is not mixed in; union the types otherwise. + ret = cdef.defs.size > 1 ? cdef.vtx : node.ret + out << " " * stack.size + "#{ format_declared_const_path(node.static_cpath, stack) }: #{ ret.show }" + end end end else diff --git a/scenario/known-issues/multi-const-write.rb b/scenario/const/multi-const-write.rb similarity index 100% rename from scenario/known-issues/multi-const-write.rb rename to scenario/const/multi-const-write.rb diff --git a/scenario/variable/operator_write.rb b/scenario/variable/operator_write.rb index d4fb7094..34dbb7e9 100644 --- a/scenario/variable/operator_write.rb +++ b/scenario/variable/operator_write.rb @@ -42,7 +42,6 @@ def test_attr=(x) ## diagnostics ## assert class C - D: Integer D: Integer def get_lv: -> Integer def set_iv: -> Integer @@ -56,4 +55,3 @@ def test_attr: -> Integer def test_attr=: (Integer) -> Integer end C::E: Integer -C::E: Integer