From 44f38b04b0cc374fcd377df0fe68f29c824185ff Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 31 Jan 2018 11:13:39 -0500 Subject: fix assertion fail when using global var number literal closes #697 --- src/analyze.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/analyze.cpp') diff --git a/src/analyze.cpp b/src/analyze.cpp index 4fa8dad7ce..2812c9d79e 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -3295,6 +3295,10 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) { is_const, init_val, &tld_var->base); tld_var->var->linkage = linkage; + if (implicit_type != nullptr && type_is_invalid(implicit_type)) { + tld_var->var->value->type = g->builtin_types.entry_invalid; + } + if (var_decl->align_expr != nullptr) { if (!analyze_const_align(g, tld_var->base.parent_scope, var_decl->align_expr, &tld_var->var->align_bytes)) { tld_var->var->value->type = g->builtin_types.entry_invalid; -- cgit v1.2.3 From 0090c2d70b89cc6b5ab02bdc02aa49c4caf71a5a Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 7 Feb 2018 20:38:49 +0100 Subject: DRY 'is slice?' conditionals in parser (#750) --- src/analyze.cpp | 6 +----- src/ir.cpp | 8 ++------ 2 files changed, 3 insertions(+), 11 deletions(-) (limited to 'src/analyze.cpp') diff --git a/src/analyze.cpp b/src/analyze.cpp index 2812c9d79e..4c982c160c 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -3380,11 +3380,7 @@ bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry * } // slice const - if (expected_type->id == TypeTableEntryIdStruct && - actual_type->id == TypeTableEntryIdStruct && - expected_type->data.structure.is_slice && - actual_type->data.structure.is_slice) - { + if (is_slice(expected_type) && is_slice(actual_type)) { TypeTableEntry *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index].type_entry; TypeTableEntry *expected_ptr_type = expected_type->data.structure.fields[slice_ptr_index].type_entry; if ((!actual_ptr_type->data.pointer.is_const || expected_ptr_type->data.pointer.is_const) && diff --git a/src/ir.cpp b/src/ir.cpp index 1dc717286a..ae8ef00f2f 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -6369,10 +6369,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, } // implicit [N]T to []const T - if (expected_type->id == TypeTableEntryIdStruct && - expected_type->data.structure.is_slice && - actual_type->id == TypeTableEntryIdArray) - { + if (is_slice(expected_type) && actual_type->id == TypeTableEntryIdArray) { TypeTableEntry *ptr_type = expected_type->data.structure.fields[slice_ptr_index].type_entry; assert(ptr_type->id == TypeTableEntryIdPointer); @@ -6384,8 +6381,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, } // implicit &const [N]T to []const T - if (expected_type->id == TypeTableEntryIdStruct && - expected_type->data.structure.is_slice && + if (is_slice(expected_type) && actual_type->id == TypeTableEntryIdPointer && actual_type->data.pointer.is_const && actual_type->data.pointer.child_type->id == TypeTableEntryIdArray) -- cgit v1.2.3