commit e8a199fb00221e1037076d667ac016892a436c9c
parent cc7a7b79602d530c8362e0fc4c24cb118666f1d2
Author: Eyal Sawady <ecs@d2evs.net>
Date: Sat, 4 Sep 2021 04:49:03 +0000
Fix bugs caught by match exhaustivity test
Signed-off-by: Eyal Sawady <ecs@d2evs.net>
Diffstat:
3 files changed, 28 insertions(+), 16 deletions(-)
diff --git a/hare/ast/decl.ha b/hare/ast/decl.ha
@@ -82,4 +82,12 @@ export fn decl_free(d: decl) void = match (d.decl) {
type_free(f.prototype);
if (f.body is expr) expr_free(f.body as expr);
},
+ c: []decl_const => {
+ for (let i = 0z; i < len(c); i += 1) {
+ ident_free(c[i].ident);
+ type_free(c[i]._type);
+ expr_free(c[i].init);
+ };
+ free(c);
+ },
};
diff --git a/hare/ast/expr.ha b/hare/ast/expr.ha
@@ -463,21 +463,7 @@ export fn expr_free(e: (expr | nullable *expr)) void = match (e) {
};
free(a.values);
},
- s: struct_constant => {
- ident_free(s.alias);
- for (let i = 0z; i < len(s.fields); i += 1) {
- match (s.fields[i]) {
- v: struct_value => {
- free(v.name);
- type_free(v._type);
- expr_free(v.init);
- },
- c: *struct_constant =>
- expr_free(c: *expr),
- };
- };
- free(s.fields);
- },
+ s: struct_constant => struct_constant_free(s),
t: tuple_constant => {
for (let i = 0z; i < len(t); i += 1) {
expr_free(t[i]);
@@ -549,3 +535,21 @@ export fn expr_free(e: (expr | nullable *expr)) void = match (e) {
},
},
};
+
+fn struct_constant_free(s: struct_constant) void = {
+ ident_free(s.alias);
+ for (let i = 0z; i < len(s.fields); i += 1) {
+ match (s.fields[i]) {
+ v: struct_value => {
+ free(v.name);
+ type_free(v._type);
+ expr_free(v.init);
+ },
+ c: *struct_constant => {
+ struct_constant_free(*c);
+ free(c);
+ },
+ };
+ };
+ free(s.fields);
+};
diff --git a/os/exec/cmd.ha b/os/exec/cmd.ha
@@ -113,7 +113,7 @@ fn lookup(name: str) (platform_cmd | void) = {
let path = strings::concat(item, "/", name);
defer free(path);
match (open(path)) {
- err: errors::opaque => continue,
+ err: error => continue,
p: platform_cmd => return p,
};
};