Browse Source

Fix issue #119
This may need better error messages

Ginger Bill 7 years ago
parent
commit
26d3c54aff
3 changed files with 17 additions and 5 deletions
  1. 15 5
      src/check_expr.cpp
  2. 1 0
      src/ir.cpp
  3. 1 0
      src/types.cpp

+ 15 - 5
src/check_expr.cpp

@@ -405,7 +405,7 @@ bool is_polymorphic_type_assignable(Checker *c, Type *poly, Type *source, bool c
 i64 check_distance_between_types(Checker *c, Operand *operand, Type *type) {
 i64 check_distance_between_types(Checker *c, Operand *operand, Type *type) {
 	if (operand->mode == Addressing_Invalid ||
 	if (operand->mode == Addressing_Invalid ||
 	    type == t_invalid) {
 	    type == t_invalid) {
-		return 0;
+		return -1;
 	}
 	}
 
 
 	if (operand->mode == Addressing_Builtin) {
 	if (operand->mode == Addressing_Builtin) {
@@ -1192,8 +1192,9 @@ bool check_representable_as_constant(Checker *c, ExactValue in_value, Type *type
 	}
 	}
 
 
 	type = core_type(type);
 	type = core_type(type);
-
-	if (is_type_boolean(type)) {
+	if (type == t_invalid) {
+		return false;
+	} else if (is_type_boolean(type)) {
 		return in_value.kind == ExactValue_Bool;
 		return in_value.kind == ExactValue_Bool;
 	} else if (is_type_string(type)) {
 	} else if (is_type_string(type)) {
 		return in_value.kind == ExactValue_String;
 		return in_value.kind == ExactValue_String;
@@ -1485,8 +1486,17 @@ void check_comparison(Checker *c, Operand *x, Operand *y, TokenKind op) {
 			gb_string_free(type_string);
 			gb_string_free(type_string);
 		}
 		}
 	} else {
 	} else {
-		gbString xt = type_to_string(x->type);
-		gbString yt = type_to_string(y->type);
+		gbString xt, yt;
+		if (x->mode == Addressing_Overload) {
+			xt = gb_string_make(heap_allocator(), "overloaded procedure");
+		} else {
+			xt = type_to_string(x->type);
+		}
+		if (y->mode == Addressing_Overload) {
+			yt = gb_string_make(heap_allocator(), "overloaded procedure");
+		} else {
+			yt = type_to_string(y->type);
+		}
 		err_str = gb_string_make(c->tmp_allocator,
 		err_str = gb_string_make(c->tmp_allocator,
 		                         gb_bprintf("mismatched types `%s` and `%s`", xt, yt));
 		                         gb_bprintf("mismatched types `%s` and `%s`", xt, yt));
 		gb_string_free(yt);
 		gb_string_free(yt);

+ 1 - 0
src/ir.cpp

@@ -4639,6 +4639,7 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) {
 
 
 	case_ast_node(i, Ident, expr);
 	case_ast_node(i, Ident, expr);
 		Entity *e = entity_of_ident(proc->module->info, expr);
 		Entity *e = entity_of_ident(proc->module->info, expr);
+		GB_ASSERT_MSG(e != nullptr, "%s", expr_to_string(expr));
 		if (e->kind == Entity_Builtin) {
 		if (e->kind == Entity_Builtin) {
 			Token token = ast_node_token(expr);
 			Token token = ast_node_token(expr);
 			GB_PANIC("TODO(bill): ir_build_single_expr Entity_Builtin `%.*s`\n"
 			GB_PANIC("TODO(bill): ir_build_single_expr Entity_Builtin `%.*s`\n"

+ 1 - 0
src/types.cpp

@@ -3,6 +3,7 @@ struct AstNode;
 
 
 enum BasicKind {
 enum BasicKind {
 	Basic_Invalid,
 	Basic_Invalid,
+
 	Basic_bool,
 	Basic_bool,
 	Basic_i8,
 	Basic_i8,
 	Basic_u8,
 	Basic_u8,