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

Improve error message for missing field name in tuple #1522

Closed
plajjan opened this issue Oct 1, 2023 · 7 comments
Closed

Improve error message for missing field name in tuple #1522

plajjan opened this issue Oct 1, 2023 · 7 comments

Comments

@plajjan
Copy link
Contributor

plajjan commented Oct 1, 2023

I think the parsing error for this could be improved.

The last field in my tuple is missing its name:

actor main(env):
    abc = (a="foo", "bar")
kll@Boxy:~/terastream/acton$ actonc examples/foo.act
Building file examples/foo.act

ERROR: Error when compiling foo module: Syntax error
examples/foo.act:2:7:
  |
2 |     abc = (a="foo", "bar")
  |         ^^
unexpected "= "
expecting ':', ';', call arguments, slice/index expression, comma, end of line, if clause, or operator

and it's pointing to what?

@plajjan
Copy link
Contributor Author

plajjan commented Oct 1, 2023

@sydow I think this counts as a parser error, like you were looking for in #732, right? :)

@sydow
Copy link
Collaborator

sydow commented Oct 2, 2023

Yes, this is certainly a good example of a terrible error message. I will be glad to try to fix it as soon as I know what syntax should be allowed. For example, this is accepted by the compiler:

actor main(env):
abc = ("foo", b="bar")

and abc gets type (str, b : str), following the idea (for function parameters) that positional elements precede keyword ones. What are the rules for tuples with (some) named fields? Maybe this was discussed at some point, but I certainly don't remember. I am sure @nordlander does.

@plajjan
Copy link
Contributor Author

plajjan commented Oct 2, 2023

@sydow I have not been part of any such discussion - I don't think we've discussed the details of it in particular. As far as I know, the design that we've implemented is to allow tuples with either named fields or no names. Thus, mixing by providing names for some fields but not others is invalid and this seems to be enforced now (although perhaps more by happenstance!?). I don't really have an opinion on whether it makes sense to allow mixing or not. Since names are just an alias that get replaced by the index I guess it's technically possible to mix. What are the drawbacks to mixing?

In the current situation with named / unnamed mix being forbidden, the best error message is the one that guides the user to do the right thing and fix their code.

I think this looks great:

ERROR: Error when compiling foo module: Syntax error
  ╭─[ examples/foo.act:2:7 ]
  │
2 │     abc = (a=1, b=2, c=3, 4)
  .            ─┬─  ─┬─  ─┬─  ┬
  .             │    │    │   ╰──── This field does not have a name
  .             │    │    │
  .             ╰────┴────┴──────── These fields have a name
  ╰──
Error: Tuple contains a mix of named and unnamed fields.
Hint: All fields in a tuple must be named or unnamed. Either add names to all fields or remove names to make the tuple unnamed.

granted, it does quite a bit more stuff than our current error messages but I think it's the direction we should move in. This whole Error / Hint thing is one that Postgresql has implemented and it's been sooooo useful so I'd really like to have that. The ascii style drawings of things is inspired by both Haskell's error messages but also Ariadne (see #490).

@nordlander
Copy link
Contributor

nordlander commented Oct 2, 2023 via email

@sydow
Copy link
Collaborator

sydow commented Oct 2, 2023 via email

@nordlander
Copy link
Contributor

Ja, för anrop blir felmeddelandet mycket bättre! Och man borde kunna parsa tupler på precis samma sätt, tycker jag. Det som möjligen krånglar till det är att grammatiken tillåter att man utelämnar parenteserna runt en tupel på vissa ställen. Men det borde gå att begränsa om det ställer till problem. Det enda ställe där jag spontant tycker att tupler utan parentes har någon som helst poäng är vid retur av multipla funktionsresultat. Och även där är vinsten ganska blygsam.

sydow added a commit that referenced this issue Dec 5, 2023
sydow added a commit that referenced this issue Dec 5, 2023
@sydow
Copy link
Collaborator

sydow commented Dec 5, 2023

fixed by #1597

@sydow sydow closed this as completed Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants