[I6] Taking object added to scope via add_to_scope causes RTEs? (has/hasnt test on nothing)

Using Inform 6.31, I came across what looks like a bug in Standard Library 6/11. However, the root cause seems to still persist in Standard Library 6.12.4. [edit: No, it fortunately doesn’t persist to 6.12.4.]

First, the demonstration code:

Constant Story "Something Broke";
Constant Headline "^(unexpected RTE)^";

Include "Parser";
Include "VerbLib";
Include "Grammar";

Object Start "Starting Point"
    with    description
                "An uninteresting room."
    has     light;

Object machine "machine" Start
    with    name    'machine',
            description
                "It has a prominent switch.",
            add_to_scope sw1
    has     static;

Object sw1 "switch"
    with    name    'switch',
            desription
                "It doesn't seem to be attached well.";


[ Initialise ;

    location = Start;

];

This yields interaction:

Starting Point
An uninteresting room.

You can see a machine here.

>TAKE SWITCH

[** Programming error: tried to test "has" or "hasnt" of nothing **]

[** Programming error: tried to test "has" or "hasnt" of nothing **]
Taken.

The problem seems to originate in routine AttemptToTakeObject (in verblibm.h), which has a block:

! Consult the immediate possessor of the item, if it's in a container
! which the player is not in.

i = parent(item);
if (i ~= ancestor && (i has container || i has supporter)) { ! PROBLEM HERE IF i == nothing
    after_recipient = i;
    k = action; action = ##LetGo;
    if (RunRoutines(i, before) ~= 0) { action = k; rtrue; }
    action=k;
}

Using a Replace directive and substituting the if statement’s condition with:

if (i ~= nothing or ancestor && (i has container || i has supporter)) { ! RTEs no longer occur

seems to stop the RTEs.

Is this a real bug in the Standard Library, or am I missing something?

Yes, I see that happening. I assume you were looking at DM4 example 103.

Seems like it must be a “new” bug since 6.21, but I don’t have older libraries lying around to test.

I can get this bad behavior with 6.11 of the Library, but not with 6.12. I’m using version 6.34 of the Compiler.

For the misbehaving game, what do you see when you type VERSION?

@DavidG, it’s Standard Library 6/11 with Inform v6.31. The version report is

Release 1 / Serial number 201028 / Inform v6.31 Library 6/11 SX
Standard interpreter 1.0 (1F) / Library serial number 040227

I was very much mistaken when I said above that the issue persisted into Standard Library 6.12.4. (I was unfortunately looking at the wrong directory’s version of the file when I tried to double-check.) The 6.12.4 Standard Library has a fix already in place for the line in question:

if (i && i ~= ancestor && (i has container or supporter)) {

Thank you for taking a look at this, and please accept my apologies for the error and the inconvenience caused.