@informalsystems/quint
Version:
Core tool for the Quint specification language
52 lines • 2.02 kB
JavaScript
;
/* ----------------------------------------------------------------------------------
* Copyright 2023 Informal Systems
* Licensed under the Apache License, Version 2.0.
* See LICENSE in the project root for license information.
* --------------------------------------------------------------------------------- */
Object.defineProperty(exports, "__esModule", { value: true });
exports.MultipleUpdatesChecker = void 0;
const base_1 = require("./base");
const EffectVisitor_1 = require("./EffectVisitor");
const lodash_1 = require("lodash");
/**
* Checks effects for multiple updates of the same state variable.
*/
class MultipleUpdatesChecker {
constructor() {
this.errors = new Map();
}
/**
* Checks effects for multiple updates of the same state variable.
*
* @param effects the effects to look for multiple updates on
*
* @returns a map of errors, where the key is the variable id
*/
checkEffects(effects) {
effects.forEach(e => (0, EffectVisitor_1.walkEffect)(this, e.effect));
return this.errors;
}
exitConcrete(e) {
const updateEntities = e.components.reduce((updates, c) => {
if (c.kind === 'update') {
updates.push(c.entity);
}
return updates;
}, []);
const vars = (0, base_1.stateVariables)({ kind: 'union', entities: updateEntities });
const repeated = (0, lodash_1.values)((0, lodash_1.pickBy)((0, lodash_1.groupBy)(vars, v => v.name), x => x.length > 1)).flat();
if (repeated.length > 0) {
repeated.forEach(v => {
this.errors.set(v.reference, {
code: 'QNT202',
message: `Multiple updates of variable ${v.name}`,
reference: v.reference,
data: {},
});
});
}
}
}
exports.MultipleUpdatesChecker = MultipleUpdatesChecker;
//# sourceMappingURL=MultipleUpdatesChecker.js.map