Commit Graph

795 Commits

Author SHA1 Message Date
Kasey White
3514e66234 Fix to variant name creation for dependencies.
Last few changes to go Tuple Index,
Assert, Check, not

change test 35 to produce intended functionality
2022-12-30 14:01:11 -05:00
Kasey White
b0ea187151 better data deserialization errors and test hint
now runs even being in a sequence
2022-12-30 14:01:11 -05:00
Kasey White
34d398ab3b fix dependencies ordering so now test 34 passes 2022-12-29 17:14:23 -05:00
Kasey White
306fa891a0 validator params are now converted to type from data 2022-12-29 17:14:23 -05:00
KtorZ
85a6a711e1 Add more colors to error messages.
And, let 'formatdoc' insert newlines when relevant to
  format the text to the same column length.
2022-12-29 17:38:34 +01:00
KtorZ
3139c85fe8 Support declaring bytearray literals as base16 strings. 2022-12-29 13:08:58 +01:00
KtorZ
1701cacb52 Add builtin functions to the prelude
Starting with 'not', will add 'always' and 'identity' later.
2022-12-29 12:05:30 +01:00
Kasey White
cce76bbd63 fix issue with constructor clauses and clause props 2022-12-28 18:00:11 -05:00
KtorZ
c4c0ace3a6 Align warnings message's style with errors. 2022-12-28 18:45:04 +01:00
KtorZ
7c1b8e8f3b Map remaining relevant builtins. 2022-12-28 18:27:28 +01:00
KtorZ
f2e716dd86 Fix else/if formatter. 2022-12-28 17:55:11 +01:00
KtorZ
bae8267f18 Fix formatter for unary operation
Was wrongly converting any unary operation into '!'
2022-12-28 17:51:00 +01:00
Kasey White
722117bfc4 one minor scope fix 2022-12-27 22:33:09 -05:00
Kasey White
551d4eea93 fix test 28 2022-12-27 22:33:09 -05:00
Kasey White
010024fb95 fix: acceptance test 031
Co-authored-by: rvcas <x@rvcas.dev>
2022-12-27 22:33:09 -05:00
Kasey White
083b7fcb5f feat: support negation of int
* add unary op
* parse, typecheck, and code gen it
* express boolean not as unary op as well, previously called negate

Co-authored-by: rvcas <x@rvcas.dev>
2022-12-27 20:39:03 -05:00
Kasey White
542e39f093 feat: finish up zero arg issues with dependencies 2022-12-27 19:35:08 -05:00
Kasey White
30487cc232 fix test 23 2022-12-27 19:35:08 -05:00
Kasey White
919ea6c723 tuple destructuring nested and not now works 2022-12-27 19:35:08 -05:00
Kasey White
a08c615da4 checkpoint 2022-12-27 19:35:08 -05:00
Kasey White
b7d506a8db nested lists now work 2022-12-27 19:35:08 -05:00
Kasey White
6126ee4cb4 checkpoint 2022-12-27 19:35:08 -05:00
rvcas
38a716d94e feat: allow error to hold a label 2022-12-23 15:52:44 -05:00
rvcas
37196a29ee feat: error keyword 2022-12-23 15:52:44 -05:00
KtorZ
7b9ea5dabb Add links to the user-manual to errors, when applicable. 2022-12-23 19:50:14 +01:00
KtorZ
69f060e675 Rework all errors to provide better help text. 2022-12-23 19:27:06 +01:00
KtorZ
c47c50ffb8 Show most type-checking error on a single line; reads better. 2022-12-23 00:25:18 +01:00
KtorZ
ce0c6e0d0f Use smart-constructor for UnexpectedLabeledArg errors.
Reduce duplications and keep the formatting of the error inside the error module.
2022-12-23 00:24:57 +01:00
KtorZ
dca633da48 Refactor 'UnknownVariable' and 'UnknownTypeConstructor' as smart-constructor. 2022-12-23 00:09:07 +01:00
KtorZ
aa2a235790 Suggest possible candidate on unknown imports.
## Before

  ```
  × Type-checking
  ╰─▶ Unknown module field 'ValidityRaneg' in module 'aiken/transaction'
  ```

  ## After

  ```
    × Type-checking
    ╰─▶ Unknown import 'ValidityRaneg' from module 'aiken/transaction'

     ╭─[../stdlib/validators/tmp.ak:2:1]
   2 │ use aiken/interval.{Interval, IntervalBound, IntervalBoundType}
   3 │ use aiken/transaction.{ScriptContext, ValidityRaneg}
     ·                                       ─────────────
   4 │
     ╰────
    help: Did you mean to import 'ValidityRange'?
  ```
