Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symbol literals with interpolation are not allowed in hash patterns #340

Open
kddnewton opened this issue Mar 27, 2023 · 7 comments
Open
Assignees

Comments

@kddnewton
Copy link

Found this while importing your tests into YARP. On this line:

in {"#{"a"}": 1} then

It's actually a syntax error.

case foo
in {"#{"a"}": 1}
end

Running ruby -c gives:

test.rb: test.rb:2: symbol literal with interpolation is not allowed (SyntaxError)
in {"#{"a"}": 1}
    ^~~~~~~~~
@mbj
Copy link
Owner

mbj commented Mar 27, 2023

Interesting, whitequark/parser seems to accept it right now, producing this AST, its accepted in 2.7, 3.0, 3.1 and 3.2 here.

(case-match
  (send nil :foo)
  (in-pattern
    (hash-pattern
      (pair
        (dsym
          (begin
            (str "a")))
        (int 1))) nil nil) nil)

On MRI: Ruby 2.7 accepts it. But 3.0, 3.1 and 3.2 not.

Unparsers goal was to be able to unparser whitequark/parser so it does the job "right". This pattern tests are extracted from whitequark parser corpus. So you should have found it also via your test extraction.

I think we have to file this issue in whitequark/parser. Once they remove support unparser will also.

@mbj
Copy link
Owner

mbj commented Mar 27, 2023

For full visibility, I've reported this in: whitequark/parser#919. I do not want to filter it out unparser side for the moment. I'll do so with a fixing parser release.

@mbj mbj self-assigned this Mar 27, 2023
@mbj
Copy link
Owner

mbj commented Mar 27, 2023

@kddnewton if you are importing unparsers tests, you can just ignore this pattern, or would it be better for you I pushed a removal?

@kddnewton
Copy link
Author

That's okay! I'm just ignored that one line for now. I appreciate the explanation!

@mbj
Copy link
Owner

mbj commented Mar 27, 2023

Well I'd be happy to use YARP in the future as source AST for unparser. So thanks to you.

I hope you made dstrings less ambigious in your native AST, I'll check it out soon. Dynamic strings are the only construct that unparser fails on in edge cases right now.

@kddnewton
Copy link
Author

YARP has two kinds of strings: StringNode and InterpolatedStringNode. InterpolatedStringNode has a list of child nodes which are interpolated expressions, string nodes, or interpolated variables. Does that answer your question? I'm not entirely sure.

@mbj
Copy link
Owner

mbj commented Mar 27, 2023

@kddnewton yes helps me already, the story goes a bit deeper. I'll reply here later explaining it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants