Skip to content

Implicit "it" parameter should not be assignable #9265

Description

@headius

Assignments to the implicit it parameter should not reassign the parameter but instead create a new local it variable. JRuby's logic reassigns the implicit.

    "foo".tap do
      it or flunk
      it = it = "bar"

      assert_equal([:it], binding.implicit_parameters)
      assert_equal("foo", binding.implicit_parameter_get(:it))
      assert_equal(true, binding.implicit_parameter_defined?(:it))

      assert_equal([:it], binding.local_variables)
      assert_equal("bar", binding.local_variable_get(:it))
      assert_equal(true, binding.local_variable_defined?(:it))
    end

In JRuby, the assert_equal("bar"... fails because there's only one it variable here and it gets reassigned.

We currently allocate variables in the scope by name, so this may require some new representation of implicit variables that does not use the same table. This test (test/mri/ruby/test_proc.rb @ test_implicit_parameters_for_it_complex) will be excluded for now since this is a little bit edge-casey (nobody should be relying on this behavior in code that anyone will ever maintain).

Ref #9061

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions