From 81e79161151912c86c6892bf8d4349360826c971 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Mon, 16 Mar 2020 18:53:19 -0400 Subject: made #sizeof only take a type --- test.toc | 12 ++++++++++-- types.c | 14 +++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/test.toc b/test.toc index 03f7ae6..a525e75 100644 --- a/test.toc +++ b/test.toc @@ -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 diff --git a/types.c b/types.c index 0ec2a26..712c8d8 100644 --- a/types.c +++ b/types.c @@ -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 -- cgit v1.2.3