Commit graph

265 commits

Author SHA1 Message Date
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
e030cd3da5 optimize restore 2021-11-17 16:33:32 +01:00
Folkert
237d8d1c0b fix the Default instance for subs
we later rely on some variables always existing (numbers, empty record, empty tag union)
but the default instance did not insert those
2021-11-17 16:29:16 +01:00
Folkert
ede5967ced Merge remote-tracking branch 'origin/trunk' into deep-copy-var-to 2021-11-16 23:56:11 +01:00
Folkert
849510c42c WIP 2021-11-16 23:55:11 +01:00
Folkert
db081cd84b WIP 2021-11-15 20:12:48 +01:00
Folkert
2c0aac2a6a remove solved type hash instance 2021-11-14 22:20:06 +01:00
Brendan Hansknecht
d49ac68bcc Update dep with major version changes 2021-11-05 19:19:37 -07:00
Brendan Hansknecht
bddc08c977 Remove unused dependencies 2021-11-05 16:58:11 -07:00
Anton-4
a3fc724df3 removed unused maplit 2021-11-03 10:50:25 +01:00
Folkert
30e7f7b335 make solved type hash use an explicit stack (no recursion) 2021-10-29 21:24:40 +02:00
Folkert
55f8a7f3a4 implement print of FunctionOrTagUnion 2021-10-13 14:50:21 +02:00
Folkert
6a43be26d3 fix usize vs. u32/u64 conflict 2021-08-25 20:58:42 +02:00
Folkert
aa042f3357 better debug info for a mismatch 2021-08-20 22:41:43 +02:00
Richard Feldman
0bebb64bae
Merge branch 'trunk' into NumBytesTo 2021-08-19 01:37:39 -04:00
Folkert
6284a90785 a working version 2021-08-18 17:36:27 +02:00
Folkert
4e728c7222 add records to subs debug format 2021-08-18 14:48:30 +02:00
Joshua Hoeflich
1b04ad0535 Merge branch 'trunk' into NumBytesTo 2021-08-14 20:41:33 -05:00
Joshua Hoeflich
5115a004ed Type shenanigans work 2021-08-14 18:50:55 -05:00
Richard Feldman
bb7726b0e0
Merge branch 'trunk' into store-bool-closure-as-unit 2021-08-14 16:47:42 -04:00
Folkert
db877c7395 debug impl for the new Subs 2021-08-14 15:54:37 +02:00
Folkert
4cbb1c9b25 optimize initial tag union creation 2021-08-13 23:53:27 +02:00
Folkert
26da66d73f remove from_mutmap 2021-08-13 15:42:43 +02:00
Richard Feldman
0f42da7b7b
Merge pull request #1510 from rtfeldman/alias-nominal-equality
Alias nominal equality
2021-08-13 08:50:38 -04:00
Folkert
24ddc4b1e8 further optimizations 2021-08-13 13:25:36 +02:00
Folkert de Vries
3ac646f2a6
Merge branch 'trunk' into soa-alias 2021-08-13 13:13:42 +02:00
Folkert
df83bf0d48 Merge remote-tracking branch 'origin/soa-alias' into alias-nominal-equality 2021-08-13 12:11:36 +02:00
Folkert
c9040c012e make things work 2021-08-13 11:04:31 +02:00
Folkert
67182baa81 add new AliasVariables type 2021-08-13 10:07:58 +02:00
Richard Feldman
bf38493d65 Make is_empty const 2021-08-12 21:39:57 -04:00
Folkert
c8007201b0 shrink FlatType further 2021-08-12 23:13:32 +02:00
Folkert
42f04fcc77 use variablesubsslice for Apply 2021-08-12 22:49:56 +02:00
Folkert
c058368a6d optimize tag union type -> layout conversion 2021-08-12 21:32:23 +02:00
Folkert
3bbf1a5506 use UnionTags for recursive tag unions 2021-08-12 20:50:33 +02:00
Folkert
e86cc22024 add empty variable slice at index 0 2021-08-12 19:35:33 +02:00
Folkert
0643efa571 clippy 2021-08-11 22:04:43 +02:00
Folkert
1d32be0818 all tests pass 2021-08-11 21:59:23 +02:00
Folkert
6c0860b6bf milestone all but one gen tests passing 2021-08-11 21:50:11 +02:00
Folkert
56b699fcf3 add iterator helpers 2021-08-11 20:35:36 +02:00
Folkert
fd3ccaeabe add helper functions 2021-08-11 20:35:02 +02:00
Folkert
903ac405a3 short_circuit_help 2021-08-11 20:24:10 +02:00
Folkert
823824c62d add index for variables slice 2021-08-11 20:11:50 +02:00
Folkert
4386d3d5f4 add write_ext_content 2021-08-11 20:10:22 +02:00
Folkert
83ad331bb1 remove chase_record_ext_var 2021-08-07 15:35:57 +02:00
Folkert
7a44572ebc make occurs return Result to use the ? operator 2021-08-07 13:56:16 +02:00
Folkert
ad3d006a11 use a SubsIndex instead of Box 2021-08-07 13:50:53 +02:00
Folkert
dd73428dc1 UnionTags 2021-08-07 13:26:52 +02:00
Folkert
fe773995c8 make VariableSubsSlice 2021-08-07 13:12:39 +02:00
Folkert
c09acb255c also sort by stack size 2021-08-07 13:08:55 +02:00
Folkert
524bde64d0 cleanup and comments 2021-08-07 01:31:40 +02:00