summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-03-16 18:53:19 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2020-03-16 18:53:19 -0400
commit81e79161151912c86c6892bf8d4349360826c971 (patch)
tree1a85cd60fb1f8883e441feb0a27dc180f2b895f6
parent47ffc86ede157409dd04f2cc6e569efd47240a4e (diff)
made #sizeof only take a type
-rw-r--r--test.toc12
-rw-r--r--types.c14
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