GaloisInc / saw-script

The SAW scripting language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nonexistent types in function arguments aren't detected

sauclovian-g opened this issue · comments

Consider the following otherwise useless script with a typo in it:

typedef FooType = {
   Thingy : (() -> ())
};

let foo_id (foo : FooTYpe) = foo;

It seems like this should not be allowed, because it names a type that doesn't exist. However, it's accepted silently.

This gets substantially more confusing if you try to access the members of the type:

typedef FooType = {
   Thingy : (() -> ())
};

let do_thingy (foo : FooTYpe) = foo.Thingy ();

because now it fails with the error Record lookup on non-record argument. If you can't spot the typo (or worse, you've got a name with multiple plausible spellings and you're using the wrong one, like Grey and Gray) this is horribly frustrating.

In the example above, FooTYpe is treated as a type variable. Type variables can begin with either lower or uppercase in SAWScript, and if a name does not refer to an existing identifier, then it is treated as a type variable:

sawscript> :type foo_id
{a.0} a.0 -> a.0

I can see why this would be confusing, although this is behaving as expected in some sense. Perhaps we could mention this in the SAW manual?

Shouldn't (in the case where it's used at least, like in do_thingy) it then infer that it's a struct type, namely the same type that would be inferred for the function's return struct if there weren't an annotation? That would still produce somewhat unexpected behavior when there's a type conflict later on, but it wouldn't have the same flavor of "why is this just ignoring what I'm telling it and what do I even do about it?"

(also in the long run I would be all for moving to explicit declaration of type variables like Cryptol, but that's not a change one can just make arbitrarily)

Indeed, SAWScript's type inference could stand to be improved in this regard. See also #1995.

Hmm in that case there's probably no need to keep this issue open

Oops, wrong kind of close

ok then, how about closing it as invalid?