From e8558680248c58194b21d40485849d72c7a6c86f Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Wed, 17 Aug 2022 17:46:57 +0800 Subject: [PATCH 1/2] test: Add test with wrong output for rescue bindings. --- test/scip/testdata/rescue.rb | 12 ++++++++++++ test/scip/testdata/rescue.snapshot.rb | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 test/scip/testdata/rescue.rb create mode 100644 test/scip/testdata/rescue.snapshot.rb diff --git a/test/scip/testdata/rescue.rb b/test/scip/testdata/rescue.rb new file mode 100644 index 000000000..853480660 --- /dev/null +++ b/test/scip/testdata/rescue.rb @@ -0,0 +1,12 @@ +# typed: true + +def f + begin + raise 'This exception will be rescued!' + rescue StandardError => e + puts "Rescued: #{e.inspect}" + rescue AnotherError => e + puts "Rescued, but with a different block: #{e.inspect}" + end + f +end diff --git a/test/scip/testdata/rescue.snapshot.rb b/test/scip/testdata/rescue.snapshot.rb new file mode 100644 index 000000000..08c829ce8 --- /dev/null +++ b/test/scip/testdata/rescue.snapshot.rb @@ -0,0 +1,24 @@ + # typed: true + + def f +#^^^^^ definition [..] Object#f(). + begin + raise 'This exception will be rescued!' + rescue StandardError => e +# ^^^^ definition local 2~#3809224601 +# ^^^^^^^^^^^^^ reference local 1~#3809224601 +# ^^^^^^^^^^^^^ reference [..] StandardError# +# ^ definition local 1~#3809224601 + puts "Rescued: #{e.inspect}" +# ^ reference local 1~#3809224601 + rescue AnotherError => e +# ^^^^^^ definition local 3~#3809224601 +# ^^^^^^^^^^^^ reference local 1~#3809224601 +# ^^^^^^^^^^^^ reference [..] T.untyped# +# ^ reference (write) local 1~#3809224601 + puts "Rescued, but with a different block: #{e.inspect}" +# ^ reference local 1~#3809224601 + end + f +# ^ reference [..] Object#f(). + end From c45dfcbb37c89afc8b894208fe28ede84fc0a413 Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Mon, 22 Aug 2022 10:15:24 +0800 Subject: [PATCH 2/2] fix: Emit reference for rescued bindings. --- scip_indexer/SCIPIndexer.cc | 1 + test/scip/testdata/rescue.rb | 16 +++++++---- test/scip/testdata/rescue.snapshot.rb | 40 +++++++++++++++++---------- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/scip_indexer/SCIPIndexer.cc b/scip_indexer/SCIPIndexer.cc index c64ecefbf..1f5250cf9 100644 --- a/scip_indexer/SCIPIndexer.cc +++ b/scip_indexer/SCIPIndexer.cc @@ -111,6 +111,7 @@ static bool isTemporary(const core::GlobalState &gs, const core::LocalVariable & auto n = var._name; return n == Names::blockPreCallTemp() || n == Names::blockTemp() || n == Names::blockPassTemp() || n == Names::blkArg() || n == Names::blockCall() || n == Names::blockBreakAssign() || n == Names::forTemp() || + n == Names::keepForCfgTemp() || // Insert checks because sometimes temporaries are initialized with a 0 unique value. 😬 n == Names::finalReturn() || n == NameRef::noName() || n == Names::blockCall() || n == Names::selfLocal() || n == Names::unconditional(); diff --git a/test/scip/testdata/rescue.rb b/test/scip/testdata/rescue.rb index 853480660..8784d41d0 100644 --- a/test/scip/testdata/rescue.rb +++ b/test/scip/testdata/rescue.rb @@ -1,12 +1,18 @@ # typed: true +class MyError < StandardError +end + +def handle(e) + puts e.inspect.to_s +end + def f begin raise 'This exception will be rescued!' - rescue StandardError => e - puts "Rescued: #{e.inspect}" - rescue AnotherError => e - puts "Rescued, but with a different block: #{e.inspect}" + rescue MyError => e1 + handle(e1) + rescue StandardError => e2 + handle(e2) end - f end diff --git a/test/scip/testdata/rescue.snapshot.rb b/test/scip/testdata/rescue.snapshot.rb index 08c829ce8..7e7a7cba5 100644 --- a/test/scip/testdata/rescue.snapshot.rb +++ b/test/scip/testdata/rescue.snapshot.rb @@ -1,24 +1,34 @@ # typed: true + class MyError < StandardError +# ^^^^^^^ definition [..] MyError# +# ^^^^^^^^^^^^^ definition [..] StandardError# + end + + def handle(e) +#^^^^^^^^^^^^^ definition [..] Object#handle(). +# ^ definition local 1~#780127187 + puts e.inspect.to_s +# ^ reference local 1~#780127187 + end + def f #^^^^^ definition [..] Object#f(). begin raise 'This exception will be rescued!' - rescue StandardError => e -# ^^^^ definition local 2~#3809224601 -# ^^^^^^^^^^^^^ reference local 1~#3809224601 + rescue MyError => e1 +# ^^^^^^^ reference local 1~#3809224601 +# ^^^^^^^ reference [..] MyError# +# ^^ definition local 1~#3809224601 + handle(e1) +# ^^^^^^ reference [..] Object#handle(). +# ^^ reference local 1~#3809224601 + rescue StandardError => e2 +# ^^^^^^^^^^^^^ reference local 2~#3809224601 # ^^^^^^^^^^^^^ reference [..] StandardError# -# ^ definition local 1~#3809224601 - puts "Rescued: #{e.inspect}" -# ^ reference local 1~#3809224601 - rescue AnotherError => e -# ^^^^^^ definition local 3~#3809224601 -# ^^^^^^^^^^^^ reference local 1~#3809224601 -# ^^^^^^^^^^^^ reference [..] T.untyped# -# ^ reference (write) local 1~#3809224601 - puts "Rescued, but with a different block: #{e.inspect}" -# ^ reference local 1~#3809224601 +# ^^ definition local 2~#3809224601 + handle(e2) +# ^^^^^^ reference [..] Object#handle(). +# ^^ reference local 2~#3809224601 end - f -# ^ reference [..] Object#f(). end