{"record":{"id":"79aeb304eadb1c44","repo":"dianping/cat","slug":"xqst0034","errorCode":"XQST0034","errorMessage":"\"{name}\": duplicate function declaration","messagePattern":"\"(.+?)\": duplicate function declaration","errorType":"error_code","errorClass":"StaticError","httpStatus":null,"severity":"error","filePath":"cat-home/src/main/webapp/assets/js/editor/worker-xquery.js","lineNumber":1999,"sourceCode":"            } else {\n                return this.root.functions[key];\n            }\n        },\n        \n        addFunction: function(qname, pos, params) {\n            if(this !== this.root){\n                throw new Error('addFunction() not invoked from the root static context.');\n            }\n            var arity = params.length;\n            if(\n                this.moduleNamespace !== '' &&\n                !(this.moduleNamespace === qname.uri || (qname.uri === '' && this.defaultFunctionNamespace === this.moduleNamespace))\n            ) {\n                throw new StaticError('XQST0048', '\"' + qname.prefix + ':' + qname.name + '\": Qname not library namespace', pos);\n            }\n            var key = getFnKey(qname, arity);\n            if(this.functions[key]) {\n                throw new StaticError('XQST0034', '\"' + qname.name + '\": duplicate function declaration', pos);\n            }\n            this.functions[key] = {\n                pos: pos,\n                params: params\n            };\n            return this;\n        }\n        \n    };\n    s.root = parent ? parent.root : s;\n    return s;\n};\n\n},\n{\"../tree_ops\":11,\"./errors\":1,\"./schema_built-in_types\":3}],\n5:[function(require,module,exports){\nexports.Translator = function(rootStcx, ast){\n    'use strict';","sourceCodeStart":1981,"sourceCodeEnd":2017,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-home/src/main/webapp/assets/js/editor/worker-xquery.js#L1981-L2017","documentation":"XQST0034 is the standard duplicate-function-declaration error. addFunction() keys functions by QName plus arity (getFnKey); if this.functions already holds that key, the second declaration is rejected. Two functions in one context may share a name only when their arities differ.","triggerScenarios":"Two 'declare function local:foo($a)' with the same name and one parameter; note the same name with different parameter counts (overloading) is allowed and will not trigger this.","commonSituations":"Merging files that both define local:process; copy-paste helpers like local:log defined twice; refactors that re-add a function under the same signature.","solutions":["Rename one of the functions (or merge the bodies).","If overloading is intended, give the variants different parameter counts.","After merging prologs, grep for 'declare function <name>' to catch duplicates."],"exampleFix":"// before\ndeclare function local:render($x) { local:wrap($x) };\ndeclare function local:render($x) { $x };\n\n// after\ndeclare function local:render($x) { local:wrap($x) };\ndeclare function local:render-raw($x) { $x };","handlingStrategy":"validation","validationCode":"// Detect duplicate name#arity function declarations\nvar seen = {};\nfnDecls.forEach(function(f) {\n  var key = f.uri + '#' + f.name + '#' + f.params.length;\n  if (seen[key]) { warn('Duplicate function ' + f.name + '#' + f.params.length); }\n  seen[key] = true;\n});","typeGuard":null,"tryCatchPattern":"if (e.code === 'XQST0034') {\n  highlight(e.pos, 'Rename one function or change its arity — same name+arity declared twice');\n}","preventionTips":["After merging query files, dedupe local: function definitions.","Prefer distinct helper names over relying on overloading."],"tags":["xquery","function-declaration","duplicate"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}