Skip to content
Merged
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
2 changes: 2 additions & 0 deletions lib/typeprof/core/ast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ def self.create_rbs_member(raw_decl, lenv)
SigAttrAccessorNode.new(raw_decl, lenv)
when RBS::AST::Declarations::Base
self.create_rbs_decl(raw_decl, lenv)
when RBS::AST::Members::InstanceVariable
SigInstanceVariableNode.new(raw_decl, lenv)
else
raise "unsupported: #{ raw_decl.class }"
end
Expand Down
38 changes: 38 additions & 0 deletions lib/typeprof/core/ast/sig_decl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,44 @@ def install0(genv)
end
end

class SigInstanceVariableNode < Node
def initialize(raw_decl, lenv)
super(raw_decl, lenv)
@var = raw_decl.name
@cpath = lenv.cref.cpath
@type = AST.create_rbs_type(raw_decl.type, lenv)
end

attr_reader :cpath, :type
def subnodes = { type: }
def attrs = { cpath: }

def define0(genv)
@type.define(genv)
mod = genv.resolve_ivar(cpath, false, @var)
mod.add_decl(self)
mod
end

def define_copy(genv)
mod = genv.resolve_ivar(cpath, false, @var)
mod.add_decl(self)
mod.remove_decl(@prev_node)
super(genv)
end

def undefine0(genv)
genv.resolve_ivar(cpath, false, @var).remove_decl(self)
@type.undefine(genv)
end

def install0(genv)
box = @changes.add_type_read_box(genv, @type)
@changes.add_edge(genv, box.ret, @static_ret.vtx)
box.ret
end
end

class SigGlobalVariableNode < Node
def initialize(raw_decl, lenv)
super(raw_decl, lenv)
Expand Down
16 changes: 16 additions & 0 deletions scenario/rbs/ivar.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## update: test.rbs
class Foo
@foo: String
end

## update: test.rb
class Foo
def check
@foo
end
end

## assert
class Foo
def check: -> String
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
def hello(name)
"Hello, #{ name }"
@name = name
"Hello, #{ @name }"
raise
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class MyDummyGem
@name: String
def hello: (String) -> :ok
end
end