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
9 changes: 9 additions & 0 deletions ast/Trees.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1343,11 +1343,20 @@ core::NameRef Literal::asString() const {

core::NameRef Literal::asSymbol() const {
ENFORCE(isSymbol());
return asName();
}

core::NameRef Literal::asName() const {
ENFORCE(isName());
auto t = core::cast_type_nonnull<core::NamedLiteralType>(value);
core::NameRef res = t.asName();
return res;
}

bool Literal::isName() const {
return isString() || isSymbol();
}

bool Literal::isSymbol() const {
return core::isa_type<core::NamedLiteralType>(value) &&
core::cast_type_nonnull<core::NamedLiteralType>(value).literalKind ==
Expand Down
2 changes: 2 additions & 0 deletions ast/Trees.h
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,8 @@ EXPRESSION(Literal) {

std::string toStringWithTabs(const core::GlobalState &gs, int tabs = 0) const;
std::string showRaw(const core::GlobalState &gs, int tabs = 0) const;
bool isName() const;
core::NameRef asName() const;
std::string nodeName() const;
bool isString() const;
bool isSymbol() const;
Expand Down
162 changes: 101 additions & 61 deletions rewriter/Minitest.cc

Large diffs are not rendered by default.

File renamed without changes.
20 changes: 20 additions & 0 deletions test/scip/testdata/minitest_2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# typed: true

class Test
extend T::Sig
def self.test_each(arg, &blk); end
def self.it(name, &blk); end
def self.describe(name, &blk); end
end

class Foo < Test
# The unclosed `do` block here should be a recoverable parse error.
test_each([[1, 2], [3,4]]) do |(a,b)|
# ^^ error: Hint: this "do" token

it "it block 1" do
end

it "it block 2" do
end
end # error: unexpected token "end of file"
30 changes: 30 additions & 0 deletions test/scip/testdata/minitest_2.snapshot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# typed: true

class Test
# ^^^^ definition [..] Test#
extend T::Sig
# ^^^^^^ reference [..] Kernel#extend().
def self.test_each(arg, &blk); end
# ^^^^^^^^^ definition [..] `<Class:Test>`#test_each().
def self.it(name, &blk); end
# ^^ definition [..] `<Class:Test>`#it().
def self.describe(name, &blk); end
# ^^^^^^^^ definition [..] `<Class:Test>`#describe().
end

class Foo < Test
# ^^^ definition [..] Foo#
# ^^^^ reference [..] Test#
# The unclosed `do` block here should be a recoverable parse error.
test_each([[1, 2], [3,4]]) do |(a,b)|
# ^^^^^^^^^ reference [..] `<Class:Test>`#test_each().
# ^^ error: Hint: this "do" token

it "it block 1" do
# ^^^^^^^^^^^^ definition [..] Foo#`<it 'it block 1'>`().
end

it "it block 2" do
# ^^^^^^^^^^^^ definition [..] Foo#`<it 'it block 2'>`().
end
end # error: unexpected token "end of file"
24 changes: 24 additions & 0 deletions test/scip/testdata/minitest_3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# typed: true
extend T::Sig

class Test
extend T::Sig

def self.test_each(iter, &blk); end
def self.it(name, &blk); end
def self.describe(name, &blk); end

test_each([[1,2], [3,4]]) do |(a,b)|

describe "d" do
it "b" do
T.reveal_type(a) # error: Revealed type: `Integer`
end
end

it "a" do
T.reveal_type(a) # error: Revealed type: `Integer`
end

end
end
45 changes: 45 additions & 0 deletions test/scip/testdata/minitest_3.snapshot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# typed: true
extend T::Sig
#^^^^^^ reference [..] Kernel#extend().
# ^ reference [..] T#
# ^^^ reference [..] T#Sig#

class Test
# ^^^^ definition [..] Test#
extend T::Sig
# ^^^^^^ reference [..] Kernel#extend().

def self.test_each(iter, &blk); end
# ^^^^^^^^^ definition [..] `<Class:Test>`#test_each().
def self.it(name, &blk); end
# ^^ definition [..] `<Class:Test>`#it().
def self.describe(name, &blk); end
# ^^^^^^^^ definition [..] `<Class:Test>`#describe().

test_each([[1,2], [3,4]]) do |(a,b)|
# ^^^^^^^^^ reference [..] `<Class:Test>`#test_each().
# ^ definition local 1~#2288740619
# ^ definition local 1~#416088458
# ^ definition local 2~#2288740619
# ^ definition local 2~#416088458

describe "d" do
it "b" do
# ^^^ definition [..] Test#`<it 'b'>`().
T.reveal_type(a) # error: Revealed type: `Integer`
# ^ reference [..] T#
# ^^^^^^^^^^^ reference [..] `<Class:T>`#reveal_type().
# ^ reference local 1~#416088458
end
end

it "a" do
# ^^^ definition [..] Test#`<it 'a'>`().
T.reveal_type(a) # error: Revealed type: `Integer`
# ^ reference [..] T#
# ^^^^^^^^^^^ reference [..] `<Class:T>`#reveal_type().
# ^ reference local 1~#2288740619
end

end
end
Loading