Skip to content

Support RBS::AST::Members::ClassVariable #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2025
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 @@ -417,6 +417,8 @@ def self.create_rbs_member(raw_decl, lenv)
SigInstanceVariableNode.new(raw_decl, lenv, false)
when RBS::AST::Members::ClassInstanceVariable
SigInstanceVariableNode.new(raw_decl, lenv, true)
when RBS::AST::Members::ClassVariable
SigClassVariableNode.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 @@ -473,6 +473,44 @@ def install0(genv)
end
end

class SigClassVariableNode < 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)
cvar = genv.resolve_cvar(cpath, @var)
cvar.add_decl(self)
cvar
end

def define_copy(genv)
cvar = genv.resolve_cvar(cpath, @var)
cvar.add_decl(self)
cvar.remove_decl(@prev_node)
super(genv)
end

def undefine0(genv)
genv.resolve_cvar(cpath, @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/cvar.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: test.rb
class Foo
def check: -> String
end