From 0c37aa9ea0271ddd8c93ea65f76d2f9ef4d777c5 Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Sat, 18 Feb 2017 22:19:35 +0000 Subject: [PATCH] Fix overloading bug due to comparison of named types --- code/demo.odin | 1 - core/sys/windows.odin | 5 +++-- src/check_expr.c | 5 +---- src/checker.c | 3 +++ src/types.c | 36 ++++++++++++++++++++++-------------- 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/code/demo.odin b/code/demo.odin index 34274cb22..8e5719f0f 100644 --- a/code/demo.odin +++ b/code/demo.odin @@ -7,7 +7,6 @@ #import "os.odin"; #import "halloc.odin"; - main :: proc() { /* /* diff --git a/core/sys/windows.odin b/core/sys/windows.odin index 165a0f761..d027c6072 100644 --- a/core/sys/windows.odin +++ b/core/sys/windows.odin @@ -396,8 +396,8 @@ PIXELFORMATDESCRIPTOR :: struct #ordered { damage_mask: u32, } -GetDC :: proc(h: HANDLE) -> HDC #foreign user32; -SetPixelFormat :: proc(hdc: HDC, pixel_format: i32, pfd: ^PIXELFORMATDESCRIPTOR ) -> BOOL #foreign gdi32; +GetDC :: proc(h: HWND) -> HDC #foreign user32; +SetPixelFormat :: proc(hdc: HDC, pixel_format: i32, pfd: ^PIXELFORMATDESCRIPTOR) -> BOOL #foreign gdi32; ChoosePixelFormat :: proc(hdc: HDC, pfd: ^PIXELFORMATDESCRIPTOR) -> i32 #foreign gdi32; SwapBuffers :: proc(hdc: HDC) -> BOOL #foreign gdi32; 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; wglGetProcAddress :: proc(c_str: ^u8) -> PROC #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; 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; }