parser.go: function parameter list can't specify same parameter more than once
This commit is contained in:
parent
98fc89e84f
commit
321030c8d3
16
parser.go
16
parser.go
@ -66,6 +66,12 @@ func (parser *parser) parseFuncDef(scanner *scanner) (tree *term, err error) {
|
||||
tk = parser.Next(scanner)
|
||||
if tk.IsSymbol(SymIdentifier) {
|
||||
param := newTerm(tk)
|
||||
if len(args) > 0 {
|
||||
if pos := paramAlreadyDefined(args, param); pos > 0 {
|
||||
err = tk.Errorf("parameter %q at position %d already defined at position %d", param.source(), len(args)+1, pos)
|
||||
break
|
||||
}
|
||||
}
|
||||
args = append(args, param)
|
||||
tk = parser.Next(scanner)
|
||||
if tk.Sym == SymEqual {
|
||||
@ -110,6 +116,16 @@ func (parser *parser) parseFuncDef(scanner *scanner) (tree *term, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func paramAlreadyDefined(args []*term, param *term) (position int) {
|
||||
position = 0
|
||||
for i, arg := range args {
|
||||
if arg.source() == param.source() {
|
||||
position = i + 1
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (parser *parser) parseList(scanner *scanner, parsingIndeces bool, allowVarRef bool) (subtree *term, err error) {
|
||||
r, c := scanner.lastPos()
|
||||
args := make([]*term, 0)
|
||||
|
Loading…
Reference in New Issue
Block a user