2022-12-22 23:46:17 +01:00
KtorZ
70b1ec4324 Add function to calculate lenvenshtein distance of two strings
Will be useful to make import or usage suggestions.
2022-12-22 23:44:15 +01:00
KtorZ
666761efef Make 'UnexpectedLabelArg' errors more helpful
## Before

  ```
   × Checking
   ╰─▶ Unexpected labeled argument

       t

     ╭─[/Users/mati/Devel/OpenSource/time_lock_aiken/validators/time_lock.ak:13:1]
  13 │   let now = when context.transaction.validity_range.lower_bound.bound_type is {
  14 │     Finite { t } -> t
     ·              ─
  15 │     NegativeInfinity -> 0
     ╰────
  ```

  ## After

  ```
    × Type-checking
    ╰─▶ Unexpected labeled argument 't'

      ╭─[../stdlib/validators/tmp.ak:10:1]
   10 │   let now = when context.transaction.validity_range.lower_bound.bound_type is {
   11 │     interval.Finite { t } -> t
      ·                       ─
   12 │     interval.NegativeInfinity -> 0
      ╰────
    help: The constructor 'Finite' does not have any labeled field. Its fields
          must therefore be matched only by position.

          Perhaps, try the following:

          ╰─▶  interval.Finite(t)
  ```
2022-12-22 21:45:49 +01:00
KtorZ
0682781460 Better errors when using unknown data-type constructor.
## Before

  ```
    × Checking
    ╰─▶ Unknown variable

            Finite

      ╭─[../stdlib/validators/tmp.ak:10:1]
   10 │   let now = when context.transaction.validity_range.lower_bound.bound_type is {
   11 │     Finite { t } -> t
      ·     ────────────
   12 │     NegativeInfinity -> 0
      ╰────
  ```

  ## After

  ```
    × Type-checking
    ╰─▶ Unknown data-type constructor 'Finite'

      ╭─[../stdlib/validators/tmp.ak:10:1]
   10 │   let now = when context.transaction.validity_range.lower_bound.bound_type is {
   11 │     Finite { t } -> t
      ·     ────────────
   12 │     NegativeInfinity -> 0
      ╰────
    help: Did you forget to import it?

          Data-type constructors are not automatically imported, even if their type is
          imported. So, if a module `aiken/pet` defines the following type:

           ┍━ aiken/pet.ak ━━━━━━━━
           │ pub type Pet {
           │   Cat
           │   Dog
           │ }

          You must import its constructors explicitly to use them, or prefix them
          with the module's name.

           ┍━ foo.ak ━━━━━━━━
           │ use aiken/pet.{Pet, Dog}
           │
           │ fn foo(pet : Pet) {
           │   when pet is {
           │     pet.Cat -> // ...
           │     Dog -> // ...
           │   }
           │ }
  ```
2022-12-22 19:34:50 +01:00
KtorZ
2aa4429231 Rename Unit -> Void 2022-12-22 18:52:28 +01:00
KtorZ
5cf9742e5e Move tuple-index hint as diagnostic's help 2022-12-22 18:52:28 +01:00
KtorZ
1f15c2ca20 Sort import alphabetically when formatting.
Fixes #211.
2022-12-22 18:00:25 +01:00
KtorZ
1ca705005d Fix formatting of if-expressions
Fixes #129.
2022-12-22 16:51:23 +01:00
Matthias Benkort
a129a8a0d3 Merge pull request #208 from aiken-lang/tuple-when2
fix todo and list and tuple not equal operator
2022-12-22 10:28:06 +01:00
KtorZ
7ad8babf17 Rename ArgName::{Discard,NamedLabeled} as ArgName::{Discarded,Named}
Now that the other variants are gone, this is clearer.
2022-12-22 09:36:44 +01:00
KtorZ
8ab05509b1 Remove Named & DiscardLabeled, now unused
And unify everything into either 'Discard' or 'NamedLabeled'
2022-12-22 09:36:44 +01:00
KtorZ
bf7cdfba73 Implement parser & type-checker for tuple indexes.
```aiken
  fn foo() {
    let tuple = #(1, 2, 3, 4)
    tuple.1st + tuple.2nd + tuple.3rd + tuple.4th
  }
  ```
2022-12-22 09:14:23 +01:00
Kasey White
b1dec1259d fix todo and list and tuple not equal comparator 2022-12-22 01:09:06 -05:00
rvcas
7867793bcd feat: on fmt if label and name are the same only print one 2022-12-21 19:17:15 -05:00
rvcas
4c4e454ea3 feat: all function args are now labeled implicitly 2022-12-21 19:17:15 -05:00
rvcas
42204d2d71 chore: make folder names match crate name 2022-12-21 18:11:07 -05:00