Skip to content

Commit 9b60088

Browse files
authored
fix: Fix bug that could caused variable map to be left in an inconsistent state. (#9339)
1 parent 55f5d64 commit 9b60088

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

core/variable_map.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ export class VariableMap
112112
const oldType = variable.getType();
113113
if (oldType === newType) return variable;
114114

115-
this.variableMap.get(variable.getType())?.delete(variable.getId());
115+
const oldTypeVariables = this.variableMap.get(oldType);
116+
oldTypeVariables?.delete(variable.getId());
117+
if (oldTypeVariables?.size === 0) {
118+
this.variableMap.delete(oldType);
119+
}
116120
variable.setType(newType);
117121
const newTypeVariables =
118122
this.variableMap.get(newType) ??

tests/mocha/variable_map_test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ suite('Variable Map', function () {
258258
assert.deepEqual(newTypeVariables, [variable]);
259259
assert.equal(variable.getType(), '');
260260
});
261+
262+
test('removes the type from the map when the last instance is changed', function () {
263+
const var1 = this.variableMap.createVariable('name1', 'type1');
264+
const var2 = this.variableMap.createVariable('name2', 'type2');
265+
this.variableMap.changeVariableType(var1, 'type2');
266+
assert.deepEqual(this.variableMap.getTypes(), ['type2']);
267+
});
261268
},
262269
);
263270

0 commit comments

Comments
 (0)