fmease / lushui

The reference compiler of the Lushui programming language
Apache License 2.0
5 stars 0 forks source link

Improve diagnostic when `of` is indented (as a continued section) and data constructors are not indented enough #114

Closed fmease closed 1 year ago

fmease commented 2 years ago

Given:

data X: Type
    of
    x: X

lushui currently outputs:

error[E012]: declaration `x` has no definition
 --> /home/fmease/programming/main_projects/lushui/x.lushui:3:9
  |
3 |     x: X
  |        ><
  |
 help: provide a definition with `=`

Which is entirely correct but it is confusing for newcomers. The correct code would be:

data X: Type
    of
        x: X

So, when we encounter a non-intrinsic function declaration without a body and the declaration above is a data declaration, add the following help message: indent the declaration to make it a data constructor for type Type (or something similar).

We don't need to check if the of is in a separate line, it's a fine suggestion even in a more general setting. Just make sure (smh!) that we are not in a delimited section (we don't store this in the AST right now though, that needs to change). Another implementation issue: In the lowerer, we cannot currently say give me the declaration above, we either need to add this information to the DeclarationContext or make use of indices (node indices) in the AST (c.f. #44).

fmease commented 1 year ago

We no longer have delimited sections