Bug 133811 - The program does not continue with 'Dim' or 'ReDim' following 'If' in one line statement.
Summary: The program does not continue with 'Dim' or 'ReDim' following 'If' in one lin...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
6.2.8.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Macro-StarBasic
  Show dependency treegraph
 
Reported: 2020-06-09 07:32 UTC by Nukool Chompuparn
Modified: 2023-11-08 03:15 UTC (History)
3 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 Nukool Chompuparn 2020-06-09 07:32:17 UTC
Description:
Using 'If' in one line statement, 'Dim' and 'ReDim' subsequent statements next to 'If' condition are not executed.

Steps to Reproduce:
1. Example code:

Option Explicit

Sub Test_IfIsNotClosed
    If False Then Dim i%
    i = 1
    MsgBox i
End Sub

Sub Test_IfIsClosed
    If False Then
    	Dim j%
    	j = 1
    Else
    	Dim k%
    	k = 2
    End If
    MsgBox k
End Sub	

2. Dim i% is not executed. 


Actual Results:
Dim i% is not executed. 

Expected Results:
Dim or ReDim should be executed.


Reproducible: Always


User Profile Reset: No



Additional Info:
Version: 6.2.8.2
Build ID: f82ddfca21ebc1e222a662a32b25c0c9d20169ee
CPU threads: 4; OS: Linux 5.6; UI render: default; VCL: gtk3; 
Locale: en-US (en_US.UTF-8); UI-Language: en-US
Calc: threaded
Comment 1 Mike Kaganski 2020-06-09 08:38:15 UTC
This is not specific to one-line If. In the code of comment 0, Test_IfIsClosed only tests the k variable that gets Dim'ed in "true" branch; but trying to MsgBox j there instead of MsgBox k also gives the same "Variable not defined." run-time error.

But I am unsure that the "Expected Results" from comment 0 ("Dim or ReDim should be executed") are correct. Dim is not a run-time operator - it is compile-time instruction. It should, naturally, be effective regardless of conditions; but in fact, the line

> If False Then Dim i%

should be syntax error (since it's equal to this *incomplete* run-time instruction: "If False Then"). It *is* syntax error in, say, VBA (tested in Excel 2016).

Alternatively, it should be tolerated in non-VBA mode (to keep backward compatibility with strange StarBasic code using it?), and then the "Expected Results" is OK (but should be made syntax error in "Option VBASupport 1" mode).
Comment 2 Jim Kornelsen 2020-06-09 20:10:32 UTC
The following line (if there is one) also gets skipped, but only when the condition is false.

Sub SayHi
    If False Then ReDim a
    MsgBox "hello"
    MsgBox "there"
End Sub

Result: Displays only "there"

Treating this as a syntax error would solve the problem.
Comment 3 QA Administrators 2023-11-08 03:15:25 UTC
Dear Nukool Chompuparn,

To make sure we're focusing on the bugs that affect our users today, LibreOffice QA is asking bug reporters and confirmers to retest open, confirmed bugs which have not been touched for over a year.

There have been thousands of bug fixes and commits since anyone checked on this bug report. During that time, it's possible that the bug has been fixed, or the details of the problem have changed. We'd really appreciate your help in getting confirmation that the bug is still present.

If you have time, please do the following:

Test to see if the bug is still present with the latest version of LibreOffice from https://www.libreoffice.org/download/

If the bug is present, please leave a comment that includes the information from Help - About LibreOffice.
 
If the bug is NOT present, please set the bug's Status field to RESOLVED-WORKSFORME and leave a comment that includes the information from Help - About LibreOffice.

Please DO NOT

Update the version field
Reply via email (please reply directly on the bug tracker)
Set the bug's Status field to RESOLVED - FIXED (this status has a particular meaning that is not 
appropriate in this case)


If you want to do more to help you can test to see if your issue is a REGRESSION. To do so:
1. Download and install oldest version of LibreOffice (usually 3.3 unless your bug pertains to a feature added after 3.3) from https://downloadarchive.documentfoundation.org/libreoffice/old/

2. Test your bug
3. Leave a comment with your results.
4a. If the bug was present with 3.3 - set version to 'inherited from OOo';
4b. If the bug was not present in 3.3 - add 'regression' to keyword


Feel free to come ask questions or to say hello in our QA chat: https://web.libera.chat/?settings=#libreoffice-qa

Thank you for helping us make LibreOffice even better for everyone!

Warm Regards,
QA Team

MassPing-UntouchedBug