moshell icon indicating copy to clipboard operation
moshell copied to clipboard

Point to declarations in diagnostics

Open syldium opened this issue 2 years ago • 0 comments

Diagnostics are contextualized errors, that point the relevant code spans.

Observation::here is important, probably as important as giving where the declaration happened. When an immutable variable is reassigned twice for instance, it would be nice to point that the variable definition may be changed by replacing the val keyword for var.

Giving this help might not always be useful when defined in an external library, so the focus here would be to expand the error context by indicating where the symbol is declared.

Function parameters are already mapped to their span in the source code, this issue will require doing the same when collecting the symbols. This could be stored in the Variables struct, populated through the Environment struct during the collection phase.

The diagnostics can then be updated:

val constant = 0
constant = 1 // Immutable variable assigned twice
constant() // Invoking non function type

fun foo() = {}
foo($constant) // Incorrect parameter count

syldium avatar Aug 13 '23 13:08 syldium