Commit graph

104 commits

Author SHA1 Message Date
ayazhafiz
e03592930f Typecheck numeric literals with suffixes in expressions
Part of #2350
2022-02-01 22:49:50 -05:00
ayazhafiz
4e942b3e5d Make nested datatypes into errors
I was hoping to add nested datatypes into the language, but it turns out
doing so is quite tricky and not all that useful with Roc's current
compilation model. Basically every implementation strategy I could think
of ended up requiring a uniform representation for the data layout
(or some ugly workaround). Furhermore it increased the complexity of the
checker/mono IR generator a little bit - basically, we must always pass
around the alias definitions of nested datatypes and instantiate them
at usage sites, rather than being able to unroll aliases as we currently
do during canonicalization.

So, especially because we don't support polymorphic recursion anyway, I
think it may be better to simply disallow any kind of nested datatypes
in the language. In any case, Stephanie Weirich [seems to think nested
datatypes are not needed](https://www.cis.upenn.edu/~plclub/blog/2020-12-04-nested-datatypes/).

Closes #2293
2022-01-31 22:58:01 -05:00
Richard Feldman
02263dbf42
Report hosted module parse errors 2022-01-30 20:40:50 -05:00
Richard Feldman
121e387f5a
Make some errors more specific 2022-01-30 20:40:50 -05:00
Folkert
8aae60ddda fix reporting tests 2022-01-25 10:25:05 +01:00
Mats Sigge
71f359fbdc Move macros from roc_reporting to new roc_error_macros module
The `internal_error!` and `user_error!´ macros can't be used everywhere
when they live in `roc_reporting` due to circular dependencies.
2022-01-23 18:40:04 +01:00
ayazhafiz
48a3e871e8 Report self-recursive aliases at their declaration site, not in usages
Closes #2380
2022-01-22 14:26:32 -05:00
ayazhafiz
5058e3cfc4 Fix panic during reporting
Closes #2326
2022-01-12 22:02:51 -05:00
Joshua Warner
f22f96843e Refactor ParseProblem
* Remove the `pos` field, which was always being assigned Position::default()
* Remove one use of this `pos`, by removing the never-used SyntaxError::ConditionFailed variant
* Adjust the other use to do what was probably intended - which is to say, pointing to the beginning of the def with the error
* Rename to FileError, reuse `SourceError` as an inner field, to avoid duplicating the `bytes`
2022-01-03 20:10:50 -08:00
Joshua Warner
650c29de3c Change LineColumn::column to u32 to avoid overflow, and remove LineTooLong error 2022-01-02 21:50:42 -08:00
Joshua Warner
cb8cf44596 fmt 2022-01-01 18:20:05 -08:00
Joshua Warner
70156b0a90 Simplify advancing 2022-01-01 18:20:05 -08:00
Joshua Warner
4b04ec6bbc Add Position::offset, and recompute line/column info based on source 2022-01-01 18:20:05 -08:00
Joshua Warner
443d738f9b Make Position::{line, column} fields private 2022-01-01 18:20:05 -08:00
Joshua Warner
82d2be0635 Introduce LineColumnRegion and force conversion 2022-01-01 18:20:05 -08:00
ayazhafiz
dae94f4aaa Improve error message 2021-12-26 08:51:35 -06:00
ayazhafiz
3b209b1164 Report type alias issues 2021-12-26 08:44:10 -06:00
Joshua Warner
8b58d5cbc7 Switch to always encoding package names / paths as strings
This will simplify parsing and make it possible to have a uniform lexer for the language. Previously unquoted package names were allowed to include '-'s, which aren't valid identifiers.

In the future, we'll distinguish local paths from packages in the package-manager by looking for a ".roc" suffix, which should only be present in local paths.
2021-12-23 20:11:14 -08:00
Joshua Warner
22e2545fd6 format 2021-12-22 20:46:42 -08:00
Joshua Warner
4d7070ce3b Always combine line,column into Position 2021-12-22 20:32:46 -08:00
Joshua Warner
f19220473a Rename Located -> Loc 2021-12-22 19:18:22 -08:00
Joshua Warner
96e8916594 Refactor BadOperator to take a &str rather than &[u8] 2021-12-18 14:42:48 -08:00
Chelsea Troy
f680ee3c24 Fix a spelling mistake; how was this ever passing? 2021-12-01 18:41:37 -06:00
Chelsea Troy
2eefe9ff6d cargo fmt 2021-12-01 18:38:51 -06:00
Chelsea Troy
0e5f82526a Account for SingleQuote in the case statements for the cli, plus some errata
+ Evidently I failed to finish fixing merge conflicts
+ Some of the types that the SingleQuote code mentioned didn't exist according to the build step. I looked around and switched them out for types it LOOKED like they were supposed to be, but someone should probably check this
+ Don't make commits like this; it's multiple unrelated changes thrown together. I'm still figuring out my way around here
2021-12-01 00:13:15 -06:00
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
a8e38172ac Remove redundant refs 2021-11-25 11:22:19 -05:00
ayazhafiz
7f6a8cbaea Improve wildcard collision error message from Richard's review 2021-11-25 11:16:18 -05:00
ayazhafiz
3b7596dd34 Remove redundant clones 2021-11-25 11:16:18 -05:00
ayazhafiz
3f3a34382c Suggest non-conflicting type variable name for wildcard renaming
There is still a potential for conflicts here, because we don't look at
type variables introduced _prior_ to this annotation. However, this
should be okay in most cases.
2021-11-25 11:16:18 -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
8726e38dad Improve error message when nested wildcards are connected
We now push analysis of when two wildcards are associated with each
other to the time when we try to give tips for a diff between types. Two
wildcards always have a diff, since they are associated with different
types.
2021-11-25 11:15:31 -05:00
ayazhafiz
817bb22f9e Improve error message when we try to unify two wildcards
Closes #1931
2021-11-25 11:15:31 -05:00
ayazhafiz
8f1878bc42 Print type annotation in all type errors related to annotations 2021-11-25 11:15:31 -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
ayazhafiz
7a0ecbd262 Fix grammar issue in rigids type annotation tip 2021-11-25 11:15:31 -05:00
ayazhafiz
d47c52c422 Fix grammar in comment 2021-11-25 11:15:31 -05:00
Folkert de Vries
816e390e36
Merge pull request #2057 from rtfeldman/reporting-cfg-windows
Use cfg to check if we're compiling for windows (in reporting)
2021-11-24 13:29:48 +01:00
Folkert
8ce195998a clean up comment 2021-11-23 20:05:11 +01:00
Folkert
e4ffe804ec remove lowercases from errortype alias 2021-11-22 20:26:50 +01:00
Folkert
2c20d79cb8 actually check if we're compiling (the compiler) for windows 2021-11-22 12:52:23 +01:00
Brendan Hansknecht
8e834fba07 add error macros to roc_reporting 2021-11-20 18:49:33 -08:00
Folkert de Vries
71233fcfc1
Merge pull request #2012 from rtfeldman/i/1714
Take syntactic sugar into account when reporting errors
2021-11-19 10:26:24 +01:00
ayazhafiz
a985204d5c Simplify error message for string interpolation-related type mismatch 2021-11-18 21:32:07 -05:00
ayazhafiz
5bfc52cd3b Remove Sugar enum and inline single variant into CalledVia 2021-11-18 21:23:41 -05:00
ayazhafiz
4ef40be0f0 Remove unused variable refs 2021-11-18 20:20:33 -05:00
ayazhafiz
8b7217847d Rename additional stale roc_module::operator refs and format 2021-11-18 20:20:33 -05:00
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