mirror of
https://github.com/MontFerret/ferret.git
synced 2025-12-11 22:47:08 +02:00
Added var uniqueness check
This commit is contained in:
@@ -208,4 +208,27 @@ func TestLet(t *testing.T) {
|
||||
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
Convey("Should not compile if a variable not defined", t, func() {
|
||||
c := compiler.New()
|
||||
|
||||
_, err := c.Compile(`
|
||||
RETURN foo
|
||||
`)
|
||||
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
Convey("Should not compile if a variable is not unique", t, func() {
|
||||
c := compiler.New()
|
||||
|
||||
_, err := c.Compile(`
|
||||
LET foo = "bar"
|
||||
LET foo = "baz"
|
||||
|
||||
RETURN foo
|
||||
`)
|
||||
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1013,6 +1013,13 @@ func (v *visitor) doVisitVariableDeclaration(ctx *fql.VariableDeclarationContext
|
||||
var init core.Expression
|
||||
var err error
|
||||
|
||||
name := ctx.Identifier().GetText()
|
||||
err = scope.SetVariable(name)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
exp := ctx.Expression()
|
||||
|
||||
if exp != nil {
|
||||
@@ -1039,10 +1046,6 @@ func (v *visitor) doVisitVariableDeclaration(ctx *fql.VariableDeclarationContext
|
||||
return nil, err
|
||||
}
|
||||
|
||||
name := ctx.Identifier().GetText()
|
||||
|
||||
scope.SetVariable(name)
|
||||
|
||||
return expressions.NewVariableDeclarationExpression(
|
||||
v.getSourceMap(ctx),
|
||||
name,
|
||||
|
||||
Reference in New Issue
Block a user