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)
|
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 init core.Expression
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
name := ctx.Identifier().GetText()
|
||||||
|
err = scope.SetVariable(name)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
exp := ctx.Expression()
|
exp := ctx.Expression()
|
||||||
|
|
||||||
if exp != nil {
|
if exp != nil {
|
||||||
@@ -1039,10 +1046,6 @@ func (v *visitor) doVisitVariableDeclaration(ctx *fql.VariableDeclarationContext
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
name := ctx.Identifier().GetText()
|
|
||||||
|
|
||||||
scope.SetVariable(name)
|
|
||||||
|
|
||||||
return expressions.NewVariableDeclarationExpression(
|
return expressions.NewVariableDeclarationExpression(
|
||||||
v.getSourceMap(ctx),
|
v.getSourceMap(ctx),
|
||||||
name,
|
name,
|
||||||
|
|||||||
Reference in New Issue
Block a user