swarm-game / swarm

Resource gathering + programming game
Other
835 stars 52 forks source link

Statically verify that constant-valued text args to commands refer to valid entities #1716

Open kostmo opened 9 months ago

kostmo commented 9 months ago

In a .sw program, when we encounter a line:

place "foo";

given the context of a scenario, we should be able to check statically whether "foo" refers to an existing entity.

Entities are defined both globally and on a per-scenario basis.

Also related: #1301

byorgey commented 1 day ago

One slight practical difficulty is that we do not currently pass along the set of existing entities during typechecking. An alternative idea would be to check this in a separate pass, after typechecking has succeeded --- traverse through the term just looking for literal text arguments to functions that expect entities, and make sure they are known.

If we ever do #455 it would certainly change what this looks like, but that need not stop us implementing this useful (and hopefully not too difficult) check in the meantime.