Browse Source

Fix Internal error when accessing polymorphic struct parameters (also provide suggestions?) #513

gingerBill 5 years ago
parent
commit
4f2d4716ad
1 changed files with 12 additions and 1 deletions
  1. 12 1
      src/check_expr.cpp

+ 12 - 1
src/check_expr.cpp

@@ -3254,7 +3254,18 @@ Entity *check_selector(CheckerContext *c, Operand *operand, Ast *node, Type *typ
 		return nullptr;
 	}
 
-
+	if (expr_entity != nullptr && is_type_polymorphic(expr_entity->type)) {
+		gbString op_str   = expr_to_string(op_expr);
+		gbString type_str = type_to_string(operand->type);
+		gbString sel_str  = expr_to_string(selector);
+		error(op_expr, "Cannot access field '%s' from non-specialized polymorphic type '%s'", sel_str, op_str);
+		gb_string_free(sel_str);
+		gb_string_free(type_str);
+		gb_string_free(op_str);
+		operand->mode = Addressing_Invalid;
+		operand->expr = node;
+		return nullptr;
+	}
 
 	add_entity_use(c, selector, entity);