diff --git a/lang/check/check.go b/lang/check/check.go index f5e1e477..e46cb754 100644 --- a/lang/check/check.go +++ b/lang/check/check.go @@ -12,18 +12,13 @@ import ( t "github.com/google/puffs/lang/token" ) -// DummyTypeIdealNumber is an a.Node.MType field that means that n is an ideal -// numeric constant. -// -// TODO: change 1 to a named constant. -var DummyTypeIdealNumber = a.NewTypeExpr(0, 1, nil, nil, nil) +// DummyTypeIdealNumber is an *ast.Node MType (implicit type) that means that n +// is an ideal numeric constant. +var DummyTypeIdealNumber = a.NewTypeExpr(0, t.IDIdeal, nil, nil, nil) // TypeString returns a string form of the type n. func TypeString(m *t.IDMap, n *a.TypeExpr) string { if n != nil { - if n == DummyTypeIdealNumber { - return "!ideal!" - } switch n.PackageOrDecorator() { case 0: return m.ByID(n.Name()) diff --git a/lang/parse/parse.go b/lang/parse/parse.go index 2a39044c..e1a25a71 100644 --- a/lang/parse/parse.go +++ b/lang/parse/parse.go @@ -67,6 +67,14 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) { if err != nil { return nil, err } + if id0 != 0 && id0.IsBuiltIn() { + return nil, fmt.Errorf("parse: built-in %q used for func receiver at %s:%d", + p.m.ByID(id0), p.filename, p.line()) + } + if id1.IsBuiltIn() { + return nil, fmt.Errorf("parse: built-in %q used for func name at %s:%d", + p.m.ByID(id1), p.filename, p.line()) + } if p.peekID() == t.IDQuestion { flags |= a.FlagsSuspendible p.src = p.src[1:] @@ -97,6 +105,10 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) { if err != nil { return nil, err } + if name.IsBuiltIn() { + return nil, fmt.Errorf("parse: built-in %q used for struct name at %s:%d", + p.m.ByID(name), p.filename, p.line()) + } if p.peekID() == t.IDQuestion { flags |= a.FlagsSuspendible p.src = p.src[1:] diff --git a/lang/token/list.go b/lang/token/list.go index 37ad4b8e..c1837dbc 100644 --- a/lang/token/list.go +++ b/lang/token/list.go @@ -179,6 +179,7 @@ const ( IDStruct = ID(0x69<> KeyShift: {"struct", IDStruct}, IDUse >> KeyShift: {"use", IDUse}, IDVar >> KeyShift: {"var", IDVar}, + IDIdeal >> KeyShift: {"ideal", IDIdeal}, IDFalse >> KeyShift: {"false", IDFalse}, IDTrue >> KeyShift: {"true", IDTrue},