Ruby: incorrect diagnostic about unused local variable

Hi,
On the following input:

class Foo
  def self.foo(att, val = nil, exception: true)
    maybe_rescue =
      ->(proc) {
        if exception
          proc[]
        else
          begin
            proc[]
          rescue => e
            logger.warn "ignored an error: #{e}"
            nil
          end
        end
      }
    if val.is_a?(String)
      case att
      when nil then nil
      when :birth_date, 'birth_date' then val = maybe_rescue[->{Date.parse(val)}]
      when :created_at, 'created_at' then val = maybe_rescue[->{DateTime.parse(val)}]
      end
    end
  end
end

I get a false positive about maybe_rescue: “Remove this unused “maybe_rescue” local variable.”

This is sonar on macOS, downloaded as a zip.

  • sonar-scanner-5.0.1.3006-macosx
  • sonarqube-10.2.1.78527/bin/macosx-universal-64

Sorry if this is not the right place, I’m new to Sonar.
Cheers!

No answers. Is this the proper place to report bugs?

I have more of these. For instance:

The variable is obviously used in the last line of the capture.

Hey @Akim ,

Sorry for making you wait, this is indeed an FP on our analyzer side, and here is the ticket to handle it: SONARSLANG-640.

It’s the correct place to report such issues, it’s just that we don’t work often on the ruby analyzer, and we somehow missed this thread.

Cheers,
Michael