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

@@ -12,4 +12,4 @@ class c1($a, $b []str) {
}
}
-- OUTPUT --
# err: errUnify: unify error with: str("hello"): type error: list != str
# err: errUnify: type error: list != str: /main.mcl @ 4:1-4:25

View File

@@ -15,4 +15,4 @@ test ["x",] {
float32 => $b,
}
-- OUTPUT --
# err: errUnify: unify error with: topLevel(func() { <built-in:_operator> }): type error: int != float
# err: errUnify: type error: int != float: /main.mcl @ 10:6-10:22

View File

@@ -2,4 +2,4 @@
import "fmt"
test fmt.printf("%d%d", 42) {} # should not pass, missing second int
-- OUTPUT --
# err: errUnify: unify error with: call:fmt.printf(str("%d%d"), int(42)): type error: str != list
# err: errUnify: type error: str != list: /main.mcl @ 2:1-2:30

View File

@@ -3,4 +3,4 @@ test "t1" {
stringptr => 42, # int, not str
}
-- OUTPUT --
# err: errUnify: unify error with: int(42): type error: str != int
# err: errUnify: type error: str != int: /main.mcl @ 2:2-2:17

View File

@@ -7,4 +7,4 @@ test "test" {}
Test["${name}"] -> Test["test"] # must fail
-- OUTPUT --
# err: errUnify: unify error with: var(name): type error: str != list
# err: errUnify: type error: str != list: /main.mcl @ 6:1-6:15

View File

@@ -7,4 +7,4 @@ test "test" {}
Test["test"] -> Test["${name}"] # must fail
-- OUTPUT --
# err: errUnify: unify error with: var(name): type error: str != list
# err: errUnify: type error: str != list: /main.mcl @ 6:17-6:31

View File

@@ -5,4 +5,4 @@ $name = ["a", "bb", "ccc",]
test "${name}" {} # must fail
-- OUTPUT --
# err: errUnify: unify error with: var(name): type error: str != list
# err: errUnify: type error: str != list: /main.mcl @ 4:1-4:17