Skip to content

Commit

Permalink
reinstated: overloaded functions (including operators) can have diffe…
Browse files Browse the repository at this point in the history
…rent return types
  • Loading branch information
gewang committed Nov 28, 2023
1 parent 7af4f81 commit 3a4479b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
2 changes: 2 additions & 0 deletions VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -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)
==================
Expand Down
4 changes: 2 additions & 2 deletions src/core/chuck_dl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
43 changes: 23 additions & 20 deletions src/core/chuck_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3a4479b

Please sign in to comment.