@@ -3671,23 +3671,39 @@ unique_ptr<parser::Node> Translator::patternTranslate(pm_node_t *node) {
36713671
36723672 unique_ptr<parser::Node> arrayPattern = nullptr ;
36733673
3674- // When the pattern ends with an implicit rest node, we need to return an `ArrayPatternWithTail` instead
3675- if (prismRestNode != nullptr && PM_NODE_TYPE_P (prismRestNode, PM_IMPLICIT_REST_NODE)) {
3676- arrayPattern = make_unique<parser::ArrayPatternWithTail>(location, move (sorbetElements));
3677- } else {
3678- arrayPattern = make_unique<parser::ArrayPattern>(location, move (sorbetElements));
3679- }
3680-
36813674 if (auto *prismConstant = arrayPatternNode->constant ) {
36823675 // An array pattern can start with a constant that matches against a specific type,
3683- // rather than any value whose `#deconstruct` results are matched by the pattern
3676+ // ( rather than any value whose `#deconstruct` results are matched by the pattern).
36843677 // E.g. the `Point` in `in Point[1, 2]`
36853678 auto sorbetConstant = translate (prismConstant);
36863679
3680+ ENFORCE (arrayPatternNode->opening_loc .start && arrayPatternNode->closing_loc .end ,
3681+ " Array pattern without parentheses or square brackets?" );
3682+
3683+ // The `ArrayPattern` loc doesn't include the constant, if there is one.
3684+ // `Point[x: Integer => 1, y: Integer => 2]`
3685+ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ArrayPattern loc
3686+ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ConstPattern loc
3687+ auto arrayPatternLoc =
3688+ translateLoc (arrayPatternNode->opening_loc .start , arrayPatternNode->closing_loc .end );
3689+
3690+ // When the pattern ends with an implicit rest node, we need to return an `ArrayPatternWithTail`
3691+ // instead
3692+ if (prismRestNode != nullptr && PM_NODE_TYPE_P (prismRestNode, PM_IMPLICIT_REST_NODE)) {
3693+ arrayPattern = make_unique<parser::ArrayPatternWithTail>(arrayPatternLoc, move (sorbetElements));
3694+ } else {
3695+ arrayPattern = make_unique<parser::ArrayPattern>(arrayPatternLoc, move (sorbetElements));
3696+ }
3697+
36873698 return make_unique<parser::ConstPattern>(location, move (sorbetConstant), move (arrayPattern));
36883699 }
36893700
3690- return arrayPattern;
3701+ // When the pattern ends with an implicit rest node, we need to return an `ArrayPatternWithTail` instead
3702+ if (prismRestNode != nullptr && PM_NODE_TYPE_P (prismRestNode, PM_IMPLICIT_REST_NODE)) {
3703+ return make_unique<parser::ArrayPatternWithTail>(location, move (sorbetElements));
3704+ } else {
3705+ return make_unique<parser::ArrayPattern>(location, move (sorbetElements));
3706+ }
36913707 }
36923708 case PM_CAPTURE_PATTERN_NODE: { // A variable capture such as the `Integer => i` in `in Integer => i`
36933709 auto capturePatternNode = down_cast<pm_capture_pattern_node>(node);
@@ -3755,18 +3771,28 @@ unique_ptr<parser::Node> Translator::patternTranslate(pm_node_t *node) {
37553771 }
37563772 }
37573773
3758- auto hashPattern = make_unique<parser::HashPattern>(location, move (sorbetElements));
3759-
37603774 if (auto *prismConstant = hashPatternNode->constant ) {
37613775 // A hash pattern can start with a constant that matches against a specific type,
3762- // rather than any value whose `#deconstruct_keys` results are matched by the pattern
3776+ // ( rather than any value whose `#deconstruct_keys` results are matched by the pattern).
37633777 // E.g. the `Point` in `in Point[x: Integer => 1, y: Integer => 2]`
37643778 auto sorbetConstant = translate (prismConstant);
37653779
3780+ ENFORCE (hashPatternNode->opening_loc .start && hashPatternNode->closing_loc .end ,
3781+ " Hash pattern without parentheses or square brackets?" );
3782+
3783+ // The `HashPattern` loc doesn't include the constant, if there is one.
3784+ // `Point[x: Integer => 1, y: Integer => 2]`
3785+ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ HashPattern loc
3786+ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ConstPattern loc
3787+ auto hashPatternLoc =
3788+ translateLoc (hashPatternNode->opening_loc .start , hashPatternNode->closing_loc .end );
3789+
3790+ auto hashPattern = make_unique<parser::HashPattern>(hashPatternLoc, move (sorbetElements));
3791+
37663792 return make_unique<parser::ConstPattern>(location, move (sorbetConstant), move (hashPattern));
37673793 }
37683794
3769- return hashPattern ;
3795+ return make_unique<parser::HashPattern>(location, move (sorbetElements)) ;
37703796 }
37713797 case PM_IMPLICIT_NODE: {
37723798 auto implicitNode = down_cast<pm_implicit_node>(node);
0 commit comments