diff --git a/spec/ameba/rule/lint/unused_literal_spec.cr b/spec/ameba/rule/lint/unused_literal_spec.cr index 5fc58aa39..65c4a5594 100644 --- a/spec/ameba/rule/lint/unused_literal_spec.cr +++ b/spec/ameba/rule/lint/unused_literal_spec.cr @@ -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 diff --git a/src/ameba/ast/visitors/implicit_return_visitor.cr b/src/ameba/ast/visitors/implicit_return_visitor.cr index a3deb745e..f21b84caf 100644 --- a/src/ameba/ast/visitors/implicit_return_visitor.cr +++ b/src/ameba/ast/visitors/implicit_return_visitor.cr @@ -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) @@ -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