diff --git a/sdk/angelscript/source/as_compiler.cpp b/sdk/angelscript/source/as_compiler.cpp index 246fc8800..3f2d9ff63 100644 --- a/sdk/angelscript/source/as_compiler.cpp +++ b/sdk/angelscript/source/as_compiler.cpp @@ -13139,6 +13139,9 @@ int asCCompiler::InstantiateTemplateFunctions(asCArray& funcs, asCScriptNod if (numTypes == 0) continue; asCArray 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 diff --git a/sdk/angelscript/source/as_scriptengine.cpp b/sdk/angelscript/source/as_scriptengine.cpp index ff0cc2cae..14b0462d6 100644 --- a/sdk/angelscript/source/as_scriptengine.cpp +++ b/sdk/angelscript/source/as_scriptengine.cpp @@ -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; } diff --git a/sdk/tests/test_feature/source/test_template.cpp b/sdk/tests/test_feature/source/test_template.cpp index 15d7547b6..de406e71c 100644 --- a/sdk/tests/test_feature/source/test_template.cpp +++ b/sdk/tests/test_feature/source/test_template.cpp @@ -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()", asFUNCTION(0), asCALL_GENERIC); + r = engine->RegisterObjectMethod("myObj", "const T@ get() 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(); \n" + " const myObj@ constX = x;\n" + " const auto constResult = constX.get(); \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; }