Bug 149157 - VBA parsing bug with multiline continuation in comment
Summary: VBA parsing bug with multiline continuation in comment
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
7.3.3.2 release
Hardware: All All
: medium minor
Assignee: Andreas Heinisch
URL:
Whiteboard: target:7.4.0 target:7.3.5
Keywords:
Depends on:
Blocks:
 
Reported: 2022-05-18 17:20 UTC by studog
Modified: 2024-08-27 17:21 UTC (History)
0 users

See Also:
Crash report or crash signature:


Attachments
Copy of the spreadsheet used in the reproduction steps (249.00 KB, application/vnd.ms-excel)
2022-05-18 17:22 UTC, studog
Details

Note You need to log in before you can comment on or make changes to this bug.
Description studog 2022-05-18 17:20:42 UTC
Description:
Opening a specific .xls file throws a "BASIC syntax error. Else/Endif without if." error. This is spurious, if I understand BASIC syntax correctly.



Steps to Reproduce:
1. https://services.cds.ca/applications/taxforms/taxforms.nsf/Pages/-EN-LimitedPartnershipsandIncomeTrusts -> scroll down, click 'Display T3 information for year 2020' -> scroll down, click 'I accept'
2. I'm using the spreadsheet for CUSIP 41754Q104 HARVEST GLOBAL RESOURCE LEADERS ETF because it's currently the top result but quite a lot of them have the specific formatting that invokes the bug
3. Download the spreadsheet.
4. Open with Libreoffice; I use `soffice CDSP-BRWLCN_T3_R16_TY2020_2020_07_27_11_38_36.xls` from the command line

Actual Results:
Document load is interrupted with the above-noted BASIC syntax error. The IDE will open automatically to allow the error dialog to show.

Expected Results:
The spreadsheet opens without issue.


Reproducible: Always


User Profile Reset: No


OpenGL enabled: Yes

Additional Info:
The error occurs at line 373 in the above-noted spreadsheet, but in actual fact, it is caused by the underscore line continuation character at the end of line 354 ''Nov-2013 Range("S12").Value = 0 Or _'. The one-character change of removing that underscore fixes the issue.

This appears to be code/comment in a template that is widely used which is why many of the spreadsheets at the CDS service have this problem. The underscore/comment appears at some point in the template's history, older spreadsheets don't have it and are unaffected.

https://help.libreoffice.org/7.3/en-US/text/sbasic/shared/03090407.html?DbPAR=BASIC#bm_id3154347 states that line continuation can be done in a comment, but 'Option Compatible' needs to be set, and it isn't in this sheet.

Even if it was set line 355 should break the comment continuation leaving line 356 to begin the if statement. Adding more blank lines between 354 and 356 does not change the behaviour.

MS claims you can't continue a comment: https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/program-structure/how-to-break-and-combine-statements-in-code so the fact that LibreOffice allows this but only in compatibility (with VBA) mode is strange.




Version: 7.3.3.2 / LibreOffice Community
Build ID: 30(Build:2)
CPU threads: 8; OS: Linux 5.4; UI render: default; VCL: gtk3
Locale: en-US (C.UTF-8); UI: en-US
Ubuntu package version: 1:7.3.3~rc2-0ubuntu0.18.04.1~lo1
Calc: threaded


glxinfo | grep OpenGL
OpenGL vendor string: X.Org
OpenGL renderer string: AMD TAHITI (DRM 2.50.0, 5.4.0-110-generic, LLVM 10.0.0)
OpenGL core profile version string: 4.5 (Core Profile) Mesa 20.0.8
OpenGL core profile shading language version string: 4.50
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.5 (Compatibility Profile) Mesa 20.0.8
OpenGL shading language version string: 4.50
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.2 Mesa 20.0.8
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:
Comment 1 studog 2022-05-18 17:22:38 UTC
Created attachment 180190 [details]
Copy of the spreadsheet used in the reproduction steps

Attached a copy of the spreadsheet I used as an example in the reproduction steps.
Comment 2 Mike Kaganski 2022-05-18 17:57:51 UTC Comment hidden (obsolete)
Comment 3 Mike Kaganski 2022-05-26 12:06:12 UTC
Oh wait.

The quote from VB documentation in comment 0 is unrelated: VBA is not VB, and in Excel, the code from comment 2 also shows "Compile error: Else without If"; and the syntax highlighting shows the If line as a comment. So using the comment continuation for VBA code is correct.

But in the problematic case, the continuation is followed by an empty line. So the empty line should consume the continuation - but it doesn't.

The updated problematic code is:

sub foo
  ' _

  If 1 Then
  Else
  End If
end sub

I wonder if there are other variants of the error - when the continuation ignores an empty line outside of comments ...

Another observation is: if the trailing _ is followed by a space before newline, the space doesn't cancel the continuation effect of the _, as it should.
Comment 4 Mike Kaganski 2022-05-26 12:17:07 UTC
FTR: the respective VBA documentation [1] doesn't mention a limitation for comments. Comments documentation [2], [3] also doesn't mention that.

[1] https://docs.microsoft.com/en-us/office/vba/language/glossary/vbe-glossary#line-continuation-character
[2] https://docs.microsoft.com/en-us/office/vba/language/glossary/vbe-glossary#comment
[3] https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/rem-statement
Comment 5 Commit Notification 2022-05-31 10:31:38 UTC
Andreas Heinisch committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/b94275f6d2cb4dc28d1563fd7994251042b6d51a

tdf#149157 - Break multiline continuation in a comment after a new line

It will be available in 7.4.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.
Comment 6 Commit Notification 2022-05-31 17:56:36 UTC
Andreas Heinisch committed a patch related to this issue.
It has been pushed to "libreoffice-7-3":

https://git.libreoffice.org/core/commit/73e46d86335e60f1b11a91b23522402cd34466a8

tdf#149157 - Break multiline continuation in a comment after a new line

It will be available in 7.3.5.

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.
Comment 7 studog 2024-08-27 17:21:07 UTC
(In reply to Mike Kaganski from comment #3)
> The quote from VB documentation in comment 0 is unrelated: VBA is not VB

Apologies. I should have spotted that.
Comment 8 studog 2024-08-27 17:21:32 UTC
Issue confirmed FIXED on

Version: 24.2.5.2 (X86_64) / LibreOffice Community
Build ID: 420(Build:2)
CPU threads: 16; OS: Linux 6.8; UI render: default; VCL: gtk3
Locale: en-US (C.UTF-8); UI: en-US
Ubuntu package version: 4:24.2.5-0ubuntu0.24.04.2
Calc: threaded

Thanks!