sonar-delphi icon indicating copy to clipboard operation
sonar-delphi copied to clipboard

Inconsitent unused const when using const inline

Open Valdeirsk8 opened this issue 1 year ago • 4 comments

Prerequisites

  • [X] This bug is in SonarDelphi, not SonarQube or my Delphi code.
  • [X] This bug has not already been reported.

SonarDelphi version

1.8.0

SonarQube version

v10.5.1

Issue description

Plugin is raising an erroneous issue when using const inline.

Captura de tela 2024-08-08 163803

Steps to reproduce

const lValue: integer = 0; //<-- unused const SomeMethod(lValue); //

Minimal Delphi code exhibiting the issue

  const ldmServiceOrdemPagamento = TdmServiceOrdemPagamento.Create();
  try
    try
      const lID = pRequest.Params.Field('id').AsString; //sonar plugin is raising an issue here saying unused const
      if ldmServiceOrdemPagamento.Cancelar(lID) then
      begin
        pResponse.Status(THTTPStatus.Accepted);
      end else
      begin
        raise EHorseException.New.Error('Não foi possivel cancelar a ordem de serviço.').Status(THTTPStatus.NotAcceptable);
      end;

    except
      on E: EErrorBadRequest do
      begin
        Log.Error(E);
        raise EHorseException.New.Error(E.Message).Title('Error').status(THTTPStatus.BadRequest);
      end;
      on E: Exception do
      begin
        Log.Error(E);
        raise;
      end;
    end;
  finally
    ldmServiceOrdemPagamento.Free();
  end;

Valdeirsk8 avatar Aug 08 '24 20:08 Valdeirsk8