Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

give statement with arbitrary expression produces invalid story file #171

Open
Natrium729 opened this issue Apr 20, 2022 · 5 comments
Open

Comments

@Natrium729
Copy link

The compiler accepts arbitrary expressions for attributes in the give statement. However, it sometimes produces an invalid story file in that case, without emitting an error or a warning.

For example, the following works, giving the attribute with ID 2 to the room:

Attribute locked;

Object obj;

[ Main;
	print "Give bug^";
	give obj 1 + 1;
];

(Compiled with inform6 -~S~D -c test.inf)

However, if we replace 1 + 1 with a parenthesised expression such as (1 + 1) or even (locked), Quixe will show this error message when running the story : "Error: Unknown opcode #0 at pc=201". Gargoyle (git) also complains with a different error message: "Fatal error: too many (48) locals at 0x14 (pc = 0x512)".

On one hand, that situation shouldn't happen often since authors aren't likely to use expression in that place. On the other hand, the compiler should never produce an invalid file without complaining.

I'm not sure if accepting arbitrary expressions in that place is a good idea since it leads to ambiguous syntax. But I'm not really sure what should be done.

@erkyrath
Copy link
Contributor

erkyrath commented Apr 20, 2022

Expressions should be valid there. This is a code generation bug.

(In the line give obj 1 + 1, the expression gets folded to a constant at compile time. That's why the bug doesn't show up.)

@erkyrath
Copy link
Contributor

Whoops, hang on, I'm wrong about what happened.

The line give obj (1); is parsed as give X; where X is a function call obj(1). That's the ambiguity you were referring to. It's confusing because give X; is legal, according to the language def -- it gives the object X zero attributes.

Yeah, it's not obvious how to even detect this. We could warn on give X; but then the same problem occurs with give obj (1) light;.

Maybe the call syntax X(Y) can do some static type-checking.

@erkyrath
Copy link
Contributor

On the other hand, the compiler should never produce an invalid file without complaining.

This is not a rule at all, I'm afraid. There are an infinite number of ways to produce an invalid story file. Calling X() where X is not a function is just one of them.

@Natrium729
Copy link
Author

Ah, I didn't know it was possible to have a give statement without attributes. (And I also totally forgot about constant folding.)

In that case, yeah, the syntax is ambiguous but the compiler isn't wrong either, so I guess it's not a bug after all. (Although I would have thought interpreters would display an error message in the lines of "tried to call something that's not a routine".)

I suppose that, as you said, it should be possible to type-check routine calls, but that's not extremely important either.

@erkyrath
Copy link
Contributor

#172 is the routine-call type check.

line 12: Warning:  In function call, expected Routine but found Object "obj"
>  give obj (1+1);

Of course this warning only appears when obj is an Object literal. If it's a local variable, the compiler can't help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants