IR: don't crash if number literal used with pure error

This commit is contained in:
Andrew Kelley 2016-12-10 18:43:28 -05:00
parent 6feae8a4e9
commit 3cfbec3eef

View File

@ -3206,7 +3206,15 @@ static TypeTableEntry *ir_determine_peer_types(IrAnalyze *ira, AstNode *source_n
}
}
if (any_are_pure_error && prev_inst->type_entry->id != TypeTableEntryIdPureError) {
return get_error_type(ira->codegen, prev_inst->type_entry);
if (prev_inst->type_entry->id == TypeTableEntryIdNumLitInt ||
prev_inst->type_entry->id == TypeTableEntryIdNumLitFloat)
{
add_node_error(ira->codegen, source_node,
buf_sprintf("unable to make error union out of number literal"));
return ira->codegen->builtin_types.entry_invalid;
} else {
return get_error_type(ira->codegen, prev_inst->type_entry);
}
} else {
return prev_inst->type_entry;
}