roc/compiler/can/src
ayazhafiz 30955a1eb8 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
2021-11-18 20:20:33 -05:00
..
annotation.rs Parse _ in type annotations as an 'Inferred' type 2021-11-17 17:59:40 -08:00
builtins.rs fmt 2021-11-18 11:17:05 +00:00
constraint.rs further optimizations 2021-08-13 13:25:36 +02:00
def.rs remove im dependency where not needed 2021-11-10 16:00:22 +01:00
env.rs use IdentStr 2021-08-03 21:14:36 +02:00
expected.rs initial solver for the editor's type constraints 2021-04-12 21:26:20 +02:00
expr.rs Take syntactic sugar into account when reporting errors 2021-11-18 20:20:33 -05:00
lib.rs Clean up some clippy warnings 2021-05-23 20:28:23 -04:00
module.rs Update dep with major version changes 2021-11-05 19:19:37 -07:00
num.rs Also store f64 for things like pattern comparisons, etc 2021-08-18 17:18:13 -07:00
operator.rs Shrink Collection to make parse_expr_size test pass 2021-11-13 16:17:44 -08:00
pattern.rs Use Collection in Expr::Record and related places 2021-11-13 07:36:05 -08:00
procedure.rs fix most type inference issues 2020-10-16 20:50:42 +02:00
scope.rs Update dep with major version changes 2021-11-05 19:19:37 -07:00
string.rs s/CodePoint/CodePt/g 2021-08-07 21:46:20 -04:00