@@ -2851,8 +2851,10 @@ unique_ptr<parser::Node> Translator::translate(pm_node_t *node, bool preserveCon
28512851 // ...that implicitly checks against the last read line by an IO object, e.g. `if /wat/`
28522852 auto matchLastLineNode = down_cast<pm_match_last_line_node>(node);
28532853
2854+ auto contentLoc = translateLoc (matchLastLineNode->content_loc );
2855+
28542856 auto regex =
2855- translateRegexp (location, location , matchLastLineNode->unescaped , matchLastLineNode->closing_loc );
2857+ translateRegexp (location, contentLoc , matchLastLineNode->unescaped , matchLastLineNode->closing_loc );
28562858
28572859 return make_unsupported_node<parser::MatchCurLine>(location, move (regex));
28582860 }
@@ -4707,21 +4709,22 @@ core::NameRef Translator::nextUniqueDesugarName(core::NameRef original) {
47074709// Had to widen the type from `parser::Assign` to `parser::Node` to handle `make_node_with_expr` correctly.
47084710// TODO: narrow the type back after direct desugaring is complete. https://github.com/Shopify/sorbet/issues/671
47094711unique_ptr<parser::Node> Translator::translateRegexpOptions (pm_location_t closingLoc) {
4710- auto length = closingLoc.end - closingLoc.start ;
4711-
4712- // Chop off `/` from Regopt location, so the location only spans the options themselves:
4713- // `/foo/im`
4714- // ^^
4715- constexpr uint32_t offset = " /" sv.size ();
4716- auto location = translateLoc (closingLoc.start + offset, closingLoc.end );
4717-
4718- string_view options;
4719-
4720- if (length > 0 ) {
4721- options = sliceLocation (closingLoc).substr (1 ); // one character after the closing `/`
4722- } else {
4723- options = string_view ();
4724- }
4712+ ENFORCE (closingLoc.start && closingLoc.end );
4713+
4714+ // Chop off Regexp's closing delimiter from the start of the Regopt location,
4715+ // so the location only spans the options themselves:
4716+ // /foo/im
4717+ // ^^
4718+ // $r(foo)im
4719+ // ^^
4720+ // $r[foo]im
4721+ // ^^
4722+ // $r{foo}im
4723+ // ^^
4724+ auto prismLoc = pm_location_t {.start = closingLoc.start + 1 , .end = closingLoc.end };
4725+ auto location = translateLoc (prismLoc);
4726+
4727+ string_view options = sliceLocation (prismLoc);
47254728
47264729 if (!directlyDesugar) {
47274730 return make_unique<parser::Regopt>(location, options);
0 commit comments