| ... | ... | @@ -173,7 +173,7 @@ static TypeTableEntry *resolve_type(CodeGen *g, AstNode *node) { |
| 173 | 173 | resolve_type(g, node->data.type.child_type); |
| 174 | 174 | TypeTableEntry *child_type = node->data.type.child_type->codegen_node->data.type_node.entry; |
| 175 | 175 | assert(child_type); |
| 176 | | if (child_type == g->builtin_types.entry_unreachable) { |
| 176 | if (child_type->id == TypeTableEntryIdUnreachable) { |
| 177 | 177 | add_node_error(g, node, |
| 178 | 178 | buf_create_from_str("pointer to unreachable not allowed")); |
| 179 | 179 | } else if (child_type->id == TypeTableEntryIdInvalid) { |
| ... | ... | @@ -186,7 +186,7 @@ static TypeTableEntry *resolve_type(CodeGen *g, AstNode *node) { |
| 186 | 186 | { |
| 187 | 187 | resolve_type(g, node->data.type.child_type); |
| 188 | 188 | TypeTableEntry *child_type = node->data.type.child_type->codegen_node->data.type_node.entry; |
| 189 | | if (child_type == g->builtin_types.entry_unreachable) { |
| 189 | if (child_type->id == TypeTableEntryIdUnreachable) { |
| 190 | 190 | add_node_error(g, node, |
| 191 | 191 | buf_create_from_str("array of unreachable not allowed")); |
| 192 | 192 | } |
| ... | ... | @@ -240,10 +240,10 @@ static void resolve_function_proto(CodeGen *g, AstNode *node, FnTableEntry *fn_t |
| 240 | 240 | AstNode *child = node->data.fn_proto.params.at(i); |
| 241 | 241 | assert(child->type == NodeTypeParamDecl); |
| 242 | 242 | TypeTableEntry *type_entry = resolve_type(g, child->data.param_decl.type); |
| 243 | | if (type_entry == g->builtin_types.entry_unreachable) { |
| 243 | if (type_entry->id == TypeTableEntryIdUnreachable) { |
| 244 | 244 | add_node_error(g, child->data.param_decl.type, |
| 245 | 245 | buf_sprintf("parameter of type 'unreachable' not allowed")); |
| 246 | | } else if (type_entry == g->builtin_types.entry_void) { |
| 246 | } else if (type_entry->id == TypeTableEntryIdVoid) { |
| 247 | 247 | if (node->data.fn_proto.visib_mod == FnProtoVisibModExport) { |
| 248 | 248 | add_node_error(g, child->data.param_decl.type, |
| 249 | 249 | buf_sprintf("parameter of type 'void' not allowed on exported functions")); |
| ... | ... | @@ -570,9 +570,9 @@ static void check_type_compatibility(CodeGen *g, AstNode *node, |
| 570 | 570 | return; // anything will do |
| 571 | 571 | if (expected_type == actual_type) |
| 572 | 572 | return; // match |
| 573 | | if (expected_type == g->builtin_types.entry_invalid || actual_type == g->builtin_types.entry_invalid) |
| 573 | if (expected_type->id == TypeTableEntryIdInvalid || actual_type->id == TypeTableEntryIdInvalid) |
| 574 | 574 | return; // already complained |
| 575 | | if (actual_type == g->builtin_types.entry_unreachable) |
| 575 | if (actual_type->id == TypeTableEntryIdUnreachable) |
| 576 | 576 | return; // sorry toots; gotta run. good luck with that expected type. |
| 577 | 577 | |
| 578 | 578 | add_node_error(g, node, |
| ... | ... | @@ -815,11 +815,11 @@ static TypeTableEntry * analyze_expression(CodeGen *g, ImportTableEntry *import, |
| 815 | 815 | if (child->type == NodeTypeLabel) { |
| 816 | 816 | LabelTableEntry *label_entry = child->codegen_node->data.label_entry; |
| 817 | 817 | assert(label_entry); |
| 818 | | label_entry->entered_from_fallthrough = (return_type != g->builtin_types.entry_unreachable); |
| 818 | label_entry->entered_from_fallthrough = (return_type->id != TypeTableEntryIdUnreachable); |
| 819 | 819 | return_type = g->builtin_types.entry_void; |
| 820 | 820 | continue; |
| 821 | 821 | } |
| 822 | | if (return_type == g->builtin_types.entry_unreachable) { |
| 822 | if (return_type->id == TypeTableEntryIdUnreachable) { |
| 823 | 823 | if (child->type == NodeTypeVoid) { |
| 824 | 824 | // {unreachable;void;void} is allowed. |
| 825 | 825 | // ignore void statements once we enter unreachable land. |
| ... | ... | @@ -843,7 +843,7 @@ static TypeTableEntry * analyze_expression(CodeGen *g, ImportTableEntry *import, |
| 843 | 843 | actual_return_type = g->builtin_types.entry_void; |
| 844 | 844 | } |
| 845 | 845 | |
| 846 | | if (actual_return_type == g->builtin_types.entry_unreachable) { |
| 846 | if (actual_return_type->id == TypeTableEntryIdUnreachable) { |
| 847 | 847 | // "return exit(0)" should just be "exit(0)". |
| 848 | 848 | add_node_error(g, node, buf_sprintf("returning is unreachable")); |
| 849 | 849 | actual_return_type = g->builtin_types.entry_invalid; |
| ... | ... | @@ -857,18 +857,22 @@ static TypeTableEntry * analyze_expression(CodeGen *g, ImportTableEntry *import, |
| 857 | 857 | { |
| 858 | 858 | AstNodeVariableDeclaration *variable_declaration = &node->data.variable_declaration;; |
| 859 | 859 | |
| 860 | | TypeTableEntry *explicit_type = variable_declaration->type != nullptr ? |
| 861 | | resolve_type(g, variable_declaration->type) : nullptr; |
| 862 | | if (explicit_type == g->builtin_types.entry_unreachable) { |
| 863 | | add_node_error(g, variable_declaration->type, |
| 864 | | buf_sprintf("variable of type 'unreachable' not allowed")); |
| 860 | TypeTableEntry *explicit_type = nullptr; |
| 861 | if (variable_declaration->type != nullptr) { |
| 862 | explicit_type = resolve_type(g, variable_declaration->type); |
| 863 | if (explicit_type->id == TypeTableEntryIdUnreachable) { |
| 864 | add_node_error(g, variable_declaration->type, |
| 865 | buf_sprintf("variable of type 'unreachable' not allowed")); |
| 866 | } |
| 865 | 867 | } |
| 866 | 868 | |
| 867 | | TypeTableEntry *implicit_type = variable_declaration->expr != nullptr ? |
| 868 | | analyze_expression(g, import, context, explicit_type, variable_declaration->expr) : nullptr; |
| 869 | | if (implicit_type == g->builtin_types.entry_unreachable) { |
| 870 | | add_node_error(g, node, |
| 871 | | buf_sprintf("variable initialization is unreachable")); |
| 869 | TypeTableEntry *implicit_type = nullptr; |
| 870 | if (variable_declaration->expr != nullptr) { |
| 871 | implicit_type = analyze_expression(g, import, context, explicit_type, variable_declaration->expr); |
| 872 | if (implicit_type->id == TypeTableEntryIdUnreachable) { |
| 873 | add_node_error(g, node, |
| 874 | buf_sprintf("variable initialization is unreachable")); |
| 875 | } |
| 872 | 876 | } |
| 873 | 877 | |
| 874 | 878 | if (implicit_type == nullptr && variable_declaration->is_const) { |
| ... | ... | @@ -1185,7 +1189,7 @@ static TypeTableEntry * analyze_expression(CodeGen *g, ImportTableEntry *import, |
| 1185 | 1189 | |
| 1186 | 1190 | TypeTableEntry *primary_type; |
| 1187 | 1191 | TypeTableEntry *other_type; |
| 1188 | | if (then_type == g->builtin_types.entry_unreachable) { |
| 1192 | if (then_type->id == TypeTableEntryIdUnreachable) { |
| 1189 | 1193 | primary_type = else_type; |
| 1190 | 1194 | other_type = then_type; |
| 1191 | 1195 | } else { |