diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-02-07 20:05:15 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-02-07 20:05:15 -0500 |
commit | d64fa6da5b83e770bc4877655b70982d74c37a42 (patch) | |
tree | 0c64caab0806b61a9992c30eef5e3542762ae57b | |
parent | d81bd17093ecda178bae3281cfe79180fc21a416 (diff) |
added warning for expression statements with compile only types
-rw-r--r-- | main.c | 5 | ||||
-rw-r--r-- | test.toc | 20 | ||||
-rw-r--r-- | types.c | 16 |
3 files changed, 17 insertions, 24 deletions
@@ -18,10 +18,7 @@ /* TODO: -check for leaks ---- -warn about non-anonymous namespace statements of expression with compile-only types (e.g. int;) -allow for circular dependencies in functions returning types---this will be complicated +struct parameters - to allow circular dependencies in types foo, _ := bar(); nice syntax for #including something into a namespace run stuff at compile time without assigning it to a constant @@ -2,19 +2,7 @@ io ::= nms { #include "std/io.toc"; }; -n ::= nms { - #export x := 1; - #export counter ::= fn() int { x += 1; x }; -}; - - -#export main ::= fn() { - a := n.counter(); - b := n.counter(); - n.counter(); - c := n.counter(); - io.puts("Hello!"); - io.puti(a); - io.puti(b); - io.puti(c); -}; +main ::= fn() { + io.puts("Hello"); + int; +};
\ No newline at end of file @@ -2422,10 +2422,18 @@ static bool types_stmt(Typer *tr, Statement *s) { if (!types_expr(tr, &s->expr)) { return false; } - - if (s->expr.kind == EXPR_TUPLE && !(s->flags & STMT_EXPR_NO_SEMICOLON)) { - err_print(s->where, "Statement of a tuple is not allowed. Use a semicolon instead of a comma here."); - return false; + + if (!(s->flags & STMT_EXPR_NO_SEMICOLON)) { + if (s->expr.kind == EXPR_TUPLE) { + err_print(s->where, "Statement of a tuple is not allowed. Use a semicolon instead of a comma here."); + return false; + } + Type *t = &s->expr.type; + if (type_is_compileonly(t)) { + char *str = type_to_str(t); + warn_print(s->where, "This expression has a compile-only type (%s), so this statement will not actually be outputted in C code.", str); + free(str); + } } break; case STMT_DECL: |