From 3a4479b8261861819846acaaff6b37eeb4e32d96 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Mon, 27 Nov 2023 23:32:52 -0800 Subject: [PATCH] reinstated: overloaded functions (including operators) can have different return types --- VERSIONS | 2 ++ src/core/chuck_dl.cpp | 4 ++-- src/core/chuck_scan.cpp | 43 ++++++++++++++++++++++------------------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/VERSIONS b/VERSIONS index 39283ecf6..1239cbb7a 100644 --- a/VERSIONS +++ b/VERSIONS @@ -56,6 +56,8 @@ new Foo(10,11,12) @=> Foo @ f4; - (added) CKDoc and .help() support for constructors - (added) Shred.parent() and Shred.ancestor() - (fixed) Type.of("int[][]").isArray() now correctly returns true +- (updated) now overloaded functions (including operators) can have + different return types - (updated) ChucK API doucmentation for constructors - (added) overloaded constructors added (more to come) ================== diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp index 46ccd0a08..2e94f4f4e 100644 --- a/src/core/chuck_dl.cpp +++ b/src/core/chuck_dl.cpp @@ -1148,8 +1148,8 @@ const Chuck_DL_Query * Chuck_DLL::query() string("' in dll '") + m_filename + string("'"); return NULL; } - // delete entry - CK_SAFE_DELETE( f ); + // delete entry (and zero out the array element) + CK_SAFE_DELETE( m_query.op_overloads[i] ); } // clear m_query.op_overloads.clear(); diff --git a/src/core/chuck_scan.cpp b/src/core/chuck_scan.cpp index a3f15451c..5d743647e 100644 --- a/src/core/chuck_scan.cpp +++ b/src/core/chuck_scan.cpp @@ -3087,30 +3087,33 @@ t_CKBOOL type_engine_scan2_func_def( Chuck_Env * env, a_Func_Def f ) // if overloading if( overload != NULL ) { + // ----------------------- + // 1.5.2.0 (ge) reinstating ability for overloaded funcs + // (including operators) to return different types // ----------------------- // make sure return types match // 1.5.0.0 (ge) more precise error reporting // ----------------------- - if( *(f->ret_type) != *(overload->func_ref->def()->ret_type) ) - { - EM_error2( f->where, "overloaded functions require matching return types..." ); - // check if in class definition - if( env->class_def ) - { - EM_error3( " |- function in question: %s %s.%s(...)", - func->def()->ret_type->base_name.c_str(), env->class_def->c_name(), S_name(f->name) ); - EM_error3( " |- previous defined as: %s %s.%s(...)", - overload->func_ref->def()->ret_type->base_name.c_str(), env->class_def->c_name(), S_name(f->name) ); - } - else - { - EM_error3( " |- function in question: %s %s(...)", - func->def()->ret_type->base_name.c_str(), S_name(f->name) ); - EM_error3( " |- previous defined as: %s %s(...)", - overload->func_ref->def()->ret_type->base_name.c_str(), S_name(f->name) ); - } - goto error; - } + // if( *(f->ret_type) != *(overload->func_ref->def()->ret_type) ) + // { + // EM_error2( f->where, "overloaded functions require matching return types..." ); + // // check if in class definition + // if( env->class_def ) + // { + // EM_error3( " |- function in question: %s %s.%s(...)", + // func->def()->ret_type->base_name.c_str(), env->class_def->c_name(), S_name(f->name) ); + // EM_error3( " |- previous defined as: %s %s.%s(...)", + // overload->func_ref->def()->ret_type->base_name.c_str(), env->class_def->c_name(), S_name(f->name) ); + // } + // else + // { + // EM_error3( " |- function in question: %s %s(...)", + // func->def()->ret_type->base_name.c_str(), S_name(f->name) ); + // EM_error3( " |- previous defined as: %s %s(...)", + // overload->func_ref->def()->ret_type->base_name.c_str(), S_name(f->name) ); + // } + // goto error; + // } // ----------------------- // make sure not duplicate