Browse Source

Fix parapoly related bugs #370

gingerBill 6 years ago
parent
commit
a5ff983266
2 changed files with 37 additions and 10 deletions
  1. 23 10
      src/check_expr.cpp
  2. 14 0
      src/check_type.cpp

+ 23 - 10
src/check_expr.cpp

@@ -1429,7 +1429,6 @@ bool check_representable_as_constant(CheckerContext *c, ExactValue in_value, Typ
 		}
 	}
 
-
 	return false;
 }
 
@@ -4352,12 +4351,14 @@ isize add_dependencies_from_unpacking(CheckerContext *c, Entity **lhs, isize lhs
 	if (lhs != nullptr) {
 		for (isize j = 0; (tuple_index + j) < lhs_count && j < tuple_count; j++) {
 			Entity *e = lhs[tuple_index + j];
-			DeclInfo *decl = decl_info_of_entity(e);
-			if (decl != nullptr) {
-				c->decl = decl; // will be reset by the 'defer' any way
-				for_array(k, decl->deps.entries) {
-					Entity *dep = decl->deps.entries[k].ptr;
-					add_declaration_dependency(c, dep); // TODO(bill): Should this be here?
+			if (e != nullptr) {
+				DeclInfo *decl = decl_info_of_entity(e);
+				if (decl != nullptr) {
+					c->decl = decl; // will be reset by the 'defer' any way
+					for_array(k, decl->deps.entries) {
+						Entity *dep = decl->deps.entries[k].ptr;
+						add_declaration_dependency(c, dep); // TODO(bill): Should this be here?
+					}
 				}
 			}
 		}
@@ -4438,9 +4439,11 @@ bool check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize lhs_count,
 		if (lhs != nullptr && tuple_index < lhs_count) {
 			// NOTE(bill): override DeclInfo for dependency
 			Entity *e = lhs[tuple_index];
-			DeclInfo *decl = decl_info_of_entity(e);
-			if (decl) c->decl = decl;
-			type_hint = e->type;
+			if (e != nullptr) {
+				DeclInfo *decl = decl_info_of_entity(e);
+				if (decl) c->decl = decl;
+				type_hint = e->type;
+			}
 		}
 
 		check_expr_base(c, &o, rhs[i], type_hint);
@@ -4943,6 +4946,16 @@ CallArgumentData check_call_arguments(CheckerContext *c, Operand *operand, Type
 					lhs = pt->params->Tuple.variables.data;
 					lhs_count = pt->params->Tuple.variables.count;
 				}
+			} else {
+				// NOTE(bill): Create 'lhs' list in order to ignore parameters which are polymorphic
+				lhs_count = pt->params->Tuple.variables.count;
+				lhs = gb_alloc_array(heap_allocator(), Entity *, lhs_count);
+				for_array(i, pt->params->Tuple.variables) {
+					Entity *e = pt->params->Tuple.variables[i];
+					if (!is_type_polymorphic(e->type)) {
+						lhs[i] = e;
+					}
+				}
 			}
 		}
 

+ 14 - 0
src/check_type.cpp

@@ -1554,6 +1554,13 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is
 						success = false;
 						type = t_invalid;
 					}
+					if (is_type_untyped(default_type(type))) {
+						gbString str = type_to_string(type);
+						error(o.expr, "Cannot determine type from the parameter, got '%s'", str);
+						gb_string_free(str);
+						success = false;
+						type = t_invalid;
+					}
 					bool modify_type = !ctx->no_polymorphic_errors;
 
 					if (specialization != nullptr && !check_type_specialization_to(ctx, specialization, type, false, modify_type)) {
@@ -1604,6 +1611,13 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is
 							success = false;
 						}
 					}
+					if (is_type_untyped(default_type(type))) {
+						gbString str = type_to_string(type);
+						error(op.expr, "Cannot determine type from the parameter, got '%s'", str);
+						gb_string_free(str);
+						success = false;
+						type = t_invalid;
+					}
 				}
 
 				if (p->flags&FieldFlag_no_alias) {