fix: three foundation/el root-cause bugs (no more bandaids)

1. Parser+codegen: bare reassignment `x = expr` inside an if-body
   was compiling to three orphan expressions with no store. Now
   emits a real assignment.

2. Runtime json_get: dot-path segments that are all digits now
   correctly traverse array indices. `json_get(s, "0.field")` works.

3. Runtime HTTP writer: response bodies starting with
   `{"__status__":<int>,...}` now set the HTTP status header to
   that value and strip the marker from the served body. Existing
   404/401/503 paths in product code now produce real status codes
   instead of HTTP 200 with the status hidden in the body.

Self-host fixed point holds: gen2 == gen3 byte-identical.
Snapshot tagged at dist/platform/elc.20260502-1231-self-host.

Backlog: bl-c121edda
This commit is contained in:
Will Anderson
2026-05-02 12:32:23 -05:00
parent 1274bcde35
commit 742bd0b4f9
8 changed files with 332 additions and 30 deletions
+33
View File
@@ -0,0 +1,33 @@
// http-status-envelope.el acceptance test for the __status__ HTTP envelope.
//
// Before fix: a handler returning {"__status__":401,"error":"unauthorized"}
// went out as an HTTP 200 with the JSON body verbatim, so Cloud Run logs were
// full of 200s for what should have been 4xx/5xx.
//
// After fix: when the response body's FIRST key is __status__, the runtime
// reads the integer value as the HTTP status code and strips the marker from
// the body before sending it to the client.
//
// Verify with curl:
// curl -i http://localhost:8081/auth -> HTTP/1.1 401 Unauthorized
// curl -i http://localhost:8081/health -> HTTP/1.1 200 OK
// curl -i http://localhost:8081/oops -> HTTP/1.1 503 Service Unavailable
fn handle(method: String, path: String, body: String) -> String {
if path == "/auth" {
return "{\"__status__\":401,\"error\":\"unauthorized\"}"
}
if path == "/oops" {
return "{\"__status__\":503,\"error\":\"degraded\"}"
}
if path == "/health" {
return "{\"ok\":true}"
}
return "{\"__status__\":404,\"error\":\"not found\"}"
}
fn main() -> Int {
http_set_handler("handle")
http_serve(8081, "handle")
return 0
}
+21
View File
@@ -0,0 +1,21 @@
// json-array-traversal.el acceptance test for json_get dot-path with array
// indices.
//
// Before fix: json_get("...", "0.field") would substring-search for a literal
// key named `"0.field"` and find nothing, returning "".
//
// After fix: dot-path segments that are all digits are treated as array
// indices and the walker descends into the array.
fn test_array_traversal() -> String {
let s: String = "[{\"name\":\"alice\"},{\"name\":\"bob\"}]"
let a: String = json_get(s, "0.name")
let b: String = json_get(s, "1.name")
return a + "," + b
}
fn main() -> Int {
let r: String = test_array_traversal()
print(r)
return 0
}
+22
View File
@@ -0,0 +1,22 @@
// reassign-in-if.el acceptance test for bare reassignment inside if-body.
//
// Before fix: parser dropped `x = "override"` on the floor and codegen emitted
// three orphan expressions (`x; EL_NULL; EL_STR("override");`). Effective store
// was lost, so the function returned "default".
//
// After fix: parse_stmt recognises `Ident "=" Expr` as an Assign statement and
// codegen emits a real C assignment, so the function returns "override".
fn test_reassign() -> String {
let x: String = "default"
if true {
x = "override"
}
return x
}
fn main() -> Int {
let r: String = test_reassign()
print(r)
return 0
}