From 2dd1a1db50c0815f3bca5ec8d1a4dade888e5fad Mon Sep 17 00:00:00 2001 From: Christian Lawson-Perfect Date: Tue, 3 Dec 2024 17:00:24 +0000 Subject: [PATCH] findvars on lambda: don't include boundvars --- runtime/scripts/jme.js | 7 +++++-- tests/jme/jme-tests.mjs | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/runtime/scripts/jme.js b/runtime/scripts/jme.js index 52fb0f31e..470945258 100644 --- a/runtime/scripts/jme.js +++ b/runtime/scripts/jme.js @@ -4303,8 +4303,11 @@ var findvars = jme.findvars = function(tree,boundvars,scope) { } } else { var argvars = jme.findvars_args(tree.args, boundvars, scope); - if(tree.tok.type == 'function' && scope.getFunction(tree.tok.name).length == 0) { - argvars.push(tree.tok.name); + if(tree.tok.type == 'function') { + const fn_name = jme.normaliseName(tree.tok.name, scope); + if(boundvars.indexOf(fn_name)==-1 && scope.getFunction(fn_name).length == 0) { + argvars.push(fn_name); + } } return argvars; } diff --git a/tests/jme/jme-tests.mjs b/tests/jme/jme-tests.mjs index 82552976c..33ae6e190 100644 --- a/tests/jme/jme-tests.mjs +++ b/tests/jme/jme-tests.mjs @@ -92,6 +92,7 @@ Numbas.queueScript('jme_tests',['qunit','jme','jme-rules','jme-display','jme-cal deepCloseEqual(assert, Numbas.jme.findvars(Numbas.jme.compile('let(["x":z],x+y)')),['y','z'],'findvars on let with a dictionary'); deepCloseEqual(assert, Numbas.jme.findvars(Numbas.jme.compile('let([q,w],[2,3],x,z,x+y+q+w)')),['y','z'],'findvars on let with a sequence of names'); deepCloseEqual(assert, Numbas.jme.findvars(Numbas.jme.compile('x -> x+z')),['z'],'findvars on lambda'); + deepCloseEqual(assert, Numbas.jme.findvars(Numbas.jme.compile('a -> a(x)')),['x'],'findvars on lambda where an argument is another lambda'); deepCloseEqual(assert, Numbas.jme.findvars(Numbas.jme.compile('[x,[y,z]] -> x+y+z+w')),['w'],'findvars on lambda with destructuring'); deepCloseEqual(assert, Numbas.jme.findvars(Numbas.jme.compile('undefined_function(x)')),['x', 'undefined_function'],'Undefined function names are presumed to be missing variables.'); });