Skip to content

Commit 1b61970

Browse files
committed
Support RBS::AST::Members::ClassInstanceVariable
1 parent dda1141 commit 1b61970

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

lib/typeprof/core/ast.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,9 @@ def self.create_rbs_member(raw_decl, lenv)
414414
when RBS::AST::Declarations::Base
415415
self.create_rbs_decl(raw_decl, lenv)
416416
when RBS::AST::Members::InstanceVariable
417-
SigInstanceVariableNode.new(raw_decl, lenv)
417+
SigInstanceVariableNode.new(raw_decl, lenv, false)
418+
when RBS::AST::Members::ClassInstanceVariable
419+
SigInstanceVariableNode.new(raw_decl, lenv, true)
418420
else
419421
raise "unsupported: #{ raw_decl.class }"
420422
end

lib/typeprof/core/ast/sig_decl.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,33 +435,34 @@ def install0(genv)
435435
end
436436

437437
class SigInstanceVariableNode < Node
438-
def initialize(raw_decl, lenv)
438+
def initialize(raw_decl, lenv, class_scope)
439439
super(raw_decl, lenv)
440440
@var = raw_decl.name
441441
@cpath = lenv.cref.cpath
442+
@class_scope = class_scope
442443
@type = AST.create_rbs_type(raw_decl.type, lenv)
443444
end
444445

445-
attr_reader :cpath, :type
446+
attr_reader :cpath, :class_scope, :type
446447
def subnodes = { type: }
447-
def attrs = { cpath: }
448+
def attrs = { cpath:, class_scope: }
448449

449450
def define0(genv)
450451
@type.define(genv)
451-
mod = genv.resolve_ivar(cpath, false, @var)
452+
mod = genv.resolve_ivar(cpath, @class_scope, @var)
452453
mod.add_decl(self)
453454
mod
454455
end
455456

456457
def define_copy(genv)
457-
mod = genv.resolve_ivar(cpath, false, @var)
458+
mod = genv.resolve_ivar(cpath, @class_scope, @var)
458459
mod.add_decl(self)
459460
mod.remove_decl(@prev_node)
460461
super(genv)
461462
end
462463

463464
def undefine0(genv)
464-
genv.resolve_ivar(cpath, false, @var).remove_decl(self)
465+
genv.resolve_ivar(cpath, @class_scope, @var).remove_decl(self)
465466
@type.undefine(genv)
466467
end
467468

scenario/rbs/ivar.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
## update: test.rbs
22
class Foo
33
@foo: String
4+
self.@foo: Integer
45
end
56

67
## update: test.rb
78
class Foo
89
def check
910
@foo
1011
end
12+
def self.check
13+
@foo
14+
end
1115
end
1216

1317
## assert
1418
class Foo
1519
def check: -> String
20+
def self.check: -> Integer
1621
end

0 commit comments

Comments
 (0)