mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-10 05:11:37 -07:00
Allow for optional ok for return
This commit is contained in:
+2
-1
@@ -3920,7 +3920,8 @@ bool check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize lhs_count,
|
||||
Operand ok = o;
|
||||
val.mode = Addressing_Value;
|
||||
ok.mode = Addressing_Value;
|
||||
ok.type = t_bool;
|
||||
// ok.type = t_bool;
|
||||
ok.type = t_untyped_bool;
|
||||
array_add(operands, val);
|
||||
array_add(operands, ok);
|
||||
|
||||
|
||||
+4
-2
@@ -1211,23 +1211,25 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
|
||||
Type *proc_type = ctx->curr_proc_sig;
|
||||
GB_ASSERT(proc_type != nullptr);
|
||||
GB_ASSERT(proc_type->kind == Type_Proc);
|
||||
// Type *proc_type = c->proc_stack[c->proc_stack.count-1];
|
||||
|
||||
TypeProc *pt = &proc_type->Proc;
|
||||
if (pt->diverging) {
|
||||
error(rs->token, "Diverging procedures may not return");
|
||||
break;
|
||||
}
|
||||
|
||||
Entity **result_entities = nullptr;
|
||||
isize result_count = 0;
|
||||
bool has_named_results = pt->has_named_results;
|
||||
if (pt->results) {
|
||||
result_entities = proc_type->Proc.results->Tuple.variables.data;
|
||||
result_count = proc_type->Proc.results->Tuple.variables.count;
|
||||
}
|
||||
|
||||
auto operands = array_make<Operand>(heap_allocator(), 0, 2*rs->results.count);
|
||||
defer (array_free(&operands));
|
||||
|
||||
check_unpack_arguments(ctx, nullptr, -1, &operands, rs->results, false);
|
||||
check_unpack_arguments(ctx, result_entities, result_count, &operands, rs->results, true);
|
||||
|
||||
if (result_count == 0 && rs->results.count > 0) {
|
||||
error(rs->results[0], "No return values expected");
|
||||
|
||||
@@ -1593,6 +1593,28 @@ Ast *convert_stmt_to_body(AstFile *f, Ast *stmt) {
|
||||
}
|
||||
|
||||
|
||||
void check_polymorphic_params_for_type(AstFile *f, Ast *polymorphic_params, Token token) {
|
||||
if (polymorphic_params == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (polymorphic_params->kind != Ast_FieldList) {
|
||||
return;
|
||||
}
|
||||
ast_node(fl, FieldList, polymorphic_params);
|
||||
for_array(fi, fl->list) {
|
||||
Ast *field = fl->list[fi];
|
||||
if (field->kind != Ast_Field) {
|
||||
continue;
|
||||
}
|
||||
for_array(i, field->Field.names) {
|
||||
Ast *name = field->Field.names[i];
|
||||
if (name->kind == Ast_PolyType) {
|
||||
error(name, "Polymorphic names are not needed for %.*s parameters", LIT(token.string));
|
||||
return; // TODO(bill): Err multiple times or just the once?
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ast *parse_operand(AstFile *f, bool lhs) {
|
||||
@@ -1855,6 +1877,7 @@ Ast *parse_operand(AstFile *f, bool lhs) {
|
||||
polymorphic_params = nullptr;
|
||||
}
|
||||
expect_token_after(f, Token_CloseParen, "parameter list");
|
||||
check_polymorphic_params_for_type(f, polymorphic_params, token);
|
||||
}
|
||||
|
||||
isize prev_level = f->expr_level;
|
||||
@@ -1921,6 +1944,7 @@ Ast *parse_operand(AstFile *f, bool lhs) {
|
||||
polymorphic_params = nullptr;
|
||||
}
|
||||
expect_token_after(f, Token_CloseParen, "parameter list");
|
||||
check_polymorphic_params_for_type(f, polymorphic_params, token);
|
||||
}
|
||||
|
||||
while (allow_token(f, Token_Hash)) {
|
||||
|
||||
Reference in New Issue
Block a user