From e6f26b9931af0b05b93447639fba7569691ac0d0 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 15 Dec 2019 09:48:05 +0000 Subject: [PATCH] Fix Unable to initialize a typeid field in a struct literal #501 --- src/check_expr.cpp | 7 +++---- src/ir.cpp | 4 +++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 81095db4a..fad3a4df0 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -7299,7 +7299,7 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type } fields_visited[sel.index[0]] = true; - check_expr_with_type_hint(c, o, fv->value, field->type); + check_expr_or_type(c, o, fv->value, field->type); if (is_type_any(field->type) || is_type_union(field->type) || is_type_raw_union(field->type)) { is_constant = false; @@ -7308,7 +7308,6 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type is_constant = o->mode == Addressing_Constant; } - check_assignment(c, o, field->type, str_lit("structure literal")); } } else { @@ -7334,9 +7333,9 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type field = t->Struct.fields[index]; } - check_expr_with_type_hint(c, o, elem, field->type); + check_expr_or_type(c, o, elem, field->type); - if (is_type_any(field->type) || is_type_union(field->type) || is_type_raw_union(field->type)) { + if (is_type_any(field->type) || is_type_union(field->type) || is_type_raw_union(field->type) || is_type_typeid(field->type)) { is_constant = false; } if (is_constant) { diff --git a/src/ir.cpp b/src/ir.cpp index 9639760f0..6a9835636 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -8184,6 +8184,7 @@ irAddr ir_build_addr(irProcedure *proc, Ast *expr) { Selection sel = lookup_field(bt, name, false); index = sel.index[0]; elem = fv->value; + TypeAndValue tav = type_and_value_of_expr(elem); } else { TypeAndValue tav = type_and_value_of_expr(elem); Selection sel = lookup_field_from_index(bt, st->fields[field_index]->Variable.field_src_index); @@ -8192,12 +8193,13 @@ irAddr ir_build_addr(irProcedure *proc, Ast *expr) { field = st->fields[index]; Type *ft = field->type; - if (!is_raw_union && ir_is_elem_const(proc->module, elem, ft)) { + if (!is_raw_union && !is_type_typeid(ft) && ir_is_elem_const(proc->module, elem, ft)) { continue; } field_expr = ir_build_expr(proc, elem); + GB_ASSERT(ir_type(field_expr)->kind != Type_Tuple); Type *fet = ir_type(field_expr);