Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark object of Cast and NilableCast as used by the AST::ImplicitReturnVisitor #551

Merged
merged 2 commits into from
Feb 5, 2025
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
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