Skip to content

Commit 8a9211e

Browse files
committed
Fix locations of Complex nodes
1 parent 4afc0be commit 8a9211e

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

parser/prism/Translator.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,25 +2307,28 @@ unique_ptr<parser::Node> Translator::translate(pm_node_t *node, bool preserveCon
23072307
auto sign = value[0];
23082308
bool hasSign = (sign == '+' || sign == '-');
23092309

2310+
auto numberLoc = location;
23102311
if (hasSign) {
23112312
value.remove_prefix(1); // Remove the sign
2313+
2314+
numberLoc = core::LocOffsets{location.beginPos() + 1, location.endPos()};
23122315
}
23132316

23142317
// Create the desugared Complex call: `Kernel.Complex(0, unsigned_value)`
2315-
auto kernel = MK::Constant(location, core::Symbols::Kernel());
2318+
auto kernel = MK::Constant(numberLoc, core::Symbols::Kernel());
23162319
core::NameRef complexName = core::Names::Constants::Complex().dataCnst(ctx)->original;
23172320
core::NameRef valueName = ctx.state.enterNameUTF8(value);
2318-
auto complexCall = MK::Send2(location, move(kernel), complexName, location.copyWithZeroLength(),
2319-
MK::Int(location, 0), MK::String(location, valueName));
2321+
auto complexCall = MK::Send2(numberLoc, move(kernel), complexName, numberLoc.copyWithZeroLength(),
2322+
MK::Int(numberLoc, 0), MK::String(numberLoc, valueName));
23202323

23212324
// If there was a sign, wrap in unary operation
23222325
// E.g. desugar `+42` to `42.+()`
23232326
if (hasSign) {
2324-
auto complexNode = make_unique<parser::Complex>(location, string(value));
2327+
auto complexNode = make_unique<parser::Complex>(numberLoc, string(value));
23252328
core::NameRef unaryOp = (sign == '-') ? core::Names::unaryMinus() : core::Names::unaryPlus();
23262329

23272330
auto unarySend = MK::Send0(location, move(complexCall), unaryOp,
2328-
core::LocOffsets{location.beginLoc, location.beginLoc + 1});
2331+
core::LocOffsets{location.beginLoc, numberLoc.beginLoc});
23292332

23302333
return make_node_with_expr<parser::Send>(move(unarySend), location, move(complexNode), unaryOp,
23312334
core::LocOffsets{location.beginLoc, location.beginLoc + 1},

test/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ prism_location_test_suite(
165165
"prism_regression/keyword_it.rb",
166166
"prism_regression/lambda.rb",
167167
"prism_regression/literal_array.rb",
168-
"prism_regression/literal_complex.rb",
169168
"prism_regression/literal_hash.rb",
170169
"prism_regression/literal_regexp.rb",
171170
"prism_regression/literal_string_interpolation.rb",

0 commit comments

Comments
 (0)