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

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

Open
qsctr opened this issue Dec 9, 2023 · 2 comments
Labels
topics: error-messages Issues involving the messages SAW produces on error type: bug Issues reporting bugs or unexpected/unwanted behavior
Milestone

Comments

@qsctr
Copy link
Contributor

qsctr commented Dec 9, 2023

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
@qsctr qsctr added type: bug Issues reporting bugs or unexpected/unwanted behavior topics: error-messages Issues involving the messages SAW produces on error labels Dec 9, 2023
@RyanGlScott
Copy link
Contributor

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

@sauclovian-g
Copy link
Collaborator

This is probably the same as #2105.

@sauclovian-g sauclovian-g added this to the 2024T3 milestone Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topics: error-messages Issues involving the messages SAW produces on error type: bug Issues reporting bugs or unexpected/unwanted behavior
Projects
None yet
Development

No branches or pull requests

3 participants