Project

General

Profile

Actions

Bug #20468

closed
Image

Segfault on safe navigation in for target

Bug #20468: Segfault on safe navigation in for target

Added by kddnewton (Kevin Newton) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:117763]

Description

for foo&.bar in []; end

Related issues 1 (0 open1 closed)

Has duplicate Ruby - Bug #20561: Segfault with attr_writer, safe navigation and an "in" loopClosedActions

Image Updated by nobu (Nobuyoshi Nakada) over 1 year ago Actions #1 [ruby-core:117767]

I can't imagine what it should do when foo == nil.
Should be a syntax error probably?

Image Updated by nobu (Nobuyoshi Nakada) over 1 year ago Actions #2 [ruby-core:117768]

Hmmm, may be possible to interpret that code like as foo&.then {|recv| for recv.bar in []; end}.
Just an idea.

Image Updated by nobu (Nobuyoshi Nakada) over 1 year ago Actions #3 [ruby-core:117769]

  • Assignee set to matz (Yukihiro Matsumoto)

Image Updated by nobu (Nobuyoshi Nakada) over 1 year ago Actions #4 [ruby-core:117770]

  • Assignee deleted (matz (Yukihiro Matsumoto))

I found that a for loop variable is looser than I expected.
Not only a safe navigation call, even a constant can be used.
I don't think a constant is useful as a loop variable that is expected to be re-assigned.

https://github.com/ruby/ruby/pull/10723

Image Updated by Eregon (Benoit Daloze) over 1 year ago Actions #5 [ruby-core:117771]

Given for foo.bar in []; end is valid and does for.bar = element,
I think for foo&.bar in []; end could simply do for&.bar = element which is the same as for.bar = element unless foo.nil? (NIL_P(foo) to be precise).

Changing the syntax for for variables sounds more risky and likely to unexpectedly disallow some new lhs forms when the lhs rule is updated, and the for_var rule is forgotten to be updated too.

Image Updated by Eregon (Benoit Daloze) over 1 year ago Actions #6 [ruby-core:117772]

IOW I think the segfault could be fixed here without changing what is valid syntax.
And given this segfault probably affects older versions too there it seems better to fix the segfault than to change syntax.

Image Updated by zverok (Victor Shepelev) over 1 year ago Actions #7 [ruby-core:117773]

Agree with @Eregon (Benoit Daloze). The code should be more or less equivalent to:

for temp in [1, 2, 3]
  foo&.bar = temp
end

...which is totally valid and foo&.bar = is a no-op (semantically).

Image Updated by kddnewton (Kevin Newton) over 1 year ago Actions #8 [ruby-core:117791]

@nobu (Nobuyoshi Nakada) it's the same possibilities in for, rescue, and multi-write. As in:

for (foo, @foo, @@foo, $foo, Foo, Foo::Foo, foo.foo, foo[foo]) in bar; end

begin; rescue => foo; end
begin; rescue => @foo; end
begin; rescue => @@foo; end
begin; rescue => $foo; end
begin; rescue => Foo; end
begin; rescue => Foo::Foo; end
begin; rescue => foo.foo; end
begin; rescue => foo[foo]; end

(foo, @foo, @@foo, $foo, Foo, Foo::Foo, foo.foo, foo[foo]) = bar

Image Updated by nobu (Nobuyoshi Nakada) over 1 year ago Actions #9

  • Status changed from Open to Closed

Applied in changeset git|2dd46bb82ffc4dff01d7ea70922f0e407acafb4e.


[Bug #20468] Fix safe navigation in for variable

Image Updated by nobu (Nobuyoshi Nakada) over 1 year ago Actions #10

  • Has duplicate Bug #20561: Segfault with attr_writer, safe navigation and an "in" loop added

Image Updated by Eregon (Benoit Daloze) over 1 year ago Actions #11

  • Backport changed from 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN to 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED

Image Updated by k0kubun (Takashi Kokubun) over 1 year ago Actions #12 [ruby-core:118501]

  • Backport changed from 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED to 3.1: REQUIRED, 3.2: REQUIRED, 3.3: DONE

Image Updated by nagachika (Tomoyuki Chikanaga) over 1 year ago Actions #13 [ruby-core:118647]

  • Backport changed from 3.1: REQUIRED, 3.2: REQUIRED, 3.3: DONE to 3.1: REQUIRED, 3.2: DONE, 3.3: DONE
Actions

Also available in: PDF Atom