Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sdk/angelscript/source/as_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13139,6 +13139,9 @@ int asCCompiler::InstantiateTemplateFunctions(asCArray<int>& funcs, asCScriptNod
if (numTypes == 0) continue;
asCArray<asCDataType> dataTypes;
// TODO: If there is more than one template function with the same name, then use only the one that matches

types = startNode;

for (asUINT j = 0; j < numTypes; j++)
{
// If the number of types doesn't match the template then give an error
Expand Down
3 changes: 2 additions & 1 deletion sdk/angelscript/source/as_scriptengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3210,7 +3210,8 @@ int asCScriptEngine::GetTemplateFunctionInstance(asCScriptFunction* baseFunc, co
if (func->name == baseFunc->name &&
func->nameSpace == baseFunc->nameSpace &&
func->objectType == baseFunc->objectType &&
func->templateSubTypes == types)
func->templateSubTypes == types &&
func->IsReadOnly() == baseFunc->IsReadOnly())
return func->id;
}

Expand Down
36 changes: 36 additions & 0 deletions sdk/tests/test_feature/source/test_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,42 @@ bool Test()
engine->Release();
}

// Must be able to register const and non const template method overloads
{
engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL);

r = engine->RegisterObjectType("myObj", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0);
r = engine->RegisterObjectMethod("myObj", "T@ get<T>()", asFUNCTION(0), asCALL_GENERIC);
r = engine->RegisterObjectMethod("myObj", "const T@ get<T>() const", asFUNCTION(0), asCALL_GENERIC);

r = engine->RegisterObjectType("myTestTemplateParam", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0);

if( r < 0 )
TEST_FAILED;

asIScriptModule *mod = engine->GetModule("test", asGM_ALWAYS_CREATE);
mod->AddScriptSection("test",
"void test(myObj@ x) \n"
"{ \n"
" auto result = x.get<myTestTemplateParam>(); \n"
" const myObj@ constX = x;\n"
" const auto constResult = constX.get<myTestTemplateParam>(); \n"
"} \n");
bout.buffer = "";
r = mod->Build();
if( r < 0 )
TEST_FAILED;

if( bout.buffer != "" )
{
PRINTF("%s", bout.buffer.c_str());
TEST_FAILED;
}

engine->Release();
}

return fail;
}

Expand Down