commit 385d8cfb02dce6140657c980dd0f69c19a86daf5
parent 082cd4adc1cc382e9258f293c3e5f5ae3a040e96
Author: Drew DeVault <sir@cmpwn.com>
Date: Tue, 4 May 2021 12:18:38 -0400
hare::types: fix struct size
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
2 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/hare/types/+test.ha b/hare/types/+test.ha
@@ -42,6 +42,7 @@ fn parse_type(in: str) ast::_type = {
let atype = parse_type("struct { x: int, y: int }");
defer ast::type_free(atype);
let htype = lookup(st, &atype)!;
+ assert(htype.sz == 8);
let stype = htype._type as _struct;
assert(stype.kind == struct_union::STRUCT);
assert(len(stype.fields) == 2);
diff --git a/hare/types/store.ha b/hare/types/store.ha
@@ -192,6 +192,7 @@ fn fromast(store: *typestore, atype: *ast::_type) (_type | deferred | error) = {
},
st: ast::struct_type => {
let st = struct_from_ast(store, st, false)?;
+ sz = 0;
for (let i = 0z; i < len(st.fields); i += 1) {
const field = st.fields[i];
if (field.offs + field._type.sz > sz) {
@@ -205,6 +206,7 @@ fn fromast(store: *typestore, atype: *ast::_type) (_type | deferred | error) = {
},
un: ast::union_type => {
let st = struct_from_ast(store, un, true)?;
+ sz = 0;
for (let i = 0z; i < len(st.fields); i += 1) {
const field = st.fields[i];
if (field.offs + field._type.sz > sz) {