File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -1123,6 +1123,17 @@ func TestIssue105(t *testing.T) {
11231123 require .Contains (t , err .Error (), "ambiguous identifier Field" )
11241124}
11251125
1126+ func TestIssue_nested_closures (t * testing.T ) {
1127+ code := `all(1..3, { all(1..3, { # > 0 }) and # > 0 })`
1128+
1129+ program , err := expr .Compile (code )
1130+ require .NoError (t , err )
1131+
1132+ output , err := expr .Run (program , nil )
1133+ require .NoError (t , err )
1134+ require .True (t , output .(bool ))
1135+ }
1136+
11261137//
11271138// Mock types
11281139//
Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ type parser struct {
7777 current Token
7878 pos int
7979 err * file.Error
80- closure bool
80+ depth int // closure call depth
8181}
8282
8383type Tree struct {
@@ -219,7 +219,7 @@ func (p *parser) parsePrimary() Node {
219219 return p .parsePostfixExpression (expr )
220220 }
221221
222- if p .closure {
222+ if p .depth > 0 {
223223 if token .Is (Operator , "#" ) || token .Is (Operator , "." ) {
224224 if token .Is (Operator , "#" ) {
225225 p .next ()
@@ -377,9 +377,9 @@ func (p *parser) parseClosure() Node {
377377 token := p .current
378378 p .expect (Bracket , "{" )
379379
380- p .closure = true
380+ p .depth ++
381381 node := p .parseExpression (0 )
382- p .closure = false
382+ p .depth --
383383
384384 p .expect (Bracket , "}" )
385385 closure := & ClosureNode {
You can’t perform that action at this time.
0 commit comments