forked from M-Labs/artiq
compiler: disallow op= on mutable lists only (fix #835).
This only really applies to lists since those use fat pointers. `x.y += z` is fine.
This commit is contained in:
parent
cda9719f4b
commit
ca254ec55e
|
@ -330,7 +330,7 @@ class EscapeValidator(algorithm.Visitor):
|
||||||
self.visit_assignment(target, node.value)
|
self.visit_assignment(target, node.value)
|
||||||
|
|
||||||
def visit_AugAssign(self, node):
|
def visit_AugAssign(self, node):
|
||||||
if builtins.is_allocated(node.target.type):
|
if builtins.is_list(node.target.type):
|
||||||
note = diagnostic.Diagnostic("note",
|
note = diagnostic.Diagnostic("note",
|
||||||
"try using `{lhs} = {lhs} {op} {rhs}` instead",
|
"try using `{lhs} = {lhs} {op} {rhs}` instead",
|
||||||
{"lhs": node.target.loc.source(),
|
{"lhs": node.target.loc.source(),
|
||||||
|
@ -338,7 +338,7 @@ class EscapeValidator(algorithm.Visitor):
|
||||||
"op": node.op.loc.source()[:-1]},
|
"op": node.op.loc.source()[:-1]},
|
||||||
node.loc)
|
node.loc)
|
||||||
diag = diagnostic.Diagnostic("error",
|
diag = diagnostic.Diagnostic("error",
|
||||||
"values cannot be mutated in-place", {},
|
"lists cannot be mutated in-place", {},
|
||||||
node.op.loc, [node.target.loc],
|
node.op.loc, [node.target.loc],
|
||||||
notes=[note])
|
notes=[note])
|
||||||
self.engine.process(diag)
|
self.engine.process(diag)
|
||||||
|
|
Loading…
Reference in New Issue