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

Confusing error expected pattern, found... in let-bindings #4027

Closed
1 task done
Leedehai opened this issue Apr 28, 2024 · 0 comments · Fixed by #4034
Closed
1 task done

Confusing error expected pattern, found... in let-bindings #4027

Leedehai opened this issue Apr 28, 2024 · 0 comments · Fixed by #4034
Labels
bug Something isn't working diagnostics Improvements to compiler errors

Comments

@Leedehai
Copy link
Contributor

Description

Since release 0.11, context is a new reserved keyword, but if an unwitting user wants to define a variable named context, the error message is confusing:

#let context = 1 + 2
// actual error: 1:6-1:13 expected pattern, found `context` expression
// I suggest:    1:6-1:13 expected identifier name, found keyword `context`

Similar but different, because the error highlighted the entire let = 1 + 2 part, not just the second let word:

#let let = 1 + 2
// actual error: 1:6-1:17 expected pattern, found `let` expression
// I suggest:    1:6-1:9 expected identifier name, found keyword `let`

Note the highlighted span (1:6-1:17) let = 1 + 2 is actually not a valid "let expression" either -- it's missing the identifier.


Okay-ish because it says as is a keyword and there's an hint, but the word "pattern" here is still confusing to users. Note it does not refer to Typst's pattern type.

#let as = 1 + 2
// actual output:
// Error: 1:6-1:8 expected pattern, found keyword `as`
// Hint: 1:6-1:8 keyword `as` is not allowed as an identifier; try `as_` instead

Typst thrives on clear error messages (much clearer than LaTeX :) ), so I think it's worth improvement in these cases.

Reproduction URL

No response

Operating system

Web app, Windows, Linux, macOS

Typst version

  • I am using the latest version of Typst
@Leedehai Leedehai added the bug Something isn't working label Apr 28, 2024
@laurmaedje laurmaedje added the diagnostics Improvements to compiler errors label Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working diagnostics Improvements to compiler errors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants