{"action":"created","issue":{"url":"https://api.github.com/repos/eXist-db/exist/issues/1854","repository_url":"https://api.github.com/repos/eXist-db/exist","labels_url":"https://api.github.com/repos/eXist-db/exist/issues/1854/labels{/name}","comments_url":"https://api.github.com/repos/eXist-db/exist/issues/1854/comments","events_url":"https://api.github.com/repos/eXist-db/exist/issues/1854/events","html_url":"https://github.com/eXist-db/exist/issues/1854","id":320253316,"number":1854,"title":"import statements are (wrongly) inherited from the main XQuery script","user":{"login":"rvdb","id":223134,"avatar_url":"https://avatars1.githubusercontent.com/u/223134?v=4","gravatar_id":"","url":"https://api.github.com/users/rvdb","html_url":"https://github.com/rvdb","followers_url":"https://api.github.com/users/rvdb/followers","following_url":"https://api.github.com/users/rvdb/following{/other_user}","gists_url":"https://api.github.com/users/rvdb/gists{/gist_id}","starred_url":"https://api.github.com/users/rvdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rvdb/subscriptions","organizations_url":"https://api.github.com/users/rvdb/orgs","repos_url":"https://api.github.com/users/rvdb/repos","events_url":"https://api.github.com/users/rvdb/events{/privacy}","received_events_url":"https://api.github.com/users/rvdb/received_events","type":"User","site_admin":false},"labels":[{"id":876034261,"url":"https://api.github.com/repos/eXist-db/exist/labels/triage","name":"triage","color":"ededed","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-05-04T12:16:50Z","updated_at":"2018-05-05T15:51:17Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"### What is the problem\r\nIn eXist, XQuery modules that have been imported in a main XQuery script seem to inherit the main script's import statements, and can refer to each other, even though they don't import each other.\r\n\r\nTake, for example, following main XQuery scripts:\r\n\r\n- main.xq:\r\n\r\n      import module namespace import1=\"import1\" at \"import1.xqm\";\r\n      import module namespace import2=\"import2\" at \"import2.xqm\";\r\n      $import1:string\r\n\r\n- import1.xqm:\r\n\r\n      module namespace import1=\"import1\";\r\n      (: note how we don't import \"import2.xqm\" here, but just declare the \"import2\" namespace :)\r\n      declare namespace import2=\"import2\";\r\n      declare variable $import1:string := $import2:string;\r\n\r\n- import2.xqm:\r\n\r\n      module namespace import2=\"import2\";\r\n      declare variable $import2:string := \"a variable in the import2 module\";\r\n\r\nWhen `main.xq` is executed with eXist, the value of `$import2:string` is returned:\r\n\r\n    a variable in the import2 module\r\n\r\nYet, this is an invalid XQuery: since `import1.xqm` just declares the \"import2\" namespace without actually importing the `import2.xqm` module, the `$import2:string` variable shouldn't be accessible from `import1.xqm`, and an XQuery compilation error should be thrown. Instead, eXist seems to make `import1.xqm` inherit the `import module namespace import2=\"import2\" at \"import2.xqm\";` statement from the main XQuery script. Indeed, removing it from `main.xq` makes eXist throw the (expected) error.\r\n\r\nThis illustrates that eXist seems to interpret importing rules too lax.\r\n\r\n### What did you expect\r\nI would expect eXist to throw a XQuery compilation error, as does Saxon:\r\n\r\n    Error on line 5 of import1.xqm:\r\n      XPST0008: Variable $import2:string has not been declared\r\n    Error on line 4 column 1 of main.xq:\r\n      XPST0008: Static errors were reported in the imported library module\r\n    Static error(s) in query\r\n\r\n### Describe how to reproduce or add a test\r\nCopy the XQuery scripts mentioned above and included in this file ([import-test.zip](https://github.com/eXist-db/exist/files/1974344/import-test.zip)) and execute them with eXist. It makes no difference whether the files are stored on the file system or in the database.\r\n\r\n### Context information\r\n- eXist-db version + Git Revision hash: eXist-db 4.1.0 /  919514c68 \r\n- Java version: Oracle JDK 1.8.0_172-b11\r\n- Operating system: Windows 7\r\n- 32 or 64 bit: 64 bit\r\n- Any custom changes: none"},"comment":{"url":"https://api.github.com/repos/eXist-db/exist/issues/comments/386814836","html_url":"https://github.com/eXist-db/exist/issues/1854#issuecomment-386814836","issue_url":"https://api.github.com/repos/eXist-db/exist/issues/1854","id":386814836,"user":{"login":"dizzzz","id":1700062,"avatar_url":"https://avatars3.githubusercontent.com/u/1700062?v=4","gravatar_id":"","url":"https://api.github.com/users/dizzzz","html_url":"https://github.com/dizzzz","followers_url":"https://api.github.com/users/dizzzz/followers","following_url":"https://api.github.com/users/dizzzz/following{/other_user}","gists_url":"https://api.github.com/users/dizzzz/gists{/gist_id}","starred_url":"https://api.github.com/users/dizzzz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dizzzz/subscriptions","organizations_url":"https://api.github.com/users/dizzzz/orgs","repos_url":"https://api.github.com/users/dizzzz/repos","events_url":"https://api.github.com/users/dizzzz/events{/privacy}","received_events_url":"https://api.github.com/users/dizzzz/received_events","type":"User","site_admin":false},"created_at":"2018-05-05T15:51:17Z","updated_at":"2018-05-05T15:51:17Z","author_association":"OWNER","body":"from the spec:\r\n\r\n'''\r\nImplementations may provide mechanisms allowing the target namespace URI to be used as input to a process that delivers the module as a resource, for example a catalog, module repository, or URI resolver.\r\n'''\r\n\r\nI guess that if in an xquery already a module location is defined, it can be re-used during the whole lifespan of a query.....\r\n\r\nand : https://www.w3.org/TR/xquery-30/#id-module-handling-cycles"}}
{"actor":{"display_login":"dizzzz"}}