Skip to content

Commit

Permalink
Fix critical bug in list() where lists of different lengths could be …
Browse files Browse the repository at this point in the history
…merged accidentally
  • Loading branch information
benjie committed May 23, 2023
1 parent 00a8a74 commit fcc5143
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions grafast/grafast/src/steps/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ export class ListStep<

optimize(opts: StepOptimizeOptions) {
if (this.dependencies.every((dep) => dep instanceof ConstantStep)) {
const meta = opts.meta as { lists?: any[][] };
if (!meta.lists) {
meta.lists = [];
const meta = opts.meta as Record<number, any[][]>;
// Used to validate the lists have the same length
const cardinality = this.dependencies.length;
if (!meta[cardinality]) {
meta[cardinality] = [];
}
const existing = meta.lists.find((l) =>
const existing = meta[cardinality].find((l) =>
l.every(
(v, i) => v === (this.dependencies[i] as ConstantStep<any>).data,
),
Expand All @@ -69,7 +71,7 @@ export class ListStep<
const arr = this.dependencies.map(
(dep) => (dep as ConstantStep<any>).data,
);
meta.lists.push(arr);
meta[cardinality].push(arr);
return constant(arr);
}
}
Expand Down

0 comments on commit fcc5143

Please sign in to comment.