lang: ast, gapi, interfaces, parser: Print line numbers on error

This adds an initial implementation of printing line numbers on type
unification errors. It also attempts to print a visual position
indicator for most scenarios.

This patch was started by Felix Frank and finished by James Shubin.

Co-authored-by: Felix Frank <Felix.Frank.de@gmail.com>
This commit is contained in:
James Shubin
2025-02-25 20:15:02 -05:00
parent f754bbbf90
commit d7ecc72b41
20 changed files with 714 additions and 172 deletions

View File

@@ -39,8 +39,12 @@ import (
// solution. Those two types are symmetrical in that it doesn't matter which is
// used where, it only affects how we print out error messages.
type UnificationInvariant struct { // formerly the SamInvariant
// Expr is the expression we are determining the type for. This improves
// our error messages.
// Node is the AST node holding the expression. This improves our error
// messages.
Node Node
// Expr is the expression we are determining the type for. This is what
// we are unifying. This improves our error messages.
Expr Expr
// Expect is one of the two types to unify.
@@ -65,6 +69,7 @@ func GenericCheck(obj Expr, typ *types.Type) ([]*UnificationInvariant, error) {
invar := &UnificationInvariant{
Expr: obj,
Node: obj,
Expect: typ, // sam says not backwards
Actual: actual,
}