Skip to content

Commit

Permalink
feat(internal): Remove restriction on using tuple expressions for ass…
Browse files Browse the repository at this point in the history
…ignment expressions as TypeScript allows this
  • Loading branch information
tristanmenzel committed Oct 16, 2024
1 parent 54b3aa5 commit de5bbd5
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/puya/awst/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,30 +945,20 @@ def accept(self, visitor: StatementVisitor[T]) -> T:
@attrs.frozen
class AssignmentExpression(Expression):
"""
This both assigns value to target and returns the target as the result of the expression.
Note that tuple expressions aren't valid here as the target, but tuple variables obviously are.
This both assigns value to target and returns the value as the result of the expression.
Will validate that target and value are of the same type, and that said type is usable
as an l-value.
"""

target: Lvalue = attrs.field() # annoyingly, we can't do Lvalue "minus" TupleExpression
target: Lvalue = attrs.field()
value: Expression = attrs.field()
wtype: wtypes.WType = attrs.field(init=False)

@wtype.default
def _wtype(self) -> wtypes.WType:
return self.target.wtype

@target.validator
def _target_validator(self, _attribute: object, target: Lvalue) -> None:
if isinstance(target, TupleExpression):
raise CodeError(
"tuple unpacking in assignment expressions is not supported",
target.source_location,
)

@value.validator
def _value_validator(self, _attribute: object, value: Expression) -> None:
if value.wtype != self.target.wtype:
Expand Down

0 comments on commit de5bbd5

Please sign in to comment.