Bug 146112 - IsNull must return False when testing object variables (including non-initialized/assigned to Nothing) in VBASupport 1 mode
Summary: IsNull must return False when testing object variables (including non-initial...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: difficultyBeginner, easyHack, skillCpp
Depends on:
Blocks: Macro-VBA
  Show dependency treegraph
 
Reported: 2021-12-08 06:42 UTC by Mike Kaganski
Modified: 2022-05-02 14:53 UTC (History)
7 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-12-08 06:42:10 UTC
SbRtl_IsNull [1] is explicitly designed to return True when passed an empty object value. (This is since the initial import commit, so was always the same.)

  Dim o As Object
  MsgBox IsNull(o) ' shows "True"

However, this is inconsistent with VBA, where the same code gives False.
So the function must consider VBASupport, and exclude the object variable test when VBA support is enabled.

[1] https://opengrok.libreoffice.org/xref/core/basic/source/runtime/methods.cxx?r=fffc6b40&mo=70055&fi=2482#2482
Comment 1 Rafael Lima 2022-01-05 22:51:05 UTC
I can confirm the bug. I tested the following code in LibO Basic:

Sub TestIsnull
    Dim a As Object
    MsgBox IsNull(a)
    Set a = Nothing
    MsgBox IsNull(a)
    a = Array(1, 2, 3)
    MsgBox IsNull(a)
End Sub

It returns True, True and False regardless of VBA support being enabled or not.

However in Excel VBA, the code below returns False in all MsgBox statements.

Sub TestIsnull
    Dim a As Object
    MsgBox IsNull(a)
    Set a = Nothing
    MsgBox IsNull(a)
    Set a = Range("A1")
    MsgBox IsNull(a)
End Sub
Comment 2 Rafael Lima 2022-01-06 14:21:26 UTC
Proposed patch available for review at:
https://gerrit.libreoffice.org/c/core/+/128050
Comment 3 Xisco Faulí 2022-05-02 14:53:22 UTC
(In reply to Rafael Lima from comment #2)
> Proposed patch available for review at:
> https://gerrit.libreoffice.org/c/core/+/128050

The patch is abandoned. Resetting assignee.
@Andreas, I thought you might be interested in this issue