Commit Graph

108 Commits

Author SHA1 Message Date
ayazhafiz
8a60162a1e Rename roc_module::operator -> roc_module::called_via
A bit of a nit, but this file is now more general than just keeping
track of operator methods.
2021-11-18 20:20:33 -05:00
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
Folkert
9aca302c39 Merge remote-tracking branch 'origin/trunk' into deep-copy-var-to 2021-11-18 13:16:24 +01:00
ayazhafiz
d165052e64 Fix typo 2021-11-18 00:12:17 -05:00
ayazhafiz
22be349392 Remove redundant import 2021-11-17 22:48:41 -05:00
ayazhafiz
214b8a30a9 Suggest typo fixes for non-existing module values 2021-11-17 22:40:51 -05:00
ayazhafiz
c156f61b0f Suggest tags of primitive types when an ident is misspelled
With this change, mispellings of things like `true` and `false` will
include a hint to the user that they may want to use `True` and `False`,
respectively, instead.

There are a few ways to implement this, but exposing these common tags
(which compose builtin type aliases) seems the easiest, least expensive,
and doesn't break anything for now.
2021-11-17 22:40:51 -05:00
Callum Dunster
f972098e70 Move reporting module into root. 2021-11-16 19:58:21 +01:00