From c995e65ff25ff6bdaed7f22c253955ad5398a253 Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Wed, 29 Apr 2026 23:43:56 +0000 Subject: [PATCH] fix(patterns): handle copyBag in getRankCover kindMatcher (#3052) The match:kind helper's getRankCover only mapped copySet and copyMap to the 'tagged' pass style, leaving copyBag to fall through to the default branch where getPassStyleCover('copyBag') threw a TypeError because 'copyBag' is not a known PassStyle. Add copyBag alongside copySet and copyMap so all three tagged-encoded kinds share the same rank cover. --- .../patterns/src/patterns/patternMatchers.js | 1 + packages/patterns/test/patterns.test.js | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/patterns/src/patterns/patternMatchers.js b/packages/patterns/src/patterns/patternMatchers.js index 18cc63578a..1580003b28 100644 --- a/packages/patterns/src/patterns/patternMatchers.js +++ b/packages/patterns/src/patterns/patternMatchers.js @@ -937,6 +937,7 @@ const makePatternKit = () => { let style; switch (kind) { case 'copySet': + case 'copyBag': case 'copyMap': { style = 'tagged'; break; diff --git a/packages/patterns/test/patterns.test.js b/packages/patterns/test/patterns.test.js index e8f9faca50..c7196e7657 100644 --- a/packages/patterns/test/patterns.test.js +++ b/packages/patterns/test/patterns.test.js @@ -12,7 +12,12 @@ import { isKey, assertKey, } from '../src/keys/checkKey.js'; -import { mustMatch, matches, M } from '../src/patterns/patternMatchers.js'; +import { + mustMatch, + matches, + M, + getRankCover, +} from '../src/patterns/patternMatchers.js'; const { stringify: q } = JSON; @@ -971,3 +976,18 @@ test('Far functions (callable remotables) are valid Keys', t => { const set = makeCopySet([farFn]); t.true(matches(set, M.set())); }); + +test('getRankCover treats copyBag like other tagged kinds (#3052)', t => { + // copySet, copyBag, and copyMap all encode as the 'tagged' pass style, + // so getRankCover must produce the same range for each. Previously + // copyBag fell through to the default branch and threw a TypeError + // because 'copyBag' is not a known PassStyle. + // The kind matcher's getRankCover does not consult encodePassable, so + // this test does not require a real encoder. + const stubEncode = () => ''; + const setCover = getRankCover(M.kind('copySet'), stubEncode); + const bagCover = getRankCover(M.kind('copyBag'), stubEncode); + const mapCover = getRankCover(M.kind('copyMap'), stubEncode); + t.deepEqual(bagCover, setCover); + t.deepEqual(bagCover, mapCover); +});