Commit d8da34c64c

Andrew Kelley <superjoe30@gmail.com>
2017-01-31 08:30:10
fix crash when assigning too large value to integer
closes #228
1 parent d2b94af
Changed files (2)
src/ir.cpp
@@ -7591,6 +7591,11 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
     var->value.type = result_type;
     assert(var->value.type);
 
+    if (result_type->id == TypeTableEntryIdInvalid) {
+        decl_var_instruction->base.other = &decl_var_instruction->base;
+        return ira->codegen->builtin_types.entry_void;
+    }
+
     bool is_comptime = ir_get_var_is_comptime(var);
 
     if (casted_init_value->value.special != ConstValSpecialRuntime) {
test/run_tests.cpp
@@ -1656,6 +1656,12 @@ fn bar() -> i32 {
 }
     )SOURCE", 1, ".tmp_source.zig:11:9: error: parameter of type '(integer literal)' requires comptime");
 
+    add_compile_fail_case("assign too big number to u16", R"SOURCE(
+fn foo() {
+    var vga_mem: u16 = 0xB8000;
+}
+    )SOURCE", 1, ".tmp_source.zig:3:24: error: integer value 753664 cannot be implicitly casted to type 'u16'");
+
 }
 
 //////////////////////////////////////////////////////////////////////////////