aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJimmi Holst Christensen <jimmiholstchristensen@gmail.com>2018-04-28 17:17:48 +0200
committerJimmi Holst Christensen <jimmiholstchristensen@gmail.com>2018-04-28 17:17:48 +0200
commitfba0347ec43fb5c06b5ac9bec541b740d95194fe (patch)
treeebf1c2a12012ee94efb7e8363dd759b5ac7ab284 /src
parent2fc34eaa581cc31827e978fbd973bf36d2c647e2 (diff)
downloadzig-fba0347ec43fb5c06b5ac9bec541b740d95194fe.tar.gz
zig-fba0347ec43fb5c06b5ac9bec541b740d95194fe.zip
.ReturnType and @ArgType now emits errors on unresolved types
related: #846
Diffstat (limited to 'src')
-rw-r--r--src/ir.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index d8156b214e..641b8fc30c 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -13859,6 +13859,15 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
}
} else if (child_type->id == TypeTableEntryIdFn) {
if (buf_eql_str(field_name, "ReturnType")) {
+ if (child_type->data.fn.fn_type_id.return_type == nullptr) {
+ // Return type can only ever be null, if the function is generic
+ assert(child_type->data.fn.is_generic);
+
+ ir_add_error(ira, &field_ptr_instruction->base,
+ buf_sprintf("ReturnType has not been resolved because '%s' is generic", buf_ptr(&child_type->name)));
+ return ira->codegen->builtin_types.entry_invalid;
+ }
+
bool ptr_is_const = true;
bool ptr_is_volatile = false;
return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
@@ -17860,6 +17869,16 @@ static TypeTableEntry *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruc
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
out_val->data.x_type = fn_type_id->param_info[arg_index].type;
+ if (out_val->data.x_type == nullptr) {
+ // Args are only unresolved if our function is generic.
+ assert(fn_type->data.fn.is_generic);
+
+ ir_add_error(ira, arg_index_inst,
+ buf_sprintf("@ArgType could not resolve the type of arg %" ZIG_PRI_usize " because '%s' is generic",
+ arg_index, buf_ptr(&fn_type->name)));
+ return ira->codegen->builtin_types.entry_invalid;
+ }
+
return ira->codegen->builtin_types.entry_type;
}