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
8 changes: 8 additions & 0 deletions scip_indexer/SCIPIndexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,14 @@ class AliasMap final {
if (sym == core::Symbols::Magic_undeclaredFieldStub()) {
ENFORCE(!bind.loc.empty());
ENFORCE(klass.isClassOrModule());
auto fieldName = instr->name.shortName(gs);
if (!fieldName.empty() && fieldName[0] == '$') {
auto klass = core::Symbols::rootSingleton();
this->map.insert( // no trim(...) because globals can't have a :: prefix
{bind.bind.variable,
{GenericSymbolRef::undeclaredField(klass, instr->name, bind.bind.type), bind.loc, false}});
continue;
}
auto result = findUnresolvedFieldTransitive(ctx, ctx.locAt(bind.loc), klass.asClassOrModuleRef(),
instr->name);
if (absl::holds_alternative<core::ClassOrModuleRef>(result)) {
Expand Down
18 changes: 18 additions & 0 deletions test/scip/testdata/globals.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# typed: true

$aa = 0

def f
$aa = 10
$bb = $aa
$aa = $bb
return
end

class C
def g
$c = $bb
end
end

puts $c
32 changes: 32 additions & 0 deletions test/scip/testdata/globals.snapshot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# typed: true

$aa = 0
#^^^ definition [..] `<Class:<root>>`#$aa.

def f
# ^ definition [..] Object#f().
$aa = 10
# ^^^ definition [..] `<Class:<root>>`#$aa.
$bb = $aa
# ^^^ definition [..] `<Class:<root>>`#$bb.
# ^^^ reference [..] `<Class:<root>>`#$aa.
$aa = $bb
# ^^^ reference (write) [..] `<Class:<root>>`#$aa.
# ^^^ reference [..] `<Class:<root>>`#$bb.
return
end

class C
# ^ definition [..] C#
def g
# ^ definition [..] C#g().
$c = $bb
# ^^ definition [..] `<Class:<root>>`#$c.
# ^^^^^^^^ reference [..] `<Class:<root>>`#$c.
# ^^^ reference [..] `<Class:<root>>`#$bb.
end
end

puts $c
#^^^^ reference [..] Kernel#puts().
# ^^ reference [..] `<Class:<root>>`#$c.