You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use FINAL for immutable variables creates syntax error in case of method call #96
classlcl_test definition create private.
public section.
types: begin oftest,
id type sysuuid_x16,
name type string,
end oftest.
methods show_data.
endclass.
classlcl_test implementation.
methodshow_data.
try.
data(test_data) =value test( id= cl_system_uuid=>create_uuid_x16_static( )
name='Test' ).
cl_demo_output=>display( test_data ).
catch cx_uuid_error.
raiseexceptionnew cx_sovy_fsi_event_dispatcher( ).
endtry.
endmethod.
endclass.
When I run the ABAP Cleaner with the rule Use FINAL for immutable variables I will get a syntax error and the declaration type of the variable test_data will change from DATA to FINAL.
Manual solution is to either extract the creation of the id upfront:
It would be great if you could add another check to either extract the result of inline calls into own variables or don't change the declaration type in that case.
Seriously? The weird edge cases of the chosen expression implementation strike again :(
A variable inside the expression also works by the way:
final(test_data) =value test( LET i= cl_system_uuid=>create_uuid_x16_static( ) INid= iname='Test' ).
In my opinion this should be fixed or at least documented somewhere. Having to account for this in abap-cleaner seems unreasonable, especially when it's not obvious what works and what does not.
that's an amazing finding indeed! And you can find more surprising examples, e.g.
I shall ask colleagues from the ABAP compiler team about this. However, even if the compiler learns to deal with those cases at some point in the future, I think for the time being it would be best to prevent introducing FINAL whenever any method calls are found inside of constructor expressions on the right-hand side.
thanks again for reporting this! The workaround is now in place with version 1.5.3, which was just released. Closing this issue for now, but if there are news from the ABAP compiler team on this, we could see if the workaround can be modified accordingly or even removed at some point.
Activity
fabianlupa commentedon Aug 26, 2023
Seriously? The weird edge cases of the chosen expression implementation strike again :(
A variable inside the expression also works by the way:
In my opinion this should be fixed or at least documented somewhere. Having to account for this in abap-cleaner seems unreasonable, especially when it's not obvious what works and what does not.
jmgrassau commentedon Sep 2, 2023
Hi Christian,
that's an amazing finding indeed! And you can find more surprising examples, e.g.
I shall ask colleagues from the ABAP compiler team about this. However, even if the compiler learns to deal with those cases at some point in the future, I think for the time being it would be best to prevent introducing
FINALwhenever any method calls are found inside of constructor expressions on the right-hand side.Kind regards,
Jörg-Michael
jmgrassau commentedon Sep 2, 2023
Hi Christian and Fabian,
with the next release, the workaround would be as mentioned: Whenever a method call is found inside of a constructor expression,
DATAis kept:Hope this solves the issue, even if it does a bit too much; please let me know if you find cases which still cause a syntax error!
Kind regards,
Jörg-Michael
suynwa commentedon Sep 4, 2023
Hi Jörg-Michael, done that already 👍🏼
fix FinalVariableRule for method calls inside constructors exp.s (SAP#96
fix FinalVariableRule for method calls inside constructors exp.s (#96)
jmgrassau commentedon Sep 4, 2023
Hi Christian, Fabian and Suhas,
thanks again for reporting this! The workaround is now in place with version 1.5.3, which was just released. Closing this issue for now, but if there are news from the ABAP compiler team on this, we could see if the workaround can be modified accordingly or even removed at some point.
Kind regards,
Jörg-Michael
cgrail commentedon Sep 5, 2023
Cool. Thanks a lot.