aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/analyze.cpp4
-rw-r--r--src/codegen.cpp10
2 files changed, 7 insertions, 7 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index b55c5251e4..a626649323 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -454,8 +454,8 @@ static TypeTableEntry * analyze_expression(CodeGen *g, ImportTableEntry *import,
buf_sprintf("variable initialization is unreachable"));
}
- if (implicit_type == nullptr) {
- add_node_error(g, node, buf_sprintf("initial values are required for variable declaration"));
+ if (implicit_type == nullptr && variable_declaration->is_const) {
+ add_node_error(g, node, buf_sprintf("variables must have initial values or be declared 'mut'."));
}
TypeTableEntry *type = explicit_type != nullptr ? explicit_type : implicit_type;
diff --git a/src/codegen.cpp b/src/codegen.cpp
index be4d695279..e1a5525e37 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -526,14 +526,14 @@ static LLVMValueRef gen_expr(CodeGen *g, AstNode *node) {
variable->value_ref = gen_expr(g, node->data.variable_declaration.expr);
return nullptr;
} else {
+ LLVMValueRef value;
if (node->data.variable_declaration.expr) {
- LLVMValueRef value = gen_expr(g, node->data.variable_declaration.expr);
-
- add_debug_source_node(g, node);
- return LLVMBuildStore(g->builder, value, variable->value_ref);
+ value = gen_expr(g, node->data.variable_declaration.expr);
} else {
-
+ value = LLVMConstNull(variable->type->type_ref);
}
+ add_debug_source_node(g, node);
+ return LLVMBuildStore(g->builder, value, variable->value_ref);
}
}
case NodeTypeCastExpr: