diff options
| author | gingerBill <bill@gingerbill.org> | 2021-04-19 15:46:12 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-04-19 15:46:12 +0100 |
| commit | 36125696240469d0adcb78caa8093f581debdcb2 (patch) | |
| tree | ca7ca09a62651908213429a1a7cd45ea7c0c5faf /src/check_expr.cpp | |
| parent | c83d13d0cbbf204a045a379c74bffc4d5bcfb53c (diff) | |
Allow casting of `#optional_ok` call expressions
Diffstat (limited to 'src/check_expr.cpp')
| -rw-r--r-- | src/check_expr.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 953b32667..bf097580b 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -2231,6 +2231,26 @@ bool check_is_castable_to(CheckerContext *c, Operand *operand, Type *y) { return true; } + if (is_type_tuple(src)) { + Ast *expr = unparen_expr(operand->expr); + if (expr && expr->kind == Ast_CallExpr) { + // NOTE(bill, 2021-04-19): Allow casting procedure calls with #optional_ok + ast_node(ce, CallExpr, expr); + Type *pt = base_type(type_of_expr(ce->proc)); + if (pt->kind == Type_Proc && pt->Proc.optional_ok) { + if (pt->Proc.result_count > 0) { + Operand op = *operand; + op.type = pt->Proc.results->Tuple.variables[0]->type; + bool ok = check_is_castable_to(c, &op, y); + if (ok) { + ce->optional_ok_one = true; + } + return ok; + } + } + } + } + if (is_constant && is_type_untyped(src) && is_type_string(src)) { if (is_type_u8_array(dst)) { String s = operand->value.value_string; @@ -2346,6 +2366,7 @@ bool check_is_castable_to(CheckerContext *c, Operand *operand, Type *y) { if (is_type_rawptr(src) && is_type_proc(dst)) { return true; } + return false; } @@ -10598,7 +10619,7 @@ void check_not_tuple(CheckerContext *c, Operand *o) { if (o->type->kind == Type_Tuple) { isize count = o->type->Tuple.variables.count; error(o->expr, - "%td-valued tuple found where single value expected", count); + "%td-valued expression found where single value expected", count); o->mode = Addressing_Invalid; GB_ASSERT(count != 1); } |