Add wuffs_foo__bar__initialize methods

This commit is contained in:
Nigel Tao committed 2019-02-09 12:54:02 +11:00
1 parent 10ead58e2e
commit 8794a586ac
10 files changed
+348 -103

No files matched your search

+8
View File
@@ -24,6 +24,7 @@ import (
)
type Options struct {
AllowBuiltInNames bool
AllowDoubleUnderscoreNames bool
}
@@ -156,6 +157,13 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
if err != nil {
return nil, err
}
if !p.opts.AllowBuiltInNames {
switch id1 {
case t.IDInitialize, t.IDReset:
return nil, fmt.Errorf(`parse: cannot have a method named %q at %s:%d`,
id1.Str(p.tm), p.filename, p.line())
}
}
// TODO: should we require id0 != 0? In other words, always methods
// (attached to receivers) and never free standing functions?
if !p.opts.AllowDoubleUnderscoreNames && isDoubleUnderscore(p.tm.ByID(id1)) {