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

illegal (?) give syntax produces a Compiler Error #248

Closed sig11b closed 9 months ago

sig11b commented 9 months ago

I received a compiler error, and the error message asked me to submit a bug report. So here it goes. I could boil it down to a tiny story which still produces the error. I'm pretty sure, that this is some sort of illegal syntax, but that's what I accidentally typed. The offending line is give (hall ~on);

and here the full story:

Constant Story "Bug";
Constant Headline "bug";

Include "Parser";
Include "VerbLib";

[ Initialise ;
  location = hall;
  ! The following illegal (?) syntax causes a compiler error.
  ! It requires BOTH, the brackets AND the tilde sign.
  give (hall ~on);
];

Object hall "Hall"
  with description
  "This is the entrance hall.";

Include "Grammar";

This is what I got:

Inform 6.41 for Linux (22nd July 2022)
line 9: *** Compiler error:  SR error: emitter stack overfull
line 9: Error:  Expected expression but found ]
> ]
line 12: Error:  Expected expression with side-effects but found <constant>
> Object hall
line 16: Error:  Expected expression with side-effects but found Include
> Include "Grammar"
line 18: Error:  Expected ']' but found <end of file>
> 
line 18: Error:  Expected ';' after ']' but found <end of file>
> 
Compiled with 5 errors (no output)
***********************************************************************
* 'Compiler errors' should never occur if Inform is working properly. *
* This is version 6.41 of Inform, dated       22nd July 2022: so      *
* if that was more than a year ago, there may be a more recent        *
* version available, from which the problem may have been removed.    *
* If not, please report this fault as an issue at                     *
* https://github.com/DavidKinder/Inform6/ and if at all possible,     *
* please include your source code, as faults such as these are rare   *
* and often difficult to reproduce.  Sorry.                           *
***********************************************************************
erkyrath commented 9 months ago

Verified in the latest source. Thanks!

Yeah, that's invalid syntax. You want give hall ~on; with no parens.

erkyrath commented 9 months ago

Similar errors occur for:

val = (2~1);
val = ((2)~1);
val = (2 ~~ 1);

But not:

val = 2~1;   ! invalid but produces a sensible error
val = ~1;    ! valid, bitwise not
val = (~1);  ! ditto
erkyrath commented 9 months ago

While we're looking at prefix/postfix unary operators:

val = (1 -- 2);
val = (1 ++ 2);

...both produce:

line 7: Compiler error: SR error: Attempt to remove a nonexistent bracket layer from the emitter stack line 7: Compiler error: SR error: emitter stack overfull in subexpression line 7: Compiler error: SR error: Attempt to remove a nonexistent bracket layer from the emitter stack line 7: Compiler error: SR error: emitter stack overfull

erkyrath commented 9 months ago

My current thinking about this:

If you write (1 2) as an expression, the compiler correctly diagnoses this as two expressions with no operator between them:

Error: Missing operator: inserting '+'

("Inserting '+'" is just a way to continue compiling the line. I think I want to remove those words from the error; it's just confusing to the user.)

Writing (1 ~2) or (1 ++x) is the same mistake, but the compiler fails to recognize it. So that's the check I want to add. Haven't figured out where to add it yet.

Of course the trick is that (1-2) is not a mistake, because - is both a unary and binary operator.

erkyrath commented 9 months ago

More troubling: the expression (x++-1), which should be valid, also produces an internal compiler error!

Without the parens, it produces (not-internal) error: "Expected ';' but found -".

Written (x++)-1, it works correctly.

EDIT-ADD: It looks like the compiler is treating the - as unary in this expression. That's why it thinks the expression is invalid. This is wrong, but it's an unrelated error and not one I'm very worried about. I'm just going to handle the internal compiler error issue.