Add token.ID.IsCannotAssignTo

This commit is contained in:
Nigel Tao committed 2019-01-13 11:15:17 +11:00
1 parent b18209c7dd
commit 89c136ebe4
2 files changed
+6 -2

No files matched your search

+3 -2
View File
@@ -660,9 +660,10 @@ func (p *parser) parseAssignNode() (*a.Node, error) {
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 {
} else if id.IsCannotAssignTo() {
if l == lhs {
return nil, fmt.Errorf(`parse: cannot assign to "this" at %s:%d`, p.filename, p.line())
return nil, fmt.Errorf(`parse: cannot assign to %q at %s:%d`,
id.Str(p.tm), p.filename, p.line())
}
if !p.funcEffect.Impure() {
return nil, fmt.Errorf(`parse: cannot assign to %q in a pure function at %s:%d`,