mirror of
https://github.com/MontFerret/ferret.git
synced 2024-12-14 11:23:02 +02:00
Fixed use of duplicate variable as a source in FOR IN statement (#196)
This commit is contained in:
parent
dc3de71554
commit
b3611c5713
@ -197,4 +197,15 @@ func TestLet(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
So(string(out), ShouldEqual, "[1,2,3]")
|
||||
})
|
||||
|
||||
Convey("Should not compile FOR foo IN foo", t, func() {
|
||||
c := compiler.New()
|
||||
|
||||
_, err := c.Compile(`
|
||||
FOR foo IN foo
|
||||
RETURN foo
|
||||
`)
|
||||
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
}
|
||||
|
@ -160,17 +160,7 @@ func (v *visitor) doVisitForExpression(ctx *fql.ForExpressionContext, scope *sco
|
||||
var keyVarName string
|
||||
|
||||
parsedClauses := make([]forOption, 0, 10)
|
||||
valVar := ctx.ForExpressionValueVariable()
|
||||
valVarName = valVar.GetText()
|
||||
forInScope := scope.Fork()
|
||||
forInScope.SetVariable(valVarName)
|
||||
|
||||
keyVar := ctx.ForExpressionKeyVariable()
|
||||
|
||||
if keyVar != nil {
|
||||
keyVarName = keyVar.GetText()
|
||||
forInScope.SetVariable(keyVarName)
|
||||
}
|
||||
|
||||
srcCtx := ctx.ForExpressionSource().(*fql.ForExpressionSourceContext)
|
||||
srcExp, err := v.doVisitForExpressionSource(srcCtx, forInScope)
|
||||
@ -179,6 +169,23 @@ func (v *visitor) doVisitForExpression(ctx *fql.ForExpressionContext, scope *sco
|
||||
return nil, err
|
||||
}
|
||||
|
||||
valVar := ctx.ForExpressionValueVariable()
|
||||
valVarName = valVar.GetText()
|
||||
|
||||
if err := forInScope.SetVariable(valVarName); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
keyVar := ctx.ForExpressionKeyVariable()
|
||||
|
||||
if keyVar != nil {
|
||||
keyVarName = keyVar.GetText()
|
||||
|
||||
if err := forInScope.SetVariable(keyVarName); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
src, err := expressions.NewDataSource(
|
||||
v.getSourceMap(srcCtx),
|
||||
valVarName,
|
||||
|
Loading…
Reference in New Issue
Block a user