fix crash when error evaluating target of for expr

closes #153
master
Andrew Kelley 2016-05-16 22:51:08 -07:00
parent 3df9389215
commit 2c710382a8
2 changed files with 12 additions and 1 deletions

View File

@ -3953,7 +3953,7 @@ static TypeTableEntry *analyze_for_expr(CodeGen *g, ImportTableEntry *import, Bl
} }
TypeTableEntry *var_type; TypeTableEntry *var_type;
if (node->data.for_expr.elem_is_ptr) { if (child_type->id != TypeTableEntryIdInvalid && node->data.for_expr.elem_is_ptr) {
var_type = get_pointer_to_type(g, child_type, false); var_type = get_pointer_to_type(g, child_type, false);
} else { } else {
var_type = child_type; var_type = child_type;

View File

@ -1395,6 +1395,17 @@ fn something() -> %void { }
pub fn main(args: [][]u8) { } pub fn main(args: [][]u8) { }
)SOURCE", 1, ".tmp_source.zig:2:27: error: expected return type of main to be '%void', instead is 'void'"); )SOURCE", 1, ".tmp_source.zig:2:27: error: expected return type of main to be '%void', instead is 'void'");
add_compile_fail_case("invalid pointer for var type", R"SOURCE(
extern fn ext() -> isize;
var bytes: [ext()]u8 = undefined;
fn f() {
for (bytes) |*b, i| {
*b = u8(i);
}
}
)SOURCE", 1, ".tmp_source.zig:3:13: error: unable to evaluate constant expression");
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////