Skip to content

Ruby accepts a[&b]=c but Prism rejects it #1636

Closed

Description

@tompng

Prism rejects these codes. Ruby and YARP 0.12.0 accepts it.

a[&b] = c
a[&b] += c
a[&b] ||= c
a[&b] &&= c

I'm not sure if it's related to this issue or not, Prism::CallNode have method block but Prism::CallOperatorNode Prism::CallAndWriteNode Prism::CallOrWriteNode does not have it.

Activity

  1. eregon commented on Oct 10, 2023

    @eregon
    Member

    Maybe it's a case that CRuby should forbid?
    I think this syntax might not be intentionally supported.
    Could you open an issue at https://bugs.ruby-lang.org/ to find out?

    It does seem to "work" in CRuby to be fair:

    $ ruby -e 'a=Object.new; c=42; b=->{}; def a.[]=(*a,&b); p [a,b]; end; a[&b] = c'
    [[42], #<Proc:0x00007fc5e22bd1a8 -e:1 (lambda)>]
    
  2. added
    bug
    on Oct 11, 2023
  3. kddnewton commented on Oct 12, 2023

    @kddnewton
    Collaborator

    Thanks @tompng - regardless of whether it's good or not, we need to support it to be compatible. Fortunately I don't think this will be too bad.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions