Skip to content

Commit 4eadc0f

Browse files
fix: Fix crash with default arguments. (#24)
1 parent 7fabb47 commit 4eadc0f

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

scip_indexer/SCIPIndexer.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,10 @@ class CFGTraversal final {
825825
}
826826
// For aliases, don't emit an occurrence for the LHS; it will be emitted
827827
// when the alias is used or separately at the end. See NOTE[alias-handling].
828-
if (binding.value.tag() != cfg::Tag::Alias) {
828+
//
829+
// For ArgPresent instructions (which come up with default arguments), we will
830+
// emit defs/refs for direct usages, so don't emit a local for the temporary here.
831+
if (binding.value.tag() != cfg::Tag::Alias && binding.value.tag() != cfg::Tag::ArgPresent) {
829832
// Emit occurrence information for the LHS
830833
auto occ = cfg::LocalOccurrence{binding.bind.variable, lhsLocIfPresent(binding)};
831834
this->emitLocalOccurrence(cfg, bb, occ, ValueCategory::LValue);

test/scip/testdata/args.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,16 @@ def args(x, y)
99
end
1010
z
1111
end
12+
13+
def keyword_args(w:, x: 3, y: [], **kwargs)
14+
y << w + x
15+
y << [a]
16+
return
17+
end
18+
19+
def use_kwargs
20+
h = { a: 3 }
21+
keyword_args(w: 0, **h)
22+
keyword_args(w: 0, x: 1, y: [2], **h)
23+
return
24+
end

test/scip/testdata/args.snapshot.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,30 @@ def args(x, y)
2323
z
2424
# ^ reference local 3~#2634721084
2525
end
26+
27+
def keyword_args(w:, x: 3, y: [], **kwargs)
28+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition scip-ruby gem TODO TODO Object#keyword_args().
29+
# ^^ definition local 1~#3526982640
30+
# ^^ definition local 2~#3526982640
31+
# ^^ definition local 3~#3526982640
32+
y << w + x
33+
# ^ reference local 3~#3526982640
34+
# ^ reference local 1~#3526982640
35+
# ^ reference local 2~#3526982640
36+
y << [a]
37+
# ^ reference local 3~#3526982640
38+
return
39+
end
40+
41+
def use_kwargs
42+
#^^^^^^^^^^^^^^ definition scip-ruby gem TODO TODO Object#use_kwargs().
43+
h = { a: 3 }
44+
# ^ definition local 1~#571973038
45+
keyword_args(w: 0, **h)
46+
# ^^^^^^^^^^^^ reference scip-ruby gem TODO TODO Object#keyword_args().
47+
# ^ reference local 1~#571973038
48+
keyword_args(w: 0, x: 1, y: [2], **h)
49+
# ^^^^^^^^^^^^ reference scip-ruby gem TODO TODO Object#keyword_args().
50+
# ^ reference local 1~#571973038
51+
return
52+
end

0 commit comments

Comments
 (0)