GaloisInc / saw-script

The SAW scripting language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SAWScript: `Record lookup on non-record argument` error, when function parameter is not explicitly annotated with record type

qsctr opened this issue · comments

sawscript> (\r -> r.a) { a = 2 }

<stdin>:1:8-1:11: Record lookup on non-record argument.
Field name: a

sawscript> (\(r : { a : Int }) -> r.a) { a = 2 }
[05:22:32.360] 2

It seems like SAW is unable to infer the type of r when it is not explicitly annotated. But even with this limitation, the error message is confusing, since it is claiming that r is not a record when really it doesn't know what r is. We should either improve type inference or at least change the error message.

This works in Cryptol:

Cryptol> (\r -> r.a) { a = 2 }
Showing a specific instance of polymorphic result:
  * Using 'Integer' for the type of '(expression)'
2

I agree that we should improve the error message at the very least. Improving SAWScript's type inference would also be nice, although it doesn't seem as high of a priority, especially since Cryptol's own type inference for record types is somewhat poor, e.g.,

Cryptol> :t \r -> r.a

[error] at <interactive>:1:10--1:13:
  Failed to infer the following types:
    • ?a, type of function result at <interactive>:1:4--1:13
    • ?b, the type of 'r' at <interactive>:1:5--1:6
  subject to the following constraints:
    • field a of ?b is ?a
        arising from
        use of selector
        at <interactive>:1:10--1:13