Skip to content

Commit 129d6ba

Browse files
committed
[Bug #21784] Fix the Proc#source_location start_column for stabby lambdas
* Consistent with plain `blocks` and `for` blocks and methods where the source_location covers their entire definition. * Matches the documentation which mentions "where the definition starts/ends". * Partially reverts d357d50 which was a workaround to be compatible with parse.y.
1 parent 31c3bcb commit 129d6ba

File tree

5 files changed

+6
-13
lines changed

5 files changed

+6
-13
lines changed

parse.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5149,7 +5149,7 @@ lambda : tLAMBDA[lpar]
51495149
CMDARG_POP();
51505150
$args = args_with_numbered(p, $args, max_numparam, it_id);
51515151
{
5152-
YYLTYPE loc = code_loc_gen(&@args, &@body);
5152+
YYLTYPE loc = code_loc_gen(&@lpar, &@body);
51535153
$$ = NEW_LAMBDA($args, $body->node, &loc, &@lpar, &$body->opening_loc, &$body->closing_loc);
51545154
nd_set_line(RNODE_LAMBDA($$)->nd_body, @body.end_pos.lineno);
51555155
nd_set_line($$, @args.end_pos.lineno);

prism_compile.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3284,13 +3284,6 @@ pm_scope_node_init(const pm_node_t *node, pm_scope_node_t *scope, pm_scope_node_
32843284
scope->parameters = cast->parameters;
32853285
scope->body = cast->body;
32863286
scope->locals = cast->locals;
3287-
3288-
if (cast->parameters != NULL) {
3289-
scope->base.location.start = cast->parameters->location.start;
3290-
}
3291-
else {
3292-
scope->base.location.start = cast->operator_loc.end;
3293-
}
32943287
break;
32953288
}
32963289
case PM_MODULE_NODE: {

spec/ruby/core/proc/source_location_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
ruby_version_is("4.0") do
6262
proc { true }.source_location.should == [__FILE__, __LINE__, 11, __LINE__, 19]
6363
Proc.new { true }.source_location.should == [__FILE__, __LINE__, 15, __LINE__, 23]
64-
-> { true }.source_location.should == [__FILE__, __LINE__, 8, __LINE__, 17]
64+
-> { true }.source_location.should == [__FILE__, __LINE__, 6, __LINE__, 17]
6565
end
6666
end
6767

@@ -98,7 +98,7 @@
9898
location.should == ["foo", 100]
9999
end
100100
ruby_version_is("4.0") do
101-
location.should == ["foo", 100, 2, 100, 5]
101+
location.should == ["foo", 100, 0, 100, 5]
102102
end
103103
end
104104
end

test/ruby/test_ast.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ def test_error_tolerant_end_is_short_for_do_LAMBDA
12301230
args: nil
12311231
body:
12321232
(LAMBDA@1:0-2:3
1233-
(SCOPE@1:2-2:3
1233+
(SCOPE@1:0-2:3
12341234
tbl: []
12351235
args:
12361236
(ARGS@1:2-1:2

test/ruby/test_lambda.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def test_break
276276
end
277277

278278
def test_do_lambda_source_location
279-
exp = [__LINE__ + 1, 12, __LINE__ + 5, 7]
279+
exp = [__LINE__ + 1, 10, __LINE__ + 5, 7]
280280
lmd = ->(x,
281281
y,
282282
z) do
@@ -288,7 +288,7 @@ def test_do_lambda_source_location
288288
end
289289

290290
def test_brace_lambda_source_location
291-
exp = [__LINE__ + 1, 12, __LINE__ + 5, 5]
291+
exp = [__LINE__ + 1, 10, __LINE__ + 5, 5]
292292
lmd = ->(x,
293293
y,
294294
z) {

0 commit comments

Comments
 (0)