diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-03-16 18:53:19 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-03-16 18:53:19 -0400 |
commit | 81e79161151912c86c6892bf8d4349360826c971 (patch) | |
tree | 1a85cd60fb1f8883e441feb0a27dc180f2b895f6 | |
parent | 47ffc86ede157409dd04f2cc6e569efd47240a4e (diff) |
made #sizeof only take a type
-rw-r--r-- | test.toc | 12 | ||||
-rw-r--r-- | types.c | 14 |
2 files changed, 17 insertions, 9 deletions
@@ -1,5 +1,13 @@ #include "std/io.toc", io; +Point3D ::= struct { + x, y, z: f32; +} + main ::= fn() { - for i := 0..10 { 3; }; -}
\ No newline at end of file + p: Point3D; + io.puti(#sizeof(Point3D)); + // io.puti(#sizeof(p)); + io.puti(#sizeof(typeof p)); +} +main();
\ No newline at end of file @@ -2604,14 +2604,14 @@ static Status types_expr(Typer *tr, Expression *e) { case UNARY_DSIZEOF: case UNARY_DALIGNOF: { Type *queried_type; - if (type_is_builtin(&of->type, BUILTIN_TYPE)) { - Value val; - if (!eval_expr(tr->evalr, of, &val)) - return false; - queried_type = val.type; - } else { - queried_type = &of->type; + if (!type_is_builtin(&of->type, BUILTIN_TYPE)) { + err_print(e->where, "Argument of #sizeof or #alignof must be a Type. Did you mean #sizeof(typeof ...)?"); + return false; } + Value val; + if (!eval_expr(tr->evalr, of, &val)) + return false; + queried_type = val.type; if (e->unary.op == UNARY_DSIZEOF) e->val.i64 = (I64)compiler_sizeof(queried_type); else |