Skip to content

variable is assigned but never used not working correctly #331

Closed

Description

@Ennowulff

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.

Activity

  1. self-assigned this
    on Jun 26, 2024
  2. jmgrassau commented on Jun 26, 2024

    @jmgrassau
    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

  3. Ennowulff commented on Jun 26, 2024

    @Ennowulff
    Author

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

  4. jmgrassau commented on Jul 8, 2024

    @jmgrassau
    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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions