Skip to content

Commit 41ed5e5

Browse files
authored
Merge pull request #551 from nobodywasishere/nobody/casts-are-used
2 parents bf25d80 + f50ff91 commit 41ed5e5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

spec/ameba/rule/lint/unused_literal_spec.cr

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ module Ameba::Rule::Lint
7272
CRYSTAL
7373
end
7474

75+
it "passes if a literal value is the object of a cast" do
76+
expect_no_issues subject, <<-CRYSTAL
77+
1.as(Int64)
78+
"2".as?(String)
79+
CRYSTAL
80+
end
81+
7582
it "fails if literals are top-level" do
7683
expect_issue subject, <<-CRYSTAL
7784
1234

src/ameba/ast/visitors/implicit_return_visitor.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module Ameba::AST
2525
if exp.is_a?(Crystal::ControlExpression)
2626
incr_stack { exp.accept(self) }
2727
break
28-
elsif idx == last_idx && old_stack > 0
28+
elsif idx == last_idx && old_stack.positive?
2929
incr_stack { exp.accept(self) }
3030
else
3131
exp.accept(self)
@@ -162,7 +162,7 @@ module Ameba::AST
162162
def visit(node : Crystal::Cast | Crystal::NilableCast) : Bool
163163
@rule.test(@source, node, @stack.positive?)
164164

165-
node.obj.accept(self)
165+
incr_stack { node.obj.accept(self) }
166166

167167
false
168168
end

0 commit comments

Comments
 (0)