Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/typeprof/core/ast/variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions scenario/known-issues/alias-global-variable.rb

This file was deleted.

51 changes: 51 additions & 0 deletions scenario/variable/alias-global-variable.rb
Original file line number Diff line number Diff line change
@@ -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
Loading