diff --git a/analyzer/expression.go b/analyzer/expression.go index 832a672..1c34061 100644 --- a/analyzer/expression.go +++ b/analyzer/expression.go @@ -3,6 +3,7 @@ package analyzer import "fmt" import "git.tebibyte.media/fspl/fspl/errors" import "git.tebibyte.media/fspl/fspl/entity" +import "git.tebibyte.media/fspl/fspl/parser/fspl" // All expression analysis routines must take in the type they are being // assigned to and return an error if they can't be assigned to it. if the type @@ -62,6 +63,13 @@ func (this *Tree) analyzeDeclaration ( entity.Expression, error, ) { + if fsplParser.IsReserved(declaration.Name) { + return nil, errors.Errorf ( + declaration.Position(), + "cannot shadow reserved identifier %s", + declaration.Name) + } + scope, _ := this.topScope() existing := scope.Variable(declaration.Name) if existing != nil { diff --git a/analyzer/tree.go b/analyzer/tree.go index 2ff1cb3..17e6e84 100644 --- a/analyzer/tree.go +++ b/analyzer/tree.go @@ -76,6 +76,11 @@ func (this *Tree) assembleRawMaps () error { } func (this *Tree) topLevelNameAvailable (currentPos errors.Position, key entity.Key) error { + if fsplParser.IsReserved(key.Name) { + return errors.Errorf ( + currentPos, "cannot shadow reserved identifier %s", + key.Name) + } if _, isPrimitive := primitiveTypes[key.Name]; isPrimitive { return errors.Errorf ( currentPos, "cannot shadow primitive %s",