Skip to content

Commit

Permalink
Merge pull request #551 from nobodywasishere/nobody/casts-are-used
Browse files Browse the repository at this point in the history
  • Loading branch information
Sija authored Feb 5, 2025
2 parents bf25d80 + f50ff91 commit 41ed5e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions spec/ameba/rule/lint/unused_literal_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ module Ameba::Rule::Lint
CRYSTAL
end

it "passes if a literal value is the object of a cast" do
expect_no_issues subject, <<-CRYSTAL
1.as(Int64)
"2".as?(String)
CRYSTAL
end

it "fails if literals are top-level" do
expect_issue subject, <<-CRYSTAL
1234
Expand Down
4 changes: 2 additions & 2 deletions src/ameba/ast/visitors/implicit_return_visitor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Ameba::AST
if exp.is_a?(Crystal::ControlExpression)
incr_stack { exp.accept(self) }
break
elsif idx == last_idx && old_stack > 0
elsif idx == last_idx && old_stack.positive?
incr_stack { exp.accept(self) }
else
exp.accept(self)
Expand Down Expand Up @@ -162,7 +162,7 @@ module Ameba::AST
def visit(node : Crystal::Cast | Crystal::NilableCast) : Bool
@rule.test(@source, node, @stack.positive?)

node.obj.accept(self)
incr_stack { node.obj.accept(self) }

false
end
Expand Down

0 comments on commit 41ed5e5

Please sign in to comment.