Skip to content

Commit

Permalink
Scope.unset doesn't delete constants; unset local definitions before …
Browse files Browse the repository at this point in the history
…getting the correct answer for a JME part

fixes #1132
  • Loading branch information
christianp committed Dec 13, 2024
1 parent 18325dd commit c67131b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions runtime/scripts/jme.js
Original file line number Diff line number Diff line change
Expand Up @@ -2201,10 +2201,13 @@ Scope.prototype = /** @lends Numbas.jme.Scope.prototype */ {
*
* @param {string} name
*/
deleteVariable: function(name) {
deleteVariable: function(name, options) {
options = options || {};
name = jme.normaliseName(name, this);
this.deleted.variables[name] = true;
this.deleted.constants[name] = true;
if(options.delete_constant !== false) {
this.deleted.constants[name] = true;
}
},
/** Mark the given function name as deleted from the scope.
*
Expand Down Expand Up @@ -2544,7 +2547,7 @@ Scope.prototype = /** @lends Numbas.jme.Scope.prototype */ {
var s = new Scope([this]);
if(defs.variables) {
defs.variables.forEach(function(v) {
s.deleteVariable(v);
s.deleteVariable(v, {delete_constant: false});
});
}
if(defs.functions) {
Expand Down
1 change: 1 addition & 0 deletions runtime/scripts/parts/jme.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ JMEPart.prototype = /** @lends Numbas.JMEPart.prototype */
if(!tree && this.marks>0) {
this.error('part.jme.answer missing');
}
scope = scope.unset(this.question.local_definitions);
var expr = jme.display.treeToJME(tree,{plaindecimal: true},scope);
settings.correctVariables = jme.findvars(jme.compile(expr),[],scope);
settings.correctAnswer = jme.display.simplifyExpression(
Expand Down

0 comments on commit c67131b

Please sign in to comment.