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

Point error messages at the offending record field if possible #1459

Open
vkleen opened this issue Jul 17, 2023 · 0 comments
Open

Point error messages at the offending record field if possible #1459

vkleen opened this issue Jul 17, 2023 · 0 comments

Comments

@vkleen
Copy link
Member

vkleen commented Jul 17, 2023

Inspired by this discussion question: #1458. We should have error messages point at a particular field definition in a record, when that makes sense. For example, the code

let Contract = { foo, bar } in
{
  foo = 5,
  bar = 6,
  baz = 2,
} | Contract

produces an error message that starts with

error: contract broken by a value: extra field `baz`
  ┌─ fruits.ncl:2:1
  │
2 │ ╭ {
3 │ │   foo = 5,
4 │ │   bar = 6,
5 │ │   baz = 2,
6 │ │ }
  │ ╰─^ applied to this expression
7 │     | Contract
  │       -------- expected type

Note that the term being blamed is the entire definition of the record while, arguably, the problem is with the definition of baz. Especially for very large records this could make the difference between an easily localized problem and a frustrating debug session. Just imagine a record like the top-level of nixpkgs.

We should also find some way to make this feature available to user writter contracts. There should be some function on blame labels that could be used to point it at a specific record field name, not just at a field value as could be achieved with std.contract.apply.

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

No branches or pull requests

1 participant