Exist: regression with closures in maps (since 3.4.0)

Created on 20 Sep 2017  Â·  12Comments  Â·  Source: eXist-db/exist

What is the problem

Starting with eXist version 3.4.0 inline functions within maps will not inherit variables declared outside its function body. The problem has been discussed on eXist-open and was confirmed by @joewiz by testing against Saxon and BaseX.

What did you expect

I expected all three tests to pass without errors (as they do in eXist version 3.3.0).

Describe how to reproduce or add a test

xquery version "3.1";

module namespace ct="http://exist-db.org/xquery/closures/test";

declare variable $ct:model := function($param) {
    let $func := function() {
       $param
    }
    return
        map {
            'test1' : $func,
            'test2' : $func(),
            'test3' : function() {
                $param
            }
        }
};

declare %test:assertEquals('Hello World') function ct:test1-function-reference() as xs:string {
    try {
        $ct:model('Hello World')?test1()
    }
    catch * {$err:code || ' ' || $err:description}
};

declare %test:assertEquals('Hello World') function ct:test2-function-call() as xs:string {
    try {
        $ct:model('Hello World')?test2
    }
    catch * {$err:code || ' ' || $err:description}
};

declare %test:assertEquals('Hello World') function ct:test3-inline-function() as xs:string {
    try {
        $ct:model('Hello World')?test3()
    }
    catch * {$err:code || ' ' || $err:description}
};

Context information

  • eXist-db version 3.5.0-SNAPSHOT / fdaabad
  • Java 1.8.0_131 [Oracle Corporation]
  • Operating system MacOs Capitan 64 bit
  • vanilla build from develop branch
bug regression high prio

Most helpful comment

Assigning high prio for myself.

All 12 comments

Reviewing the details in this issue again, I notice the URL to the HoF article that Peter referenced in his exist-open post unfortunately isn’t working: http://atomic.exist-db.org/blogs/eXist/HoF...

HTTP ERROR 404

Problem accessing /exist/blogs/eXist/HoF. Reason:

Not Found

The URL http://atomic.exist-db.org/blogs/eXist/HoF does work for me … maybe just a temporary server error?

There were temporary hiccups with some pages on the server yesterday, which I fixed in the meantime.

It's best to point to http://exist-db.org/exist/apps/wiki/blogs/eXist/HoF though since http://atomic.exist-db.org is an old redirect.

While I congratulate to the 4.0 release I tentatively want to remind you of this issue. It's something that keeps me from upgrading so I'm currently stuck with version 3.3.0.

Many thanks in advance!

I had a look into this issue before 4.0 and I see where the problem is, but it's not straightforward to fix without potentially causing other regressions, so I did not want to risk it for the release.

Thanks for the reply! I was just trying to make sure it wont be forgotten ;)

Help! This is really an issue for me that prevents me from upgrading to a recent eXist version. Is a fix anywhere on the roadmap or do I have to refactor my code?

Assigning high prio for myself.

Sorry for bothering, but is there any chance this will be tackled in the near future?

not directly related, but because namespace prefixes can appear in maps, the preferred and specs compliant map syntax is

return
        map {
            'test1': $func,
            'test2': $func(),
            'test3': function() {
                $param
            }
        }

only one ws after : in { key: value }

@peterstadler I think you will have to ask @wolfgangmm

@duncdrum shall I create a PR for the tests?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lguariento picture lguariento  Â·  5Comments

merenyics picture merenyics  Â·  3Comments

mathias-goebel picture mathias-goebel  Â·  4Comments

jonjhallettuob picture jonjhallettuob  Â·  3Comments

dizzzz picture dizzzz  Â·  5Comments