Skip to content

Fix crash for interpolation in pattern key #749

@thomasmarshall

Description

@thomasmarshall
case 1
in {"a:#{1}": a} => i
 puts "a: #{a} and i: #{i}"
end

The symbol literal with interpolation is not allowed when pattern matching here. Prism raises an error but still parses the tree like so:

@ AssocNode (location: (2,4)-(2,13))
├── flags: ∅
├── key:
│   @ InterpolatedSymbolNode (location: (2,4)-(2,13))
│   ├── flags: ∅
│   ├── opening_loc: (2,4)-(2,5) = "\""
│   ├── parts: (length: 2)
│   │   ├── @ StringNode (location: (2,5)-(2,7))
│   │   │   ├── flags: static_literal, frozen
│   │   │   ├── opening_loc: ∅
│   │   │   ├── content_loc: (2,5)-(2,7) = "a:"
│   │   │   ├── closing_loc: ∅
│   │   │   └── unescaped: "a:"
│   │   └── @ EmbeddedStatementsNode (location: (2,7)-(2,11))
│   │       ├── flags: ∅
│   │       ├── opening_loc: (2,7)-(2,9) = "\#{"
│   │       ├── statements:
│   │       │   @ StatementsNode (location: (2,9)-(2,10))
│   │       │   ├── flags: ∅
│   │       │   └── body: (length: 1)
│   │       │       └── @ IntegerNode (location: (2,9)-(2,10))
│   │       │           ├── flags: static_literal, decimal
│   │       │           └── value: 1
│   │       └── closing_loc: (2,10)-(2,11) = "}"
│   └── closing_loc: (2,11)-(2,13) = "\":"
├── value:
│   @ MissingNode (location: (2,4)-(2,13))
│   └── flags: ∅
└── operator_loc: ∅

Valid node types for the key are specified here.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions