Skip to content

Commit ec6dcd0

Browse files
committed
Reject tuple reassignment syntax
1 parent cb0a37a commit ec6dcd0

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/pinescript_validator/parser.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,15 @@ def statement(self) -> AST.Statement | None:
234234

235235
self.consume(TokenType.RBRACKET, 'Expected "]" in destructuring pattern')
236236
if self.check(TokenType.ASSIGN):
237-
self.advance()
238-
return self.destructuring_assignment(names, variables, start)
237+
assign_token = self.advance()
238+
if assign_token.value == "=":
239+
return self.destructuring_assignment(names, variables, start)
240+
self.report_error(
241+
'Tuple destructuring uses "=" only. Reassignment with ":=" is not valid in Pine Script.',
242+
assign_token,
243+
)
244+
self.expression()
245+
return None
239246
self.current = checkpoint
240247
except Exception:
241248
self.current = checkpoint

tests/test_validator.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,14 @@ def test_strategy_negative_pyramiding_is_rejected(self) -> None:
153153
)
154154
)
155155

156-
def test_destructuring_reassignment_is_supported(self) -> None:
156+
def test_destructuring_reassignment_is_rejected(self) -> None:
157157
diagnostics = self.validator.validate_text("[a, b] := foo()")
158-
self.assertFalse(any("Mismatched input" in diagnostic.message for diagnostic in diagnostics))
158+
self.assertTrue(
159+
any(
160+
'Tuple destructuring uses "=" only. Reassignment with ":=" is not valid in Pine Script.' in diagnostic.message
161+
for diagnostic in diagnostics
162+
)
163+
)
159164

160165
def test_typed_array_declaration(self) -> None:
161166
diagnostics = self.validator.validate_text("var box[] mc_boxes = array.new_box()")

0 commit comments

Comments
 (0)