Skip to content

Commit c67131b

Browse files
committed
Scope.unset doesn't delete constants; unset local definitions before getting the correct answer for a JME part
fixes #1132
1 parent 18325dd commit c67131b

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

runtime/scripts/jme.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,10 +2201,13 @@ Scope.prototype = /** @lends Numbas.jme.Scope.prototype */ {
22012201
*
22022202
* @param {string} name
22032203
*/
2204-
deleteVariable: function(name) {
2204+
deleteVariable: function(name, options) {
2205+
options = options || {};
22052206
name = jme.normaliseName(name, this);
22062207
this.deleted.variables[name] = true;
2207-
this.deleted.constants[name] = true;
2208+
if(options.delete_constant !== false) {
2209+
this.deleted.constants[name] = true;
2210+
}
22082211
},
22092212
/** Mark the given function name as deleted from the scope.
22102213
*
@@ -2544,7 +2547,7 @@ Scope.prototype = /** @lends Numbas.jme.Scope.prototype */ {
25442547
var s = new Scope([this]);
25452548
if(defs.variables) {
25462549
defs.variables.forEach(function(v) {
2547-
s.deleteVariable(v);
2550+
s.deleteVariable(v, {delete_constant: false});
25482551
});
25492552
}
25502553
if(defs.functions) {

runtime/scripts/parts/jme.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ JMEPart.prototype = /** @lends Numbas.JMEPart.prototype */
288288
if(!tree && this.marks>0) {
289289
this.error('part.jme.answer missing');
290290
}
291+
scope = scope.unset(this.question.local_definitions);
291292
var expr = jme.display.treeToJME(tree,{plaindecimal: true},scope);
292293
settings.correctVariables = jme.findvars(jme.compile(expr),[],scope);
293294
settings.correctAnswer = jme.display.simplifyExpression(

0 commit comments

Comments
 (0)