mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
Take syntactic sugar into account when reporting errors
Previously, a program like ```roc word = "word" if True then 1 else "\(word) is a word" ``` would report an error like ``` ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── This `if` has an `else` branch with a different type from its `then` branch: 3│ if True then 1 else "\(word) is a word" ^^^^^^^^^^^^^^^^^^ This concat all produces: Str but the `then` branch has the type: Num a I need all branches in an `if` to have the same type! ``` but this is a little bit confusing, since the user shouldn't have to know (or care) that string interpolations are equivalent to concatenations under the current implementation. Indeed we should make this fully transparent. We now word the error message by taking into account the way calls are made. To support the case shown above, we introduce the `CalledVia::Sugar` variant to represent the fact that some calls may be the result of desugaring the surface syntax. This commit also demonstrates the usage of `CalledVia` to produce better error messages where we use binary comparison operators like `<`. There are more improvements we can make here for all `CalledVia` variants, but this is a good starting point to demonstrate the usage of the new procedure. Closes #1714
This commit is contained in:
parent
a4fc813ca3
commit
30955a1eb8
7 changed files with 110 additions and 10 deletions
|
@ -12,6 +12,15 @@ pub enum CalledVia {
|
|||
|
||||
/// Calling with a unary operator, e.g. (!foo bar baz) or (-foo bar baz)
|
||||
UnaryOp(UnaryOp),
|
||||
|
||||
/// This call is the result of some desugaring, e.g. "\(first) \(last)" is
|
||||
/// transformed into first ++ last.
|
||||
Sugar(Sugar),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Sugar {
|
||||
StringInterpolation,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue