Improve error messages around PI and other numbers with unknown units (#7457)

* Improve docs around PI

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Refactor and polish type error messages

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Add suggestion to fix unknown numbers error

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Don't warn so often about unknown units

Signed-off-by: Nick Cameron <nrc@ncameron.org>

---------

Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
Nick Cameron
2025-06-13 02:20:04 +12:00
committed by GitHub
parent bf87c23ea8
commit 1443f3ab39
21 changed files with 308 additions and 251 deletions

View File

@ -4,8 +4,8 @@ description: Error from executing argument_error.kcl
---
KCL Semantic error
× semantic: f requires a value with type `fn(any): any`, but found array of
│ number(default units), number(default units) with 2 values
× semantic: f requires a value with type `fn(any): any`, but found an array
of `number`, `number` (with type `[any; 2]`).
╭─[5:1]
4 │
5 │ map(f, f = [0, 1])
@ -15,8 +15,8 @@ KCL Semantic error
╰────
╰─▶ KCL Semantic error
× semantic: f requires a value with type `fn(any): any`, but found
│ array of number(default units), number(default units) with 2 values
× semantic: f requires a value with type `fn(any): any`, but found an
│ array of `number`, `number` (with type `[any; 2]`).
╭─[5:12]
4 │
5 │ map(f, f = [0, 1])

View File

@ -4,8 +4,8 @@ description: Error from executing array_elem_pop_empty_fail.kcl
---
KCL Semantic error
× semantic: The input argument of `pop` requires a value with type `[any;
│ 1+]`, but found [any; 0]
× semantic: The input argument of `pop` requires one or more values (`[any;
│ 1+]`), but found an empty array (with type `[any; 0]`).
╭─[2:8]
1 │ arr = []
2 │ fail = pop(arr)
@ -15,8 +15,8 @@ KCL Semantic error
╰────
╰─▶ KCL Semantic error
× semantic: The input argument of `pop` requires a value with type
│ `[any; 1+]`, but found [any; 0]
× semantic: The input argument of `pop` requires one or more values
(`[any; 1+]`), but found an empty array (with type `[any; 0]`).
╭─[2:12]
1 │ arr = []
2 │ fail = pop(arr)

View File

@ -4,7 +4,7 @@ description: Error from executing comparisons_multiple.kcl
---
KCL Semantic error
× semantic: Expected a number, but found bool
× semantic: Expected a number, but found a boolean (`true` or `false`)
╭────
1 │ assert(3 == 3 == 3, error = "this should not compile")
· ───┬──

View File

@ -5,7 +5,8 @@ description: Error from executing error_inside_fn_also_has_source_range_of_call_
KCL Semantic error
× semantic: The input argument of `startSketchOn` requires a value with type
│ `Solid | Plane`, but found string
│ `Solid` or a value with type `Plane` (`Solid | Plane`), but found a value
│ with type `string`.
╭─[3:9]
2 │ fn someNestedFunction(@something2) {
3 │ startSketchOn(something2)
@ -26,7 +27,8 @@ KCL Semantic error
├─▶ KCL Semantic error
× semantic: The input argument of `startSketchOn` requires a value
│ │ with type `Solid | Plane`, but found string
│ │ with type `Solid` or a value with type `Plane` (`Solid | Plane`),
│ │ but found a value with type `string`.
│ ╭─[3:23]
│ 2 │ fn someNestedFunction(@something2) {
│ 3 │ startSketchOn(something2)
@ -38,7 +40,8 @@ KCL Semantic error
├─▶ KCL Semantic error
× semantic: The input argument of `startSketchOn` requires a value
│ │ with type `Solid | Plane`, but found string
│ │ with type `Solid` or a value with type `Plane` (`Solid | Plane`),
│ │ but found a value with type `string`.
│ ╭─[3:9]
│ 2 │ fn someNestedFunction(@something2) {
│ 3 │ startSketchOn(something2)
@ -50,7 +53,8 @@ KCL Semantic error
╰─▶ KCL Semantic error
× semantic: The input argument of `startSketchOn` requires a value
│ with type `Solid | Plane`, but found string
│ with type `Solid` or a value with type `Plane` (`Solid | Plane`),
│ but found a value with type `string`.
╭─[6:5]
5 │
6 │ someNestedFunction(something)

View File

@ -4,8 +4,7 @@ description: Error from executing invalid_member_object.kcl
---
KCL Semantic error
× semantic: Only arrays can be indexed, but you're trying to index a
│ number(default units)
× semantic: Only arrays can be indexed, but you're trying to index a number
╭─[2:5]
1 │ num = 999
2 │ x = num[3]