ruby / prism

Prism Ruby parser
https://ruby.github.io/prism/
MIT License
825 stars 139 forks source link

Prism accepts `("a":)` as a symbol literal with parenthese, but Ruby rejects it #3035

Closed makenowjust closed 1 week ago

makenowjust commented 4 weeks ago

Bug report

Example code:

("a":)

Ruby:

-e:1: syntax error, unexpected tLABEL_END, expecting literal content or terminator or tSTRING_DBEG or tSTRING_DVAR
("a":)

Prism:

@ ProgramNode (location: (1,0)-(1,6))
├── flags: ∅
├── locals: []
└── statements:
    @ StatementsNode (location: (1,0)-(1,6))
    ├── flags: ∅
    └── body: (length: 1)
        └── @ ParenthesesNode (location: (1,0)-(1,6))
            ├── flags: newline
            ├── body:
            │   @ StatementsNode (location: (1,1)-(1,5))
            │   ├── flags: ∅
            │   └── body: (length: 1)
            │       └── @ SymbolNode (location: (1,1)-(1,5))
            │           ├── flags: newline, static_literal, forced_us_ascii_encoding
            │           ├── opening_loc: (1,1)-(1,2) = "\""
            │           ├── value_loc: (1,2)-(1,3) = "a"
            │           ├── closing_loc: (1,3)-(1,5) = "\":"
            │           └── unescaped: "a"
            ├── opening_loc: (1,0)-(1,1) = "("
            └── closing_loc: (1,5)-(1,6) = ")"

and ruby --parser=prism -e 'x = ("a":); p x' shows :a actually.

Bonus note

This bug is found by Lernen. Automata learning is real!