fix(types): check nested closure/function bodies and cast targets (issue 0064)
Closes the two residual silent holes in the unknown-type diagnostic: - Nested closure / function bodies. The body walk stopped at closure and nested-fn boundaries, so a typo'd type in a closure's local annotation silently became a 0-field struct. `walkBodyTypes` now descends control flow and expressions to re-enter each closure / nested fn via `checkScope`, which accumulates that scope's generic + value-`Type` params onto the parent's — so an inner closure still sees the outer function's `$T` (no false positive) while a genuine unknown is flagged at any nesting depth. `harvestScopeDecls` collects type-decl names across the whole body (including nested scopes) up front so locals are never false-flagged. - Cast targets. `cast(T)` where `T` is a value-`Type` param (no `$`) cast to a fabricated empty struct silently; it now gets the tailored `$T` hint. An unknown *literal* cast target already errors via value resolution, so it's left to that path — no double diagnostic. Suite: 350 passed, 0 failed. Regressions: examples/1114 (nested-closure annotation), 1115 (cast value param).
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
// An unknown type in a NESTED closure body's local annotation is rejected,
|
||||
// with the enclosing function's generic params still in scope. Previously the
|
||||
// body walk stopped at closure / nested-function boundaries, so a typo'd type
|
||||
// inside a closure slipped through and silently became a 0-field struct.
|
||||
// Regression (issue 0064, nested scopes). Expected: error at the annotation; exit 1.
|
||||
main :: () -> s32 {
|
||||
f := closure(() -> s32 {
|
||||
bad: Coordnate = ---;
|
||||
return 0;
|
||||
});
|
||||
return f();
|
||||
}
|
||||
12
examples/1115-diagnostics-cast-value-param-rejected.sx
Normal file
12
examples/1115-diagnostics-cast-value-param-rejected.sx
Normal file
@@ -0,0 +1,12 @@
|
||||
// `cast(T)` where `T` is a value parameter declared `: Type` (without the `$`
|
||||
// generic sigil) is rejected with the generic-param hint. Previously it
|
||||
// silently cast to a fabricated empty struct (an unknown *literal* cast target
|
||||
// already errored via value resolution, but the value-param case was silent).
|
||||
// Regression (issue 0064, cast position). Expected: tailored error; exit 1.
|
||||
conv :: (T: Type, x: s32) -> s32 {
|
||||
return cast(T) x;
|
||||
}
|
||||
|
||||
main :: () -> s32 {
|
||||
return conv(s32, 5);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,5 @@
|
||||
error: unknown type 'Coordnate'
|
||||
--> /Users/agra/projects/sx/examples/1114-diagnostics-unknown-type-nested-closure-rejected.sx:8:14
|
||||
|
|
||||
8 | bad: Coordnate = ---;
|
||||
| ^^^^^^^^^
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,5 @@
|
||||
error: 'T' is a value parameter, not a type; introduce a generic type parameter with `$T: Type`
|
||||
--> /Users/agra/projects/sx/examples/1115-diagnostics-cast-value-param-rejected.sx:7:17
|
||||
|
|
||||
7 | return cast(T) x;
|
||||
| ^
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user