Inform 6 error when compiling with -D without the library

When compiling the following source:

!% -Cu
!% -D

Object test
    with boom [;
        print "Boom.";

[ Main;
    ! This method call is causing the error.
    ! But other things can cause it, such as `give test attribute`.

I get the following errors:

<veneer routine 'CA__Pr'>(1): Error:  '=' applied to undeclared variable
> ebug_flag=debug_flag-n;
<veneer routine 'CA__Pr'>(1): Error:  Expected expression with side-effects but found <constant>
> ebug_flag=debug_flag-n;
<veneer routine 'CA__Pr'>(1): Error:  '=' applied to undeclared variable
> ebug_flag = debug_flag + n;
<veneer routine 'CA__Pr'>(1): Error:  Expected expression with side-effects but found <constant>
> ebug_flag = debug_flag + n;
Compiled with 4 errors (no output)

They go away without the -D, or by adding

Global debug_flag;
Attribute workflag;
[ DebugAttribute x; ];

or by using the library, which defines the above.

So it seems the compiler and the library are coupled in some way and that it’s not possible to use the first without the second? Or am I doing something wrong?

I’m using Inform 6.34 on Windows, if that matters.

Nope, you’re right, that’s an entanglement.

This example only happens when compiling for Z-code. However, there are expressions which cause the same error (undeclared variable debug_flag) in either Z-code or Glulx:

test.boom = 5;   ! if -S is set
give test attr;  ! if -S is set

…and so on.

Now it’s not true that you have to use the library code. As you found, you (or any alternate library) only has to define those three items (debug_flag, DebugAttribute(), workflag). This is a bit of extra load if you’re seriously trying to minimize your game space – but you can wrap those definitions in #ifdef DEBUG.

It would be cleaner if the debug code that used debug_flag were only compiled in if debug_flag were actually defined. (Etc.) This is possible, but it would be a fair amount of extra mess in the veneer code.

Instead of having the code using debug_flag compiled only if it’s actually defined, what about the compiler defining debug_flag automatically if not present before the veneer routine in debug mode ?

But if there are no side effects of defining them myself, I’ll do that. Thanks!

(Is it worth a bug report? A small one, affecting only people not using the library, but still a bug, right?)

There’s currently no place in the compiler code for the veneer to conditionally define variables or attributes. Which is not to say it can’t happen, but it’s a somewhat messy road.

Yeah, the current de-facto recommendation is that every Inform library should define those three things under #ifdef DEBUG. (Unless workflag is available as a general library attribute, in which case it’s always defined.) If you’re writing a game with no library and you want to use -D, you have to define them yourself.

Yes, it’s worth a bug report. It might remain open for a long while marked “this would be nice to improve someday”, but it should be written down.