Bug 152132 - Hash Mark Lines (#define) treated as comments in Libre Office Basic
Summary: Hash Mark Lines (#define) treated as comments in Libre Office Basic
Status: UNCONFIRMED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
7.4.2.3 release
Hardware: All All
: medium enhancement
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-11-20 01:44 UTC by tanh
Modified: 2022-12-01 17:20 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 tanh 2022-11-20 01:44:45 UTC
Description:
#if fred
Is treated as a comment.
It should always be treated as an error.

Steps to Reproduce:
Create new Basic subroutine:
sub Mysub
#if fred
dim a as int
#else
dim a as int
#endif
end sub

Run the sub.
1.Import VBA module containing #if, #else, #endif
2.Run any function in the module
3.

Actual Results:
BASIC syntax error. Variable a already defined.

Expected Results:
Lines starting with # are errors


Reproducible: Always


User Profile Reset: Yes

Additional Info:
It would be really nice if BASIC handled #if, #else the same way VBA 6 or 7 do: as conditional compilation meta commands.  Some older OO versions handled this differently, the initial syntax check handled #if as if: for declaration outside of a function I got "If outside of function or sub is not allowed"

But the present implementation is even worse: #if and #else are silently ignored when inside a function, so both branches are included.

In VBA back to Office 97, #if allows you to include different branches for different #defines. There are predefined values ('Win32' etc), and two different ways of defining values. #if is commonly used to allow different branches for VBA7 and OSX: it may also be used generally, as for debug builds.

When VBA code is imported into LO, the idiosyncratic treatment of # meta commands is confusing and unexpected: the lack of documentation contributes to the problem.

Implementing the feature correctly would be good: implementing the feature in a minimal way with a clear error message would be good enough.


Version: 7.4.2.3 (x86) / LibreOffice Community
Build ID: 382eef1f22670f7f4118c8c2dd222ec7ad009daf
CPU threads: 4; OS: Windows 6.1 Service Pack 1 Build 7601; UI render: Skia/Raster; VCL: win
Locale: en-AU (en_AU); UI: en-US
Calc: threaded
Comment 1 Xisco Faulí 2022-11-28 15:28:37 UTC
@Andreas, I thought you might be interested in this issue
Comment 2 Alain Romedenne 2022-12-01 17:20:49 UTC
Here's official VBA documentation on this matter
https://learn.microsoft.com/en-us/office/vba/language/concepts/getting-started/compiler-constants