wcc: Hare-style struct embedding (anon + bare-name)
Struct members can be `struct { ... }` (anonymous nested) or a bare
named type, in addition to `name: type`. The inner struct's fields
are promoted to the outer scope with offsets shifted by the embed
base; codegen already keys off Tfield.offset so cgen needs no change.
Errors on non-struct embed or name collision.
This commit is contained in:
@@ -344,6 +344,20 @@ static const struct row rows[] = {
|
||||
" os.assert(r == 42, \"sum mismatch\\n\");\n"
|
||||
" return r: i32;\n"
|
||||
"};", 42 },
|
||||
/* Hare-style struct embedding: bare-name embed + anonymous
|
||||
* nested struct, fields promoted to the outer scope. Both
|
||||
* field-by-field assignment and flat struct-literal init must
|
||||
* see promoted fields. */
|
||||
{ "type point = struct { x: i32, y: i32 };\n"
|
||||
"type vec = struct {\n"
|
||||
" point,\n"
|
||||
" struct { z: i32 },\n"
|
||||
" w: i32,\n"
|
||||
"};\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let v: vec = vec { x = 1, y = 2, z = 3, w = 36 };\n"
|
||||
" return v.x + v.y + v.z + v.w;\n"
|
||||
"};", 42 },
|
||||
/* 3-field tuple destructure in for-range */
|
||||
{ "fn main() i32 = {\n"
|
||||
" let buf: [3]i64;\n"
|
||||
|
||||
Reference in New Issue
Block a user