mirror of
https://github.com/ziglang/zig.git
synced 2026-02-03 13:13:40 +00:00
turn assertion into compile error for using var as return type
closes #758
This commit is contained in:
parent
eff3530dfa
commit
6b5cfd9d99
@ -1510,6 +1510,19 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
|
||||
}
|
||||
}
|
||||
|
||||
if (fn_proto->return_var_token != nullptr) {
|
||||
if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
|
||||
add_node_error(g, fn_proto->return_type,
|
||||
buf_sprintf("return type 'var' not allowed in function with calling convention '%s'",
|
||||
calling_convention_name(fn_type_id.cc)));
|
||||
return g->builtin_types.entry_invalid;
|
||||
}
|
||||
add_node_error(g, proto_node,
|
||||
buf_sprintf("TODO implement inferred return types https://github.com/zig-lang/zig/issues/447"));
|
||||
return g->builtin_types.entry_invalid;
|
||||
//return get_generic_fn_type(g, &fn_type_id);
|
||||
}
|
||||
|
||||
TypeTableEntry *specified_return_type = analyze_type_expr(g, child_scope, fn_proto->return_type);
|
||||
if (type_is_invalid(specified_return_type)) {
|
||||
fn_type_id.return_type = g->builtin_types.entry_invalid;
|
||||
@ -1523,16 +1536,6 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
|
||||
fn_type_id.return_type = specified_return_type;
|
||||
}
|
||||
|
||||
if (fn_proto->return_var_token != nullptr) {
|
||||
if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
|
||||
add_node_error(g, fn_proto->return_type,
|
||||
buf_sprintf("return type 'var' not allowed in function with calling convention '%s'",
|
||||
calling_convention_name(fn_type_id.cc)));
|
||||
return g->builtin_types.entry_invalid;
|
||||
}
|
||||
return get_generic_fn_type(g, &fn_type_id);
|
||||
}
|
||||
|
||||
if (!calling_convention_allows_zig_types(fn_type_id.cc) && !type_allowed_in_extern(g, fn_type_id.return_type)) {
|
||||
add_node_error(g, fn_proto->return_type,
|
||||
buf_sprintf("return type '%s' not allowed in function with calling convention '%s'",
|
||||
|
||||
@ -12019,7 +12019,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
|
||||
inst_fn_type_id.alignment = align_bytes;
|
||||
}
|
||||
|
||||
{
|
||||
if (fn_proto_node->data.fn_proto.return_var_token == nullptr) {
|
||||
AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
|
||||
TypeTableEntry *specified_return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node);
|
||||
if (type_is_invalid(specified_return_type))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user