Skip to content

Commit

Permalink
fix crash when calling comptime-known undefined function ptr
Browse files Browse the repository at this point in the history
closes #880
closes #1212
  • Loading branch information
andrewrk committed Jul 10, 2018
1 parent b5cfbfd commit 28f9230
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ir.cpp
Expand Up @@ -13271,6 +13271,8 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
return ir_finish_anal(ira, cast_instruction->value.type);
} else if (fn_ref->value.type->id == TypeTableEntryIdFn) {
FnTableEntry *fn_table_entry = ir_resolve_fn(ira, fn_ref);
if (fn_table_entry == nullptr)
return ira->codegen->builtin_types.entry_invalid;
return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
fn_ref, nullptr, is_comptime, call_instruction->fn_inline);
} else if (fn_ref->value.type->id == TypeTableEntryIdBoundFn) {
Expand Down
13 changes: 13 additions & 0 deletions test/compile_errors.zig
@@ -1,6 +1,19 @@
const tests = @import("tests.zig");

pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"use of comptime-known undefined function value",
\\const Cmd = struct {
\\ exec: fn () void,
\\};
\\export fn entry() void {
\\ const command = Cmd{ .exec = undefined };
\\ command.exec();
\\}
,
".tmp_source.zig:6:12: error: use of undefined value",
);

cases.add(
"bad @alignCast at comptime",
\\comptime {
Expand Down

0 comments on commit 28f9230

Please sign in to comment.