Commit graph

208 commits

Author SHA1 Message Date
Chelsea Troy
6cf755ad8d Resolve a bunnnch of merge conflicts 2021-11-29 23:14:29 -06:00
ayazhafiz
d352d2cdf8 Revert "Include annotation type signatures in Expected struct"
This reverts commit 6e4fd5f06a1ae6138659b0073b4e2b375a499588.

This idea didn't work out because cloning the type and storing it on a
variable still resulted in the solver trying to uify the variable with
the type. When there were errors, which there certainly would be if we
tried to unify the variable with a structure that had nested flex/rigid
vars, the nested flex/rigid vars would inherit those errors, and the
program wouldn't typecheck.

Since the motivation here was to expose the signature type to
`reporting` so that we could modify it with suggestions, we should
instead pass that information along in something analogous to the
`Expected` struct.
2021-11-25 13:24:42 -05:00
ayazhafiz
ee34e79790 Include annotation type signatures in Expected struct
To provide better error messages and suggestions related to changing
type annotations, we now pass annotation type signatures all the way
down through the constraint solver. At constraint generation we
associate the type signature with a unique variable, and during error
reporting, we pull out an `ErrorType` corresponding to the original type
signature, by looking up the unique variable. This gives us two nice
things:

1. It means we don't have to pass the original, AST-like type
   annotation, which can be quite large, to everyone who looks at an
   expectation.
2. It gives us a translation from a `Type` to an `ErrorType` for free
   using the existing translation procedure in `roc_types::subs`,
   without having to create a new translation function.
2021-11-25 11:16:17 -05:00
ayazhafiz
62873fed81 Propogate original annotation region down in AnnotationSource
This makes it easier for error reporting to find the relevant
annotations that were part of a type error, and display that in the
error message presented to a user.
2021-11-25 11:15:31 -05:00
Folkert
3139e73cf9 optimize non-capturing closure type 2021-11-24 23:14:53 +01:00
Folkert
cb8e9acb92 special-case the closure tags 2021-11-24 21:14:58 +01: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
a15183a7d1 refactor 2021-11-03 14:09:04 +01:00
Folkert
dfbdeab6f3 use u32, not unsigned32 2021-10-02 20:24:05 +02:00
Eric Correia
8272ea876f Get it all to compile! 2021-10-02 13:48:07 -04:00
Folkert
72194b87df fix typo 2021-09-24 21:58:25 +02:00
Folkert
23e8f6c687 only introduce rigid once! 2021-09-24 21:53:41 +02:00
Jared Ramirez
d69b9173fc Also store f64 for things like pattern comparisons, etc 2021-08-18 17:18:13 -07:00
Folkert
24ddc4b1e8 further optimizations 2021-08-13 13:25:36 +02:00
Folkert
899cbeabd7 fix extra ampersands 2021-07-29 17:32:08 +02:00
Folkert
ab7f4a70a1 remove list_var 2021-06-13 16:56:59 +02:00
Anton-4
314503cf7f fixed typos, added typos checking to CI 2021-06-05 20:02:54 +02:00
Folkert
e81087f913 Merge remote-tracking branch 'origin/trunk' into specialize-lowlevel 2021-05-24 15:17:28 +02:00
tarjei
0ee15f15ee Unify FunctionOrTagUnion with regular tags and functions 2021-05-23 23:14:17 +02:00
Eric Henry
d34f984169 Starting to add no arg tag union 2021-05-17 17:07:19 -04:00
Folkert
a055fa3626 fix record accessors 2021-05-14 13:07:35 +02:00
Folkert
694a896d54 fix closure size inference 2021-05-09 16:07:52 +02:00
Folkert
b01377f868 save the stack 2021-04-23 11:49:32 +02:00
Folkert
903583f1d4 implement basic type error reporting 2021-04-23 09:41:49 +02:00
Folkert
4dd0ee6543 constrain expect 2021-04-23 09:36:12 +02:00
Folkert
112e97c4a2 improve circular definition error reporting 2021-04-10 21:39:20 +02:00
Jared Ramirez
48f964adf4 Add percision variable in fp/integer eq constraints 2020-12-28 16:22:34 -06:00
Folkert
b669202d86 fix wildcards not recognized as rigids 2020-12-11 01:49:54 +01:00
Folkert
197abd8553 change constraints gen to give better errors 2020-11-15 02:06:34 +01:00
Folkert
23fe8e5c07 fix another nasty rigid problem 2020-11-15 00:23:32 +01:00
Folkert
ec3868ed7e small rigid fix 2020-11-14 02:45:05 +01:00
Folkert
815b942f29 cleanup 2020-11-13 01:59:09 +01:00
Folkert
78e0886eb1 clippy 2020-11-13 01:42:31 +01:00
Folkert
bde82c3bb6 add Store constraint that does not report errors 2020-11-12 15:47:56 +01:00
Folkert
75d18eb8ba no more rigid mistakes? 2020-11-12 15:31:25 +01:00
Folkert
7a719172bc more rigid fixes? 2020-11-12 14:55:46 +01:00
Folkert
eaf94f2cfc uncomment more of rbtree 2020-11-12 00:45:47 +01:00
Folkert
22592eff80 fix issue with rigids 2020-11-11 22:51:28 +01:00
Folkert
0ba612ecdb refactor 2020-11-11 21:56:25 +01:00
Folkert
62a82d1135 extract untyped args helper 2020-11-11 21:46:12 +01:00
Folkert
d6e7e8381c make it clearer the variables come from the def's pattern 2020-11-11 20:49:04 +01:00
Folkert
984cf744e3 make Storage store where it came from 2020-11-11 01:16:30 +01:00
Folkert
c64a6da745 make Storage store where it came from 2020-11-11 01:14:15 +01:00
Folkert
3aa6455795 fix problem with recursive definition constraint gen 2020-11-10 19:40:35 +01:00
Folkert
3cd132dd51 introduce foreign call 2020-11-05 23:35:56 +01:00
Folkert
b075c2d394 clean up imports 2020-10-31 15:36:46 +01:00
Folkert
8b3b677439 remove aliases from Let and LetCon 2020-10-31 15:27:24 +01:00
Folkert
9e981c264e fix clippy issues 2020-10-30 22:28:55 +01:00
Folkert
58467d6515 get tests back up an running 2020-10-30 16:58:53 +01:00
Folkert
8a50d48ce2 expand aliases used in constraint gen 2020-10-29 22:31:14 +01:00