Analyzer tests for reserved idents

This commit is contained in:
Sasha Koshka 2024-04-02 02:59:42 -04:00
parent 423f3ba22f
commit 6c41e71ade
2 changed files with 13 additions and 0 deletions

View File

@ -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 {

View File

@ -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",