Skip to content

Commit c8d283e

Browse files
committed
Support RBS::AST::Members::ClassVariable
This supports class variables ( `@@var` ) in RBS files.
1 parent 1b61970 commit c8d283e

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

lib/typeprof/core/ast.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,8 @@ def self.create_rbs_member(raw_decl, lenv)
417417
SigInstanceVariableNode.new(raw_decl, lenv, false)
418418
when RBS::AST::Members::ClassInstanceVariable
419419
SigInstanceVariableNode.new(raw_decl, lenv, true)
420+
when RBS::AST::Members::ClassVariable
421+
SigClassVariableNode.new(raw_decl, lenv)
420422
else
421423
raise "unsupported: #{ raw_decl.class }"
422424
end

lib/typeprof/core/ast/sig_decl.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,44 @@ def install0(genv)
473473
end
474474
end
475475

476+
class SigClassVariableNode < Node
477+
def initialize(raw_decl, lenv)
478+
super(raw_decl, lenv)
479+
@var = raw_decl.name
480+
@cpath = lenv.cref.cpath
481+
@type = AST.create_rbs_type(raw_decl.type, lenv)
482+
end
483+
484+
attr_reader :cpath, :type
485+
def subnodes = { type: }
486+
def attrs = { cpath: }
487+
488+
def define0(genv)
489+
@type.define(genv)
490+
cvar = genv.resolve_cvar(cpath, @var)
491+
cvar.add_decl(self)
492+
cvar
493+
end
494+
495+
def define_copy(genv)
496+
cvar = genv.resolve_cvar(cpath, @var)
497+
cvar.add_decl(self)
498+
cvar.remove_decl(@prev_node)
499+
super(genv)
500+
end
501+
502+
def undefine0(genv)
503+
genv.resolve_cvar(cpath, @var).remove_decl(self)
504+
@type.undefine(genv)
505+
end
506+
507+
def install0(genv)
508+
box = @changes.add_type_read_box(genv, @type)
509+
@changes.add_edge(genv, box.ret, @static_ret.vtx)
510+
box.ret
511+
end
512+
end
513+
476514
class SigGlobalVariableNode < Node
477515
def initialize(raw_decl, lenv)
478516
super(raw_decl, lenv)

scenario/rbs/cvar.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## update: test.rbs
2+
class Foo
3+
@@foo: String
4+
end
5+
6+
## update: test.rb
7+
class Foo
8+
def check
9+
@@foo
10+
end
11+
end
12+
13+
## assert: test.rb
14+
class Foo
15+
def check: -> String
16+
end

0 commit comments

Comments
 (0)