mirror of
https://github.com/ruby/ruby.git
synced 2026-01-26 12:14:51 +00:00
[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 d357d50f0a74409446f4cccec78593373f5adf2f which was a workaround to be compatible with parse.y.
This commit is contained in:
parent
cd66d15858
commit
c970d2941d
Notes:
git
2025-12-30 15:03:19 +00:00
2
parse.y
2
parse.y
@ -5149,7 +5149,7 @@ lambda : tLAMBDA[lpar]
|
||||
CMDARG_POP();
|
||||
$args = args_with_numbered(p, $args, max_numparam, it_id);
|
||||
{
|
||||
YYLTYPE loc = code_loc_gen(&@args, &@body);
|
||||
YYLTYPE loc = code_loc_gen(&@lpar, &@body);
|
||||
$$ = NEW_LAMBDA($args, $body->node, &loc, &@lpar, &$body->opening_loc, &$body->closing_loc);
|
||||
nd_set_line(RNODE_LAMBDA($$)->nd_body, @body.end_pos.lineno);
|
||||
nd_set_line($$, @args.end_pos.lineno);
|
||||
|
||||
@ -3284,13 +3284,6 @@ pm_scope_node_init(const pm_node_t *node, pm_scope_node_t *scope, pm_scope_node_
|
||||
scope->parameters = cast->parameters;
|
||||
scope->body = cast->body;
|
||||
scope->locals = cast->locals;
|
||||
|
||||
if (cast->parameters != NULL) {
|
||||
scope->base.location.start = cast->parameters->location.start;
|
||||
}
|
||||
else {
|
||||
scope->base.location.start = cast->operator_loc.end;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PM_MODULE_NODE: {
|
||||
|
||||
@ -61,7 +61,7 @@ describe "Proc#source_location" do
|
||||
ruby_version_is("4.0") do
|
||||
proc { true }.source_location.should == [__FILE__, __LINE__, 11, __LINE__, 19]
|
||||
Proc.new { true }.source_location.should == [__FILE__, __LINE__, 15, __LINE__, 23]
|
||||
-> { true }.source_location.should == [__FILE__, __LINE__, 8, __LINE__, 17]
|
||||
-> { true }.source_location.should == [__FILE__, __LINE__, 6, __LINE__, 17]
|
||||
end
|
||||
end
|
||||
|
||||
@ -98,7 +98,7 @@ describe "Proc#source_location" do
|
||||
location.should == ["foo", 100]
|
||||
end
|
||||
ruby_version_is("4.0") do
|
||||
location.should == ["foo", 100, 2, 100, 5]
|
||||
location.should == ["foo", 100, 0, 100, 5]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1230,7 +1230,7 @@ dummy
|
||||
args: nil
|
||||
body:
|
||||
(LAMBDA@1:0-2:3
|
||||
(SCOPE@1:2-2:3
|
||||
(SCOPE@1:0-2:3
|
||||
tbl: []
|
||||
args:
|
||||
(ARGS@1:2-1:2
|
||||
|
||||
@ -276,7 +276,7 @@ class TestLambdaParameters < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_do_lambda_source_location
|
||||
exp = [__LINE__ + 1, 12, __LINE__ + 5, 7]
|
||||
exp = [__LINE__ + 1, 10, __LINE__ + 5, 7]
|
||||
lmd = ->(x,
|
||||
y,
|
||||
z) do
|
||||
@ -288,7 +288,7 @@ class TestLambdaParameters < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_brace_lambda_source_location
|
||||
exp = [__LINE__ + 1, 12, __LINE__ + 5, 5]
|
||||
exp = [__LINE__ + 1, 10, __LINE__ + 5, 5]
|
||||
lmd = ->(x,
|
||||
y,
|
||||
z) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user