aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-02-18 22:19:35 +0000
committerGinger Bill <bill@gingerbill.org>2017-02-18 22:19:35 +0000
commit0c37aa9ea0271ddd8c93ea65f76d2f9ef4d777c5 (patch)
treed3a8907ca922e4e5c0b4439b3d6a043baa8a481b /src
parent9ff474f387f8cfb2b0ee780034c584aabccb9248 (diff)
Fix overloading bug due to comparison of named types
Diffstat (limited to 'src')
-rw-r--r--src/check_expr.c5
-rw-r--r--src/checker.c3
-rw-r--r--src/types.c36
3 files changed, 26 insertions, 18 deletions
diff --git a/src/check_expr.c b/src/check_expr.c
index 41f9ce08d..2f612513b 100644
--- a/src/check_expr.c
+++ b/src/check_expr.c
@@ -183,10 +183,7 @@ i64 check_distance_between_types(Checker *c, Operand *operand, Type *type) {
// TODO(bill): Should I allow this implicit conversion at all?!
// rawptr <- ^T
- if (is_type_rawptr(dst) && is_type_pointer(src)) {
- if (dst != type) {
- return -1;
- }
+ if (are_types_identical(type, t_rawptr) && is_type_pointer(src)) {
return 5;
}
#endif
diff --git a/src/checker.c b/src/checker.c
index 0b3c66166..e44fd1a77 100644
--- a/src/checker.c
+++ b/src/checker.c
@@ -1242,6 +1242,9 @@ void check_procedure_overloading(Checker *c, Entity *e) {
ProcTypeOverloadKind kind = are_proc_types_overload_safe(p->type, q->type);
switch (kind) {
case ProcOverload_Identical:
+ error(p->token, "Overloaded procedure `%.*s` as the same type as another procedure in this scope", LIT(name));
+ is_invalid = true;
+ break;
case ProcOverload_CallingConvention:
error(p->token, "Overloaded procedure `%.*s` as the same type as another procedure in this scope", LIT(name));
is_invalid = true;
diff --git a/src/types.c b/src/types.c
index 06a407576..72c9f19ce 100644
--- a/src/types.c
+++ b/src/types.c
@@ -888,7 +888,7 @@ bool are_types_identical(Type *x, Type *y) {
case Type_Named:
if (y->kind == Type_Named) {
- return x->Named.base == y->Named.base;
+ return x->Named.type_name == y->Named.type_name;
}
break;
@@ -923,7 +923,6 @@ bool are_types_identical(Type *x, Type *y) {
break;
}
-
return false;
}
@@ -1023,41 +1022,50 @@ typedef enum ProcTypeOverloadKind {
ProcTypeOverloadKind are_proc_types_overload_safe(Type *x, Type *y) {
if (!is_type_proc(x)) return ProcOverload_NotProcedure;
if (!is_type_proc(y)) return ProcOverload_NotProcedure;
- TypeProc *px = &base_type(x)->Proc;
- TypeProc *py = &base_type(y)->Proc;
+ TypeProc px = base_type(x)->Proc;
+ TypeProc py = base_type(y)->Proc;
- if (px->calling_convention != py->calling_convention) {
+ if (px.calling_convention != py.calling_convention) {
return ProcOverload_CallingConvention;
}
- if (px->param_count != py->param_count) {
+ if (px.param_count != py.param_count) {
return ProcOverload_ParamCount;
}
- for (isize i = 0; i < px->param_count; i++) {
- Entity *ex = px->params->Tuple.variables[i];
- Entity *ey = py->params->Tuple.variables[i];
+ for (isize i = 0; i < px.param_count; i++) {
+ Entity *ex = px.params->Tuple.variables[i];
+ Entity *ey = py.params->Tuple.variables[i];
if (!are_types_identical(ex->type, ey->type)) {
return ProcOverload_ParamTypes;
}
}
// IMPORTANT TODO(bill): Determine the rules for overloading procedures with variadic parameters
- if (px->variadic != py->variadic) {
+ if (px.variadic != py.variadic) {
return ProcOverload_ParamVariadic;
}
- if (px->result_count != py->result_count) {
+ if (px.result_count != py.result_count) {
return ProcOverload_ResultCount;
}
- for (isize i = 0; i < px->result_count; i++) {
- Entity *ex = px->results->Tuple.variables[i];
- Entity *ey = py->results->Tuple.variables[i];
+ for (isize i = 0; i < px.result_count; i++) {
+ Entity *ex = px.results->Tuple.variables[i];
+ Entity *ey = py.results->Tuple.variables[i];
if (!are_types_identical(ex->type, ey->type)) {
return ProcOverload_ResultTypes;
}
}
+ {
+ Entity *ex = px.params->Tuple.variables[0];
+ Entity *ey = py.params->Tuple.variables[0];
+ bool ok = are_types_identical(ex->type, ey->type);
+ if (ok) {
+ gb_printf_err("Here\n");
+ }
+ }
+
return ProcOverload_Identical;
}