aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorJosh Wolfe <thejoshwolfe@gmail.com>2015-12-03 12:38:28 -0700
committerJosh Wolfe <thejoshwolfe@gmail.com>2015-12-03 12:38:28 -0700
commit09a78d6235957001e6b92ea9a83899b18a394ac1 (patch)
tree2bb859e10b8892d2e3b24db38e3995f42e39fe96 /src/analyze.cpp
parent90565a5109116f0c689215d28ea14d3f4d046c81 (diff)
downloadzig-09a78d6235957001e6b92ea9a83899b18a394ac1.tar.gz
zig-09a78d6235957001e6b92ea9a83899b18a394ac1.zip
can't declare unreachable variables
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index be2a181713..3bad09a4d9 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -421,9 +421,17 @@ static TypeTableEntry * analyze_expression(CodeGen *g, ImportTableEntry *import,
TypeTableEntry *explicit_type = variable_declaration->type != nullptr ?
resolve_type(g, variable_declaration->type) : nullptr;
+ if (explicit_type == g->builtin_types.entry_unreachable) {
+ add_node_error(g, variable_declaration->type,
+ buf_sprintf("variable of type 'unreachable' is not allowed."));
+ }
TypeTableEntry *implicit_type = variable_declaration->expr != nullptr ?
analyze_expression(g, import, context, explicit_type, variable_declaration->expr) : nullptr;
+ if (implicit_type == g->builtin_types.entry_unreachable) {
+ add_node_error(g, node,
+ buf_sprintf("variable initialization is unreachable."));
+ }
if (implicit_type == nullptr) {
add_node_error(g, node, buf_sprintf("initial values are required for variable declaration."));
@@ -715,6 +723,11 @@ static void analyze_top_level_declaration(CodeGen *g, ImportTableEntry *import,
assert(param_decl->type->type == NodeTypeType);
TypeTableEntry *type = param_decl->type->codegen_node->data.type_node.entry;
+ if (type == g->builtin_types.entry_unreachable) {
+ add_node_error(g, param_decl->type,
+ buf_sprintf("parameter of type 'unreachable' is not allowed."));
+ }
+
LocalVariableTableEntry *variable_entry = allocate<LocalVariableTableEntry>(1);
buf_init_from_buf(&variable_entry->name, &param_decl->name);
variable_entry->type = type;