fix: Fix bug that could caused variable map to be left in an inconsistent state. (#9339)

This commit is contained in:
Aaron Dodson
2025-09-02 12:39:16 -07:00
committed by GitHub
parent 55f5d648a8
commit 9b60088d4b
2 changed files with 12 additions and 1 deletions

View File

@@ -112,7 +112,11 @@ export class VariableMap
const oldType = variable.getType();
if (oldType === newType) return variable;
this.variableMap.get(variable.getType())?.delete(variable.getId());
const oldTypeVariables = this.variableMap.get(oldType);
oldTypeVariables?.delete(variable.getId());
if (oldTypeVariables?.size === 0) {
this.variableMap.delete(oldType);
}
variable.setType(newType);
const newTypeVariables =
this.variableMap.get(newType) ??

View File

@@ -258,6 +258,13 @@ suite('Variable Map', function () {
assert.deepEqual(newTypeVariables, [variable]);
assert.equal(variable.getType(), '');
});
test('removes the type from the map when the last instance is changed', function () {
const var1 = this.variableMap.createVariable('name1', 'type1');
const var2 = this.variableMap.createVariable('name2', 'type2');
this.variableMap.changeVariableType(var1, 'type2');
assert.deepEqual(this.variableMap.getTypes(), ['type2']);
});
},
);