DavidKinder / Inform6

The latest version of the Inform 6 compiler, used for generating interactive fiction games.
http://inform-fiction.org/
Other
199 stars 32 forks source link

Verb declarations can clash if the verbs encode to the same dict word #285

Closed erkyrath closed 2 months ago

erkyrath commented 3 months ago

This is accepted:

Verb 'stockpile' * -> Ding;
Verb 'stockPile' * -> Ding;

It should trigger a "Two different verb definitions refer to 'stockpile'" error.

Same with this (assuming the standard DICT_WORD_SIZE=9):

Verb 'stockpile' * -> Ding;
Verb 'stockpilexx' * -> Ding;
erkyrath commented 3 months ago

The generated grammar table can go bad when this happens. See this example:

Constant Story "Test";
Constant Headline "^A test^";
Release 1;

Include "Parser";
Include "VerbLib";

[ Initialise;
    location = Kitchen;
];

Object   Kitchen "Kitchen"
  with description "The kitchen.",
  has  light;

Include "Grammar";

[ PopSub;
    print "Pop.^";
];

[ DingSub;
    print "Ding.^";
];

Verb 'pop' * -> Pop;

Verb 'stockpile' * -> Ding;
Verb 'stockpilexx' * -> Ding;

Verb 'ding' * -> Ding;

Kitchen The kitchen.

>stockpile Pop.

Note that we get the wrong action number out.

erkyrath commented 3 months ago

That was Glulx. In Zcode:

>stockpile Time passes.

>showverb stockpile Verb 'stockpile' 'wait' 'z'

  • -> Wait
erkyrath commented 3 months ago

I think that in make_verb(), we need to call dictionary_add() earlier and track verbs by their dict word number, not their string value.

erkyrath commented 3 months ago

It's not the grammar table that's bad, but #dict_par2 of the verb word. We wind up calling dictionary_add() with the same dict word and two different flag2 values. These get bitwise-or'd together, producing nonsense.

erkyrath commented 2 months ago

I suppose one option is to accept this and treat it like an implicit Extend. That is, just treat this as a legal way to extend a verb:

Verb 'take' 'inventory' * -> Inv;
Verb 'take' noun * -> Take;

There's been no call for this by I6 authors, but it might make life easier for I7.

erkyrath commented 2 months ago

I split off the last idea as a separate task, so this can be closed with https://github.com/DavidKinder/Inform6/pull/287 .