Bug 36737 - default values for optional parameters are not processed
Summary: default values for optional parameters are not processed
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version: 3.5.0 Beta3
Hardware: x86 (IA32) Windows (All)
: medium normal
Assignee: Not Assigned
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-01 04:18 UTC by jan.benda
Modified: 2014-07-25 14:01 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
Function to demonstrate problem (13.24 KB, application/vnd.oasis.opendocument.spreadsheet)
2014-07-25 14:01 UTC, Bob
Details

Description jan.benda 2011-05-01 04:18:38 UTC
Example code /how to reproduce/
REM  *****  BASIC  *****
Option VBASupport 1
Option Explicit

Sub Main()

MsgBox func1   //output empty box
MsgBox func1("Par1_SetValue") --output box with Par1_SetValue

End Sub


Function func1(Optional MyPar1 As String = "Par1_DefaultValue") as String
func1 = MyPar1
End Function
Comment 1 Björn Michaelsen 2011-12-23 12:05:28 UTC
[This is an automated message.]
This bug was filed before the changes to Bugzilla on 2011-10-16. Thus it
started right out as NEW without ever being explicitly confirmed. The bug is
changed to state NEEDINFO for this reason. To move this bug from NEEDINFO back
to NEW please check if the bug still persists with the 3.5.0 beta1 or beta2 prereleases.
Details on how to test the 3.5.0 beta1 can be found at:
http://wiki.documentfoundation.org/QA/BugHunting_Session_3.5.0.-1

more detail on this bulk operation: http://nabble.documentfoundation.org/RFC-Operation-Spamzilla-tp3607474p3607474.html
Comment 2 August Sodora 2012-01-08 16:29:24 UTC
Reproduced on master with the following code:

REM  *****  BASIC  *****
Option VBASupport 1
Option Explicit

Sub Main()

MsgBox(func1())
MsgBox func1("Par1_SetValue")

End Sub

Function func1(Optional MyPar1 As String = "Par1_DefaultValue") as String
func1 = MyPar1
End Function

----------

Result: An empty message box pops up followed by a message box that says "Par1_SetValue"

Expected Result: A message box that says "Par1_DefaultValue" followed by a message box that says "Par1_SetValue"

It looks to me like this is in some vba-specific part of the code because I get syntax errors if I remove the Option VBASupport 1.
Comment 3 QA Administrators 2014-06-25 17:38:03 UTC
Please read this message in its entirety before responding.

Your bug was confirmed at least 1 year ago and has not had any activity on it for over a year. Your bug is still set to NEW which means that it is open and confirmed. It would be nice to have the bug confirmed on a newer version than the version reported in the original report to know that the bug is still present -- sometimes a bug is inadvertently fixed over time and just never closed.

If you have time please do the following:
1) Test to see if the bug is still present on a currently supported version of LibreOffice (preferably 4.2 or newer).
2) If it is present please leave a comment telling us what version of LibreOffice and your operating system.
3) If it is NOT present please set the bug to RESOLVED-WORKSFORME and leave a short comment telling us your version and Operating System

Please DO NOT
1) Update the version field
2) Reply via email (please reply directly on the bug tracker)
3) Set the bug to RESOLVED - FIXED (this status has a particular meaning that is not appropriate in this case)

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 
LibreOffice is powered by a team of volunteers, every bug is confirmed (triaged) by human beings who mostly give their time for free. We invite you to join our triaging by checking out this link:
https://wiki.documentfoundation.org/QA/BugTriage

There are also other ways to get involved including with marketing, UX, documentation, and of course developing -  http://www.libreoffice.org/get-help/mailing-lists/. 

Lastly, good bug reports help tremendously in making the process go smoother, please always provide reproducible steps (even if it seems easy) and attach any and all relevant material
Comment 4 Bob 2014-07-25 14:00:41 UTC
I was about to open a very similar bug report and can provide a simple test case to demonstrate the problem still occurs of LO 4.3.0.3

VBA allows an optional parameter to be defined as - optional str as string = "abc" - the variable is not initialized to "abc" in LO

Alternatively if no default is provided - optional mstr as string mstr  - should not be initialized and isMissing(mstr) should return True it actually returns false and mstr is a null string

LO works correctly for data type Double and Variant,  I have not tested other data types

This error is particularly insidious when porting from Excel since no error is raised and differences in function execution may not be readily apparent.

I used the following function to show the problem:

function TestOpt(optional num as double =123,  optional str as string = "abc", optional numv  =456,  optional strv = "def", optional miss as double, optional mstr as string) as string 
Dim printstr as string 

printstr =              "num: >>" &num &"<<  isMissing " & isMissing(num) 
printstr = printstr & "; str: >>" &str &"<<  isMissing " & isMissing(str) 

printstr = printstr & "; numv: >>" &numv &"<<  isMissing " & isMissing(numv) 
printstr = printstr & "; strv: >>" &strv &"<<  isMissing " & isMissing(strv)
rem print printstr
printstr = printstr & "; miss: >>" &miss &"<<  isMissing " & isMissing(miss)
printstr = printstr & "; mstr: >>" &mstr &"<<  isMissing " & isMissing(mstr)
print printstr
TestOpt = printstr
end function 

Output is 
num: >>123<<  isMissing False; str: >><<  isMissing False; numv: >>456<<  isMissing False; strv: >>def<<  isMissing False; miss: >>Error ǀ<<  isMissing True; mstr: >><<  isMissing False

str and mstr are handled incorrectly, Double and Variant formats are correct
Comment 5 Bob 2014-07-25 14:01:33 UTC
Created attachment 103446 [details]
Function to demonstrate problem


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.