mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 08:52:18 +01:00
Prohibit "this.etc = etc" inside pure functions
This commit is contained in:
1 parent
d552f88738
commit
84f9d3a915
2 files changed
+23
-5
No files matched your search
+23
-3
@@ -654,10 +654,30 @@ func (p *parser) parseAssignNode() (*a.Node, error) {
|
|||||||
return nil, fmt.Errorf(`parse: assignment LHS %q is not effect-free at %s:%d`,
|
return nil, fmt.Errorf(`parse: assignment LHS %q is not effect-free at %s:%d`,
|
||||||
lhs.Str(p.tm), p.filename, p.line())
|
lhs.Str(p.tm), p.filename, p.line())
|
||||||
}
|
}
|
||||||
if lhs.Operator() == 0 && lhs.Ident().IsLiteral(p.tm) {
|
|
||||||
return nil, fmt.Errorf(`parse: assignment LHS %q is a literal at %s:%d`,
|
for l := lhs; l != nil; l = l.LHS().AsExpr() {
|
||||||
lhs.Str(p.tm), p.filename, p.line())
|
switch l.Operator() {
|
||||||
|
case 0:
|
||||||
|
if id := l.Ident(); id.IsLiteral(p.tm) {
|
||||||
|
return nil, fmt.Errorf(`parse: assignment LHS %q is a literal at %s:%d`,
|
||||||
|
l.Str(p.tm), p.filename, p.line())
|
||||||
|
} else if id == t.IDThis {
|
||||||
|
if l == lhs {
|
||||||
|
return nil, fmt.Errorf(`parse: cannot assign to "this" at %s:%d`, p.filename, p.line())
|
||||||
|
}
|
||||||
|
if !p.funcEffect.Impure() {
|
||||||
|
return nil, fmt.Errorf(`parse: cannot assign to %q in a pure function at %s:%d`,
|
||||||
|
lhs.Str(p.tm), p.filename, p.line())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case t.IDDot, t.IDOpenBracket:
|
||||||
|
// No-op.
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf(`parse: invalid assignment LHS %q at %s:%d`,
|
||||||
|
lhs.Str(p.tm), p.filename, p.line())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rhs, err = p.parseExpr()
|
rhs, err = p.parseExpr()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -53,8 +53,6 @@ pub func hasher.update!(x slice base.u8) base.u32 {
|
|||||||
args.x = remaining
|
args.x = remaining
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: check that you can't assign to this.foo unless the method's effect
|
|
||||||
// is "!" impure or "?" impure coroutine.
|
|
||||||
this.state = ((s2 & 0xFFFF) << 16) | (s1 & 0xFFFF)
|
this.state = ((s2 & 0xFFFF) << 16) | (s1 & 0xFFFF)
|
||||||
return this.state
|
return this.state
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user