Browse Source

Fix immutable `context` to `any` assignment #214

gingerBill 7 years ago
parent
commit
a83d916fad
1 changed files with 8 additions and 4 deletions
  1. 8 4
      src/check_expr.cpp

+ 8 - 4
src/check_expr.cpp

@@ -565,9 +565,13 @@ i64 check_distance_between_types(Checker *c, Operand *operand, Type *type) {
 
 	if (is_type_any(dst)) {
 		if (!is_type_polymorphic(src)) {
-			// NOTE(bill): Anything can cast to 'Any'
-			add_type_info_type(c, s);
-			return 10;
+			if (operand->mode == Addressing_Immutable && operand->type == t_context) {
+				return -1;
+			} else {
+				// NOTE(bill): Anything can cast to 'Any'
+				add_type_info_type(c, s);
+				return 10;
+			}
 		}
 	}
 
@@ -5126,7 +5130,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
 			}
 
 			init_preload(c);
-			o->mode = Addressing_Value;
+			o->mode = Addressing_Immutable;
 			o->type = t_context;
 			break;