diff --git a/lib/typeprof/core/ast/variable.rb b/lib/typeprof/core/ast/variable.rb index 49da27296..c5d959bc4 100644 --- a/lib/typeprof/core/ast/variable.rb +++ b/lib/typeprof/core/ast/variable.rb @@ -249,10 +249,24 @@ def retrieve_at(pos, &blk) class AliasGlobalVariableNode < Node def initialize(raw_node, lenv) super(raw_node, lenv) - # XXX: Who use this? I want to hard-code English.rb + @new_name = raw_node.new_name.name + @old_name = raw_node.old_name.name end + attr_reader :new_name, :old_name + + def attrs = { new_name:, old_name: } + def install0(genv) + new_vtx = genv.resolve_gvar(@new_name).vtx + old_vtx = genv.resolve_gvar(@old_name).vtx + # Go through intermediate vertices to avoid multi-edges when another + # alias node of the same variables exists + [[old_vtx, new_vtx], [new_vtx, old_vtx]].each do |src, dst| + vtx = Vertex.new(self) + @changes.add_edge(genv, src, vtx) + @changes.add_edge(genv, vtx, dst) + end Source.new(genv.nil_type) end end diff --git a/scenario/known-issues/alias-global-variable.rb b/scenario/known-issues/alias-global-variable.rb deleted file mode 100644 index be41f19f8..000000000 --- a/scenario/known-issues/alias-global-variable.rb +++ /dev/null @@ -1,15 +0,0 @@ -## update -def foo - $v = :ok -end - -def bar - alias $new_v $v - $new_v -end - -## assert -class Object - def foo: -> :ok - def bar: -> :ok -end diff --git a/scenario/variable/alias-global-variable.rb b/scenario/variable/alias-global-variable.rb new file mode 100644 index 000000000..7ec340cce --- /dev/null +++ b/scenario/variable/alias-global-variable.rb @@ -0,0 +1,51 @@ +## update +def foo + $v = :ok +end + +def bar + alias $new_v $v + $new_v +end + +## assert +class Object + def foo: -> :ok + def bar: -> :ok +end + +## update +def foo + $v = :ok +end + +def bar + alias $new_v $v + $new_v = 1 +end + +def baz + $v +end + +## assert +class Object + def foo: -> :ok + def bar: -> Integer + def baz: -> (:ok | Integer) +end + +## update +def foo + $v = :ok +end + +def bar + $new_v +end + +## assert +class Object + def foo: -> :ok + def bar: -> untyped +end