https://bugs.documentfoundation.org/show_bug.cgi?id=173904

            Bug ID: 173904
           Summary: Calc: Named expression, capitalization does not take
                    recursive defintions into account
           Product: LibreOffice
           Version: unspecified
          Hardware: All
                OS: All
            Status: UNCONFIRMED
          Severity: normal
          Priority: medium
         Component: Calc
          Assignee: [email protected]
          Reporter: [email protected]

Description:
If a Named Expression is defined in Calc, it appears that the capitalization of
function names is determined by whether the function is already existing or
not. E.g., if "sqrt" is used in the definition, it is automatically recognized
as SQRT, while if "MY_FUNC" is entered, it becomes lowercase "my_func" unless
"MY_FUNC" (with this capitalization) is already defined.

Changing capitalization of recognized functions is a good thing, not forcing
the user to write built-in Calc functions in uppercase.

The advantage of changing unrecognized function names to lowercase is less
obvious (perhaps to signal that this is not a built-in function?), although
harmless in most cases. However, in the upcoming LO 27.2, the possibility of
defining LAMBDA functions allows for recursive definitions, see example of the
recursive function MY_FACTORIAL in the help pages:
https://help.libreoffice.org/27.2/en-US/text/scalc/01/func_lambda.html

In this case, "MY_FACTORIAL" is not already defined, and it is stored as
"my_factorial". Afterwards, since the defined name was uppercase MY_FACTORIAL,
the function fails with a #NAME? error.

Steps to Reproduce:
1. Open Calc in LO 27.2 (Master version)
2. Sheet > Named Ranges and Expressions > Define
3. Name: MY_FACTORIAL
4. Range or Formula expression: =LAMBDA(n;IF(n>1;n*MY_FACTORIAL(n-1);1))
5. Close with "Add".
6. Check entrance with Sheet > Named Ranges and Expressions > Manage
7. Write in any cell, e.g. B1: =MY_FACTORIAL(5) 

Actual Results:
In step 6: The stored entrance is "LAMBDA(n;IF(n>1;n*my_factorial(n-1);1))",
i.e., function name has changed capitalization
In step 7: #NAME? error

Expected Results:
In Step 6: The stored entrance should have unchanged capitalizatio of
MY_FACTORIAL: "LAMBDA(n;IF(n>1;n*MY_FACTORIAL(n-1);1))"
The system should either not change capitalization of unrecognized names, or
involve the ongoing definition (Name) when checking for recognized names.
In step 7: No name error in using the function.


Reproducible: Always


User Profile Reset: No

Additional Info:
A work-around for this bug is to use Sheet > Named Ranges and Expressions >
Manage > Manage to manually change the capitalization. This will stick (since
the name MY_FACTORIAL is at this point a defined name).

Presently, there will be a different error, Err 514 (Internal overflow).
However, this appears to be a separate bug and will therefore be reported
separately.

The following Master version was used:

Version: 27.2.0.0.alpha0+ (X86_64)
Build ID: 70e6dd0eb1874f0c5e260948b2c8b9e192841372
CPU threads: 8; OS: Windows 11 X86_64 (build 26300); UI render: Skia/Raster;
VCL: win
Locale: da-DK (da_DK); UI: en-US
Calc: threaded

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to