Commit Graph

691 Commits

Author SHA1 Message Date
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
Lucas
168196f903 Merge pull request #210 from aiken-lang/fix-if-expressions 2022-12-22 12:46:24 -05:00
KtorZ
1f15c2ca20 Sort import alphabetically when formatting.
Fixes #211.
2022-12-22 18:00:25 +01:00
rvcas
c723f4f796 feat: redo the new command 2022-12-22 10:52:49 -05: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
rvcas
9028424a96 feat: rename Nil to Unit 2022-12-21 17:27:20 -05:00
rvcas
9df5005820 feat: add IData and BData builtins 2022-12-21 14:39:46 -05:00
rvcas
429126e38f feat: add trace 2022-12-21 14:39:46 -05:00
KtorZ
9068c89c00 Show trace logs as part of the test output when any.
```
  ┍━ test ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  │ PASS [mem: 6370, cpu: 2591822] trace_1
  │ ↳ is negative
  │ ↳ is non-negative
  ┕━━━━━━━━━ 1 tests | 1 passed | 0 failed
  ```
2022-12-21 14:39:46 -05:00
KtorZ
2fc14c7c1f Make box-drawing code more reusable
- Move it to 'pretty' module.
  - Have function work on colored strings titles and contents
2022-12-21 14:39:46 -05:00
KtorZ
f26737ecb4 Remove the 'trace/try' keyword, use builtin.trace
I am not entirely sure what the intent was for that keyword, but
  nothing really matched between the parser, the formatter and the uplc
  code gen. I don't think there's any need for a keyword here, trace is
  already readily available from the builtins.
2022-12-21 14:39:46 -05:00
KtorZ
2aad1794a1 make dependencies optional in Aiken's manifest. 2022-12-21 14:32:40 +01:00
Matthias Benkort
e6f4b378e1 Merge pull request #146 from aiken-lang/micah/file-errors
Raise more descriptive errors when the `aiken.toml` manifest is missing.
2022-12-21 11:05:02 +01:00
Micah Kendall
bd816615d7 Display more descriptive error on missing manifest
Before:

  ```
  ❯ aiken check
  Error:
    × No such file or directory (os error 2)
  ```

  After:

  ```
  ❯ aiken check
  Error:
    × Missing 'aiken.toml' manifest in /Users/ktorz/Documents/Projects/aiken-lang/aiken
    help: Try running `aiken new <REPOSITORY/PROJECT>` to initialise a project with an example manifest.
  ```

  Co-authored-by: KtorZ <matthias.benkort@gmail.com>
2022-12-21 10:10:17 +01:00
KtorZ
28c907d9de Fix acceptance 021: allow registering type aliases in any order.
This is the most intuitive thing I could come up with: since the
  problem is mainly due to the order in which we try declaring the
  aliases, then it suffices to simply try as much as we can, and retry
  on failure until there's no more failure.

  Note that it's important to detect cycles if we do such thing (which
  we can by noticing that a given iteration didn't make any progress).

  It works pretty well in the end and even allow us to define a new kind
  of type error should there be a cyclic definition.
2022-12-21 09:43:37 +01:00
KtorZ
a3591cc7dc Fix 'aiken new', now require project name in specific format. 2022-12-21 00:19:24 +01:00
rvcas
796ac28044 feat: change the printing a little 2022-12-20 16:32:31 -05:00
rvcas
e34cbc8e7e feat: compile deps 2022-12-20 16:32:31 -05:00
rvcas
b06bf610b7 feat: dep downloading now works 2022-12-20 16:32:31 -05:00
rvcas
6a0b1ce5c3 feat: start trying to use deps 2022-12-20 16:32:31 -05:00
rvcas
5bd2a9336c feat: tons of boilerplate for fetching packages 2022-12-20 16:32:31 -05:00
rvcas
a6fd8f92a8 feat(deps): start laying out some types and functions 2022-12-20 16:32:31 -05:00
rvcas
b3266fb837 chore: clippy warnings 2022-12-20 16:32:31 -05:00
Kasey White
ac14512706 feat: fix nil equals nil, and fix funcs with discard params 2022-12-20 15:40:01 -05:00
Kasey White
9177267570 feat: test 24 passes
fixed issue with is_tuple in types
minor monomorphize change
2022-12-20 15:40:01 -05:00
Kasey White
17603e8cca checkpoint 2022-12-20 15:40:01 -05:00
Kasey White
43ff66cd01 all tests pass besides todo in 13, couple changes
Use more cost efficient recurse
Monomorphize needed to deal with function arg return types
bytearray variant added for variant names
2022-12-19 00:41:27 -05:00
KtorZ
b6556e6739 Rework 'new' to not generate needless boilerplate
Instead, prints out a README with useful informations.
2022-12-19 00:41:27 -05:00
Kasey White
421e7148d0 zero arg functions now work: test 15 2022-12-19 00:41:27 -05:00
Kasey White
3a765ddef5 add better todo 2022-12-19 00:41:27 -05:00
KtorZ
529b3e87ff Rename builtin as 'verify_ed25519_signature'
It's best to keep builtin as-close-as possible to their standard name
  because they're hard to document. We can then leverage the prelude and
  the standard lib for convenient names.
2022-12-19 00:41:27 -05:00
KtorZ
44d72c046e Print files / tests as they're processed when --debug
This is because there's no proper way to catch panics in Rust, which
  makes it hard to know _which_ test did cause the panic when this
  happen. The stack trace gives little detail about this, but we can
  print this information before it happens -- making it easier to
  identify the culprit.
2022-12-19 00:41:27 -05:00
Kasey White
eb386f4606 feat: Add nil support for test 19 2022-12-19 00:41:27 -05:00
Kasey White
5b908aaeb7 fix: fieldsexpose getting wrong generic id and not replacing type 2022-12-19 00:41:27 -05:00
Kasey White
47fae21af7 minor fix to monomorphize 2022-12-19 00:41:27 -05:00
Kasey White
2bce818110 chore: fix list insertion order, function insertion order,
and Inner function issues with variant
2022-12-19 00:41:27 -05:00