aboutsummaryrefslogtreecommitdiff
path: root/src/check_expr.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-08-13 10:45:29 +0100
committergingerBill <bill@gingerbill.org>2021-08-13 10:45:29 +0100
commit367bf0c7ae12157c32dbba38170555b951da9481 (patch)
treed1d98168dd91cef855fd70255666c6553efddf7e /src/check_expr.cpp
parent7afc367275d763e4780899e99fa354ad0662e03a (diff)
Fix #1076
Diffstat (limited to 'src/check_expr.cpp')
-rw-r--r--src/check_expr.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index 99b804ea6..17ad25c58 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -2571,6 +2571,14 @@ bool is_ise_expr(Ast *node) {
return node->kind == Ast_ImplicitSelectorExpr;
}
+bool can_use_other_type_as_type_hint(bool use_lhs_as_type_hint, Type *other_type) {
+ if (use_lhs_as_type_hint) { // RHS in this case
+ return other_type != nullptr && other_type != t_invalid && is_type_typed(other_type);
+ }
+ return false;
+}
+
+
void check_binary_expr(CheckerContext *c, Operand *x, Ast *node, Type *type_hint, bool use_lhs_as_type_hint=false) {
GB_ASSERT(node->kind == Ast_BinaryExpr);
Operand y_ = {}, *y = &y_;
@@ -2707,14 +2715,14 @@ void check_binary_expr(CheckerContext *c, Operand *x, Ast *node, Type *type_hint
// Evalute the right before the left for an '.X' expression
check_expr_or_type(c, y, be->right, type_hint);
- if (use_lhs_as_type_hint) { // RHS in this case
+ if (can_use_other_type_as_type_hint(use_lhs_as_type_hint, y->type)) { // RHS in this case
check_expr_or_type(c, x, be->left, y->type);
} else {
check_expr_with_type_hint(c, x, be->left, type_hint);
}
} else {
check_expr_with_type_hint(c, x, be->left, type_hint);
- if (use_lhs_as_type_hint) {
+ if (can_use_other_type_as_type_hint(use_lhs_as_type_hint, x->type)) {
check_expr_with_type_hint(c, y, be->right, x->type);
} else {
check_expr_with_type_hint(c, y, be->right, type_hint);
@@ -6598,6 +6606,9 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
case_ast_node(cl, CompoundLit, node);
Type *type = type_hint;
+ if (type != nullptr && is_type_untyped(type)) {
+ type = nullptr;
+ }
bool is_to_be_determined_array_count = false;
bool is_constant = true;
if (cl->type != nullptr) {