Bug 143706 - Missing Optional argument is not properly missing, when ':=' syntax is used
Summary: Missing Optional argument is not properly missing, when ':=' syntax is used
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
4.0.0.3 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Macro-StarBasic
  Show dependency treegraph
 
Reported: 2021-08-03 14:55 UTC by Mike Kaganski
Modified: 2024-06-27 13:53 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Kaganski 2021-08-03 14:55:11 UTC
Consider this BASIC code:

  ' No Option VBASupport

  Sub Foo(Optional x As Double, Optional y As Double)
    MsgBox ismissing(x) & " " & ismissing(y)
  End Sub

  Sub Bar
    Foo(y:=10)
  End Sub

It produces "False False", instead of expected "True False"; and inspecting value of x inside Foo gives 0.

In non-VBASupport mode, we should not initialize missing optional arguments; the problem looks specific to the := argument value syntax, and e.g.

  Foo(, 10)

produces expected "True False".

Tested with Version: 7.2.0.2 (x64) / LibreOffice Community
Build ID: 614be4f5c67816389257027dc5e56c801a547089
CPU threads: 12; OS: Windows 10.0 Build 19043; UI render: Skia/Raster; VCL: win
Locale: ru-RU (ru_RU); UI: en-US
Calc: threaded
Comment 1 Vladimir Sokolinskiy 2021-08-03 16:35:11 UTC
Reproduced.

Version: 7.1.4.2 / LibreOffice Community
Build ID: 10(Build:2)
CPU threads: 4; OS: Linux 5.4; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Ubuntu package version: 1:7.1.4~rc2-0ubuntu0.20.04.1~lo1
Calc: threaded
Comment 2 Andreas Heinisch 2021-09-13 17:29:43 UTC
Already in Version 4.0.0.1 (Build ID: 527dba6f6e0cfbbc71bd6e7b88a52699bb48799)

Not so easy to solve on my side.

  Sub Foo(Optional x As Double, Optional y As Double)
    MsgBox ismissing(x) & " " & ismissing(y)
  End Sub

The parser initializes the variable x as double and sets it as optional.

  Sub Bar
    Foo(y:=10)
  End Sub

Here it initializes the variable y to integer with a the value 10.

However, it does not generate a StepEMPTY for StepPARAM since there is no COMMA token for the function Foo. Maybe there could be some logic scanning the parameter list for function Foo and the actual call of the function in [1]. Then, there could be an additional StepEMPTY for the parameter x in this case. Maybe there is another approach, but currently, I could not find any satisfying solution for me.

[1] https://opengrok.libreoffice.org/xref/core/basic/source/comp/exprtree.cxx?r=a5c1a645#955