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

variable is assigned but never used not working correctly #331

Closed
Ennowulff opened this issue Jun 25, 2024 · 3 comments
Closed

variable is assigned but never used not working correctly #331

Ennowulff opened this issue Jun 25, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@Ennowulff
Copy link

Hey there!

please see the following code

CLASS zcl_demo_01 DEFINITION
  PUBLIC FINAL
  CREATE PUBLIC.

  PUBLIC SECTION.
    METHODS replace_text_in
      IMPORTING
        mailtext        TYPE string
        with            TYPE clike
        if              TYPE clike
        text            TYPE clike OPTIONAL
      RETURNING
        VALUE(r_result) TYPE string.

  PRIVATE SECTION.
    TYPES: BEGIN OF _changed_parts,
             one   TYPE abap_bool,
             two   TYPE abap_bool,
             three TYPE abap_bool,
           END OF _changed_parts.

    DATA changed_parts TYPE _changed_parts.
ENDCLASS.


CLASS zcl_demo_01 IMPLEMENTATION.
  METHOD replace_text_in.
    ASSIGN COMPONENT if OF STRUCTURE changed_parts TO FIELD-SYMBOL(<field>).
    IF sy-subrc > 0.
      RETURN.
    ENDIF.

    " TODO: variable is assigned but never used (ABAP cleaner)
    DATA(findstr) = |${ if }%|.
    r_result = mailtext.
    DATA(replacestr) = |<p>{ with }{ COND #( WHEN text IS SUPPLIED THEN |: <b>{ text }</b>| ELSE `` ) }</p>|.
    IF <field> IS NOT INITIAL.
      REPLACE findstr WITH replacestr INTO r_result.
    ELSE.
      REPLACE findstr WITH `` INTO r_result.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

ABAP cleaner thinks that the variable findstr is not used, but it is by REPLACE.

@jmgrassau jmgrassau added the bug Something isn't working label Jun 26, 2024
@jmgrassau jmgrassau self-assigned this Jun 26, 2024
@jmgrassau
Copy link
Member

Hi Enno,

thanks for reporting this bug! If you activate the menu "Highlight / Write Positions", you can see that this happened because ABAP cleaner misinterpreted the obsolete syntax of REPLACE substring WITH new INTO dobj:

image

The write position really is ev_result, and after fixing that, the issue will not come up anymore in the next release:

image

Kind regards,
Jörg-Michael

@Ennowulff
Copy link
Author

Thanks for fast fixing of this glitch, @jmgrassau ! ❤️

@jmgrassau
Copy link
Member

Hi Enno,

thanks again for reporting this bug – this should now be fixed with version 1.18.0, which was just released!

Kind regards,
Jörg-Michael

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants