From 5cea71cb254b246ba15a5d651c2f04b229bc09bc Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Sun, 31 Jul 2022 09:44:36 -0700 Subject: [PATCH] refactor: isolate in the code the point of template instantiation --- src/core/PocomathInstance.mjs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/core/PocomathInstance.mjs b/src/core/PocomathInstance.mjs index 0a589ca..62c6757 100644 --- a/src/core/PocomathInstance.mjs +++ b/src/core/PocomathInstance.mjs @@ -404,7 +404,21 @@ export default class PocomathInstance { Object.defineProperty(this, name, {configurable: true, value: 'limbo'}) const tf_imps = {} for (const [rawSignature, behavior] of usableEntries) { - /* For now, replace theTemplateParam with 'any' */ + /* Check if it's an ordinary non-template signature */ + let explicit = true + for (const type of typesOfSignature(rawSignature)) { + if (this._templateParam(type)) { // template types need better check + explicit = false + break + } + } + if (explicit) { + this._addTFimplementation( + tf_imps, rawSignature, behavior.uses, behavior.does) + continue + } + /* It's a template, have to instantiate */ + /* But just for initial testing, punt and use T as synonym for 'any' */ const signature = rawSignature.replaceAll(theTemplateParam, 'any') this._addTFimplementation( tf_imps, signature, behavior.uses, behavior.does)