Analyzer tests for reserved idents
This commit is contained in:
parent
423f3ba22f
commit
6c41e71ade
@ -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 {
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user