ID:2845642
 
Not a bug
BYOND Version:514
Operating System:Windows 7 Ultimate 64-bit
Web Browser:Firefox 108.0
Applies to:DM Language
Status: Not a bug

This is not a bug. It may be an incorrect use of syntax or a limitation in the software. For further discussion on the matter, please consult the BYOND forums.
Descriptive Problem Summary:
When using nested defines, some very non-intuitive behaviour occurs. Compilation fails with nonsensical error messages.
This is actually two related bugs, one for whitespace preceding a macro'd `#define` and one far broken parsing of a nested macro'd define.
Numbered Steps to Reproduce Problem:
Compile the code snippet:

Code Snippet (if applicable) to Reproduce Problem:
#define DEFINE #define
#define DEFINE_NESTED(NAME, VALUE) \
DEFINE NAME VALUE

#define DEFINE_NESTED_WITH_STATEMENT(NAME, VALUE) \
var/test = 4\
DEFINE NAME VALUE


DEFINE A 1
DEFINE_NESTED(B, 2)

//note the space before the define
DEFINE C 3
DEFINE_NESTED_WITH_STATEMENT(D, 4)


/world/New()
ASSERT(A == 1)
ASSERT(B == 2)
ASSERT(C == 3)
ASSERT(D == 4)


Expected Results:
Compile and run with no errors

Actual Results:
loading test.dme
test.dm:11:error: : duplicate definition
test.dm:15:error: world/New: undefined var
test.dm:16:error: 1: duplicate definition
test.dm:16:error: 1: duplicate definition
test.dm:16:error: ==: instruction not allowed here
test.dm:16:error: : empty type name (indentation error?)
test.dm:16:error: : duplicate definition
test.dm:17:error: 2: duplicate definition
test.dm:17:error: 2: duplicate definition
test.dm:17:error: ==: instruction not allowed here
test.dm:17:error: : empty type name (indentation error?)
test.dm:17:error: : duplicate definition
test.dm:18:error: 3: duplicate definition
test.dm:18:error: 3: duplicate definition
test.dm:18:error: ==: instruction not allowed here
test.dm:18:error: : empty type name (indentation error?)
test.dm:18:error: : duplicate definition
test.dme:17:error: 4: duplicate definition
test.dme:17:error: 4: duplicate definition
test.dme:17:error: ==: instruction not allowed here
test.dme:17:error: : empty type name (indentation error?)
test.dme:17:error: : duplicate definition
test.dm:16:error: "test.dm": duplicate definition
test.dm:16:error: 16: duplicate definition
test.dm:16:error: "A == 1": duplicate definition
test.dm:16:error: text"[]:[]:Assertion Failed: []": value not allowed here
test.dm:16:error: : empty type name (indentation error?)
test.dm:16:error: : duplicate definition
test.dm:17:error: "test.dm": duplicate definition
test.dm:17:error: 17: duplicate definition
test.dm:17:error: "B == 2": duplicate definition
test.dm:17:error: text"[]:[]:Assertion Failed: []": value not allowed here
test.dm:17:error: : empty type name (indentation error?)
test.dm:17:error: : duplicate definition
test.dm:18:error: "test.dm": duplicate definition
test.dm:18:error: 18: duplicate definition
test.dm:18:error: "C == 3": duplicate definition
test.dm:18:error: text"[]:[]:Assertion Failed: []": value not allowed here
test.dm:18:error: : empty type name (indentation error?)
test.dm:18:error: : duplicate definition
test.dme:17:error: "test.dme": duplicate definition
test.dme:17:error: 17: duplicate definition
test.dme:17:error: "D == 4": duplicate definition
test.dme:17:error: text"[]:[]:Assertion Failed: []": value not allowed here
test.dme:17:error: : empty type name (indentation error?)
test.dme:17:error: : duplicate definition
test.dm:16:error: : duplicate definition
test.dmb - 47 errors, 0 warnings (1/3/23 2:22 pm)


Does the problem occur:
Every time? Or how often? Every time
In other games? N/A
In other user accounts? N/A
On other computers? Yes

When does the problem NOT occur?
Removing the whitespace from
 DEFINE C 3
causes that line not to error, as does manually changing it to read
 #define C 3
. As far as I can tell, nothing fixes what is happening in
DEFINE_NESTED_WITH_STATEMENT(D, 4)

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? (Visit http://www.byond.com/download/build to download old versions for testing.)
Does not work in any version I tested, from 514.1578 to 515.1597

Workarounds:
None

Slightly minimal-er example of DEFINE_NESTED_WITH_STATEMENT which is also broken:
#define DEFINE #define
#define DEFINE_NESTED_WITH_STATEMENT(NAME, VALUE) \
var/test = 4\
DEFINE NAME VALUE


DEFINE_NESTED_WITH_STATEMENT(D, 4)

/world/New()
ASSERT(D == 4)
Actually, this can be closed. It turns out I didn't understand that multi-line macros aren't really multiline. Adding a semicolon after the var definition causes it to parse as expected.

The space before DEFINE C 3 causing an error is still weird though.
Lummox JR resolved issue (Not a bug)