Fix overloading bug due to comparison of named types

This commit is contained in:
Ginger Bill
2017-02-18 22:19:35 +00:00
parent 9ff474f387
commit 0c37aa9ea0
5 changed files with 29 additions and 21 deletions
-1
View File
@@ -7,7 +7,6 @@
#import "os.odin"; #import "os.odin";
#import "halloc.odin"; #import "halloc.odin";
main :: proc() { main :: proc() {
/* /*
/* /*
+3 -2
View File
@@ -396,8 +396,8 @@ PIXELFORMATDESCRIPTOR :: struct #ordered {
damage_mask: u32, damage_mask: u32,
} }
GetDC :: proc(h: HANDLE) -> HDC #foreign user32; GetDC :: proc(h: HWND) -> HDC #foreign user32;
SetPixelFormat :: proc(hdc: HDC, pixel_format: i32, pfd: ^PIXELFORMATDESCRIPTOR ) -> BOOL #foreign gdi32; SetPixelFormat :: proc(hdc: HDC, pixel_format: i32, pfd: ^PIXELFORMATDESCRIPTOR) -> BOOL #foreign gdi32;
ChoosePixelFormat :: proc(hdc: HDC, pfd: ^PIXELFORMATDESCRIPTOR) -> i32 #foreign gdi32; ChoosePixelFormat :: proc(hdc: HDC, pfd: ^PIXELFORMATDESCRIPTOR) -> i32 #foreign gdi32;
SwapBuffers :: proc(hdc: HDC) -> BOOL #foreign gdi32; SwapBuffers :: proc(hdc: HDC) -> BOOL #foreign gdi32;
ReleaseDC :: proc(wnd: HWND, hdc: HDC) -> i32 #foreign user32; ReleaseDC :: proc(wnd: HWND, hdc: HDC) -> i32 #foreign user32;
@@ -412,6 +412,7 @@ wglCreateContext :: proc(hdc: HDC) -> HGLRC #foreign opengl32;
wglMakeCurrent :: proc(hdc: HDC, hglrc: HGLRC) -> BOOL #foreign opengl32; wglMakeCurrent :: proc(hdc: HDC, hglrc: HGLRC) -> BOOL #foreign opengl32;
wglGetProcAddress :: proc(c_str: ^u8) -> PROC #foreign opengl32; wglGetProcAddress :: proc(c_str: ^u8) -> PROC #foreign opengl32;
wglDeleteContext :: proc(hglrc: HGLRC) -> BOOL #foreign opengl32; wglDeleteContext :: proc(hglrc: HGLRC) -> BOOL #foreign opengl32;
wglChoosePixelFormatARB :: proc(hdc: HDC, attribi_list: ^i32, attribf_list: ^f32, max_formats: u32, formats: ^i32, num_formats: u32) -> BOOL #foreign opengl32;
+1 -4
View File
@@ -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?! // TODO(bill): Should I allow this implicit conversion at all?!
// rawptr <- ^T // rawptr <- ^T
if (is_type_rawptr(dst) && is_type_pointer(src)) { if (are_types_identical(type, t_rawptr) && is_type_pointer(src)) {
if (dst != type) {
return -1;
}
return 5; return 5;
} }
#endif #endif
+3
View File
@@ -1242,6 +1242,9 @@ void check_procedure_overloading(Checker *c, Entity *e) {
ProcTypeOverloadKind kind = are_proc_types_overload_safe(p->type, q->type); ProcTypeOverloadKind kind = are_proc_types_overload_safe(p->type, q->type);
switch (kind) { switch (kind) {
case ProcOverload_Identical: 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: case ProcOverload_CallingConvention:
error(p->token, "Overloaded procedure `%.*s` as the same type as another procedure in this scope", LIT(name)); error(p->token, "Overloaded procedure `%.*s` as the same type as another procedure in this scope", LIT(name));
is_invalid = true; is_invalid = true;
+22 -14
View File
@@ -888,7 +888,7 @@ bool are_types_identical(Type *x, Type *y) {
case Type_Named: case Type_Named:
if (y->kind == Type_Named) { if (y->kind == Type_Named) {
return x->Named.base == y->Named.base; return x->Named.type_name == y->Named.type_name;
} }
break; break;
@@ -923,7 +923,6 @@ bool are_types_identical(Type *x, Type *y) {
break; break;
} }
return false; return false;
} }
@@ -1023,41 +1022,50 @@ typedef enum ProcTypeOverloadKind {
ProcTypeOverloadKind are_proc_types_overload_safe(Type *x, Type *y) { ProcTypeOverloadKind are_proc_types_overload_safe(Type *x, Type *y) {
if (!is_type_proc(x)) return ProcOverload_NotProcedure; if (!is_type_proc(x)) return ProcOverload_NotProcedure;
if (!is_type_proc(y)) return ProcOverload_NotProcedure; if (!is_type_proc(y)) return ProcOverload_NotProcedure;
TypeProc *px = &base_type(x)->Proc; TypeProc px = base_type(x)->Proc;
TypeProc *py = &base_type(y)->Proc; TypeProc py = base_type(y)->Proc;
if (px->calling_convention != py->calling_convention) { if (px.calling_convention != py.calling_convention) {
return ProcOverload_CallingConvention; return ProcOverload_CallingConvention;
} }
if (px->param_count != py->param_count) { if (px.param_count != py.param_count) {
return ProcOverload_ParamCount; return ProcOverload_ParamCount;
} }
for (isize i = 0; i < px->param_count; i++) { for (isize i = 0; i < px.param_count; i++) {
Entity *ex = px->params->Tuple.variables[i]; Entity *ex = px.params->Tuple.variables[i];
Entity *ey = py->params->Tuple.variables[i]; Entity *ey = py.params->Tuple.variables[i];
if (!are_types_identical(ex->type, ey->type)) { if (!are_types_identical(ex->type, ey->type)) {
return ProcOverload_ParamTypes; return ProcOverload_ParamTypes;
} }
} }
// IMPORTANT TODO(bill): Determine the rules for overloading procedures with variadic parameters // 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; return ProcOverload_ParamVariadic;
} }
if (px->result_count != py->result_count) { if (px.result_count != py.result_count) {
return ProcOverload_ResultCount; return ProcOverload_ResultCount;
} }
for (isize i = 0; i < px->result_count; i++) { for (isize i = 0; i < px.result_count; i++) {
Entity *ex = px->results->Tuple.variables[i]; Entity *ex = px.results->Tuple.variables[i];
Entity *ey = py->results->Tuple.variables[i]; Entity *ey = py.results->Tuple.variables[i];
if (!are_types_identical(ex->type, ey->type)) { if (!are_types_identical(ex->type, ey->type)) {
return ProcOverload_ResultTypes; 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; return ProcOverload_Identical;
} }