From 9d6666f333cd427a720c639ee0b9b513d79fe8a0 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 14 Dec 2018 21:58:12 +0000 Subject: [PATCH] Disallow casting between `cstring` and `[]u8` --- src/check_expr.cpp | 6 +++--- src/parser.cpp | 14 ++++++++++++-- src/parser.hpp | 2 ++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 37a54854c..1e487fb00 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -1926,11 +1926,11 @@ bool check_is_castable_to(CheckerContext *c, Operand *operand, Type *y) { return true; } - // []byte/[]u8 <-> string - if (is_type_u8_slice(src) && is_type_string(dst)) { + // []byte/[]u8 <-> string (not cstring) + if (is_type_u8_slice(src) && (is_type_string(dst) && !is_type_cstring(dst))) { return true; } - if (is_type_string(src) && is_type_u8_slice(dst)) { + if ((is_type_string(src) && !is_type_cstring(src)) && is_type_u8_slice(dst)) { // if (is_type_typed(src)) { return true; // } diff --git a/src/parser.cpp b/src/parser.cpp index dc1a22780..f42cfaa32 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1686,7 +1686,14 @@ Ast *parse_operand(AstFile *f, bool lhs) { operand = ast_bad_expr(f, token, f->curr_token); } warning(token, "#run is not yet implemented"); - } else if (name.string == "file") { return ast_basic_directive(f, token, name.string); + } /* else if (name.string == "no_deferred") { + operand = parse_expr(f, false); + if (unparen_expr(operand)->kind != Ast_CallExpr) { + syntax_error(operand, "#no_deferred can only be applied to procedure calls"); + operand = ast_bad_expr(f, token, f->curr_token); + } + operand->stmt_state_flags |= StmtStateFlag_no_deferred; + } */ else if (name.string == "file") { return ast_basic_directive(f, token, name.string); } else if (name.string == "line") { return ast_basic_directive(f, token, name.string); } else if (name.string == "procedure") { return ast_basic_directive(f, token, name.string); } else if (name.string == "caller_location") { return ast_basic_directive(f, token, name.string); @@ -3887,7 +3894,10 @@ Ast *parse_stmt(AstFile *f) { } else if (tag == "assert") { Ast *t = ast_basic_directive(f, hash_token, tag); return ast_expr_stmt(f, parse_call_expr(f, t)); - } + } /* else if (name.string == "no_deferred") { + s = parse_stmt(f); + s->stmt_state_flags |= StmtStateFlag_no_deferred; + } */ if (tag == "include") { syntax_error(token, "#include is not a valid import declaration kind. Did you mean 'import'?"); diff --git a/src/parser.hpp b/src/parser.hpp index 8ed521823..f48e230ff 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -173,6 +173,8 @@ enum ProcCallingConvention { enum StmtStateFlag { StmtStateFlag_bounds_check = 1<<0, StmtStateFlag_no_bounds_check = 1<<1, + + StmtStateFlag_no_deferred = 1<<5, }; enum FieldFlag {