Description: In a BASIC procedure with two optional parameters when you call the procedure with the first parameter omited and the second parameter present then the fist parameter receives a value and the function IsMissing returs false. I attached a test file with this BASIC code: option explicit Sub Main SubOneParameter() SubOneParameter(1) SubTwoParameters() SubTwoParameters(,) SubTwoParameters(,2) SubTwoParameters(1,) SubTwoParameters(1,2) End Sub sub SubOneParameter(optional lPar1 as integer) if ismissing(lPar1) then msgbox("Missing parameter") else msgbox("Not missing parameter, value "+lPar1) endif end sub sub SubTwoParameters(optional lPar1 as integer,optional lPar2 as integer) dim cMsg as string if ismissing(lPar1) then cMsg="Missing first parameter" else cMsg="Not missing first parameter, value "+lPar1 endif cMsg=cMsg+chr(13) if ismissing(lPar2) then cMsg=cMsg+"Missing second parameter" else cMsg=cMsg+"Not missing second parameter, value "+lPar2 endif msgbox(cMsg) end sub Actual Results: In The call SubTwoParameters(,) the first parameter (not present) receives the value 448 ??? and shows message Not missing first parameter, value 448 Missing second parameter In The call SubTwoParameters(,2) the first parameter (not present) receives the value 448 ??? and shows message Not missing first parameter, value 448 Not missing second parameter, value 2 Expected Results: When the first parameter is not present never must reveive a value. Reproducible: Always User Profile Reset: Yes Additional Info:
Created attachment 151253 [details] Test file
confirming. looks like the comma "," is evaluted as parameter ?
Reminder to myself: https://opengrok.libreoffice.org/xref/core/basic/source/comp/exprtree.cxx?r=7ddedd25#966 https://opengrok.libreoffice.org/xref/core/basic/source/runtime/runtime.cxx?r=b9fe4f26#2744
https://opengrok.libreoffice.org/xref/core/basic/source/sbx/sbxint.cxx?r=4fdc90c5#39
or maybe...(not sure) https://opengrok.libreoffice.org/xref/core/basic/source/sbx/sbxint.cxx?r=4fdc90c5#55
seems my patch for tdf#118544 is the culprit. (e.g. Implicitly converting Variant/Error to Integer if the parameter is declared as Integer, and this is no longer of the type SbxError )
my guess might be wrong, I'll see the code more closely just a bit later.
I investigated the error and I think I need some clarifications: - in VB the function IsMissing works only with variant datatypes - in LO IsMissing works or should work even with other datatypes?!? In the majority of the cases it works :). I does not work in the case, where the missing parameter is before any non missing parameters, e.g., SubTwoParameters(,2) Because, if I change the method signature to variant datatypes, everything works as expected: SubTwoParameters(optional lPar1 as variant, optional lPar2 as variant) Any thoughts?
(In reply to Andreas Heinisch from comment #8) > I investigated the error and I think I need some clarifications: > > - in VB the function IsMissing works only with variant datatypes > - in LO IsMissing works or should work even with other datatypes?!? Why are you asking? You have just fixed tdf#36737 ;-) > In the > majority of the cases it works :). I does not work in the case, where the > missing parameter is before any non missing parameters, e.g., > SubTwoParameters(,2) When you fixed the mentioned bug, in SbiRuntime::StepPARAM there was initial part assigning error 448 to missing previous arguments. That looks relevant. There should be a difference somewhere that treats actually missing parameter differently compared to error 448.
(In reply to Mike Kaganski from comment #9) > (In reply to Andreas Heinisch from comment #8) > > I investigated the error and I think I need some clarifications: > > > > - in VB the function IsMissing works only with variant datatypes > > - in LO IsMissing works or should work even with other datatypes?!? > > Why are you asking? You have just fixed tdf#36737 ;-) The more I work with these optionals/missing parameters, the more I get confused hahaha, but I found many RefCards, where it states, that it should work with every datatype, whereas in VB it works only with Variants. > > > In the > > majority of the cases it works :). I does not work in the case, where the > > missing parameter is before any non missing parameters, e.g., > > SubTwoParameters(,2) > > When you fixed the mentioned bug, in SbiRuntime::StepPARAM there was initial > part assigning error 448 to missing previous arguments. That looks relevant. > There should be a difference somewhere that treats actually missing > parameter differently compared to error 448. The thing is that the parameter already has a value in StepPARAM, because it has been converted from Error to Int. In SbiRuntime::StepEMPTY() it gets the error value (https://opengrok.libreoffice.org/xref/core/basic/source/runtime/runtime.cxx?r=8e323fca#2744) and later it will be converted to the specified type, for instance in https://opengrok.libreoffice.org/xref/core/basic/source/sbx/sbxuint.cxx?r=4fdc90c5#53. I will search for a fix ...
https://gerrit.libreoffice.org/c/core/+/90215/1
Andreas Heinisch committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/84b884135ee419fe7abfefa7b4b651a649cf9ad9 tdf#79426, tdf#125180 - Don't convert missing parameters to requested type It will be available in 7.0.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.