dianping/cat · error · StaticError

XQST0034

XQST0034

Error message

"{name}": duplicate function declaration

What it means

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.

Source

Thrown at cat-home/src/main/webapp/assets/js/editor/worker-xquery.js:1999

            } else {
                return this.root.functions[key];
            }
        },
        
        addFunction: function(qname, pos, params) {
            if(this !== this.root){
                throw new Error('addFunction() not invoked from the root static context.');
            }
            var arity = params.length;
            if(
                this.moduleNamespace !== '' &&
                !(this.moduleNamespace === qname.uri || (qname.uri === '' && this.defaultFunctionNamespace === this.moduleNamespace))
            ) {
                throw new StaticError('XQST0048', '"' + qname.prefix + ':' + qname.name + '": Qname not library namespace', pos);
            }
            var key = getFnKey(qname, arity);
            if(this.functions[key]) {
                throw new StaticError('XQST0034', '"' + qname.name + '": duplicate function declaration', pos);
            }
            this.functions[key] = {
                pos: pos,
                params: params
            };
            return this;
        }
        
    };
    s.root = parent ? parent.root : s;
    return s;
};

},
{"../tree_ops":11,"./errors":1,"./schema_built-in_types":3}],
5:[function(require,module,exports){
exports.Translator = function(rootStcx, ast){
    'use strict';

View on GitHub (pinned to e815e74d4c)

Solutions

  1. Rename one of the functions (or merge the bodies).
  2. If overloading is intended, give the variants different parameter counts.
  3. After merging prologs, grep for 'declare function <name>' to catch duplicates.

Example fix

// before
declare function local:render($x) { local:wrap($x) };
declare function local:render($x) { $x };

// after
declare function local:render($x) { local:wrap($x) };
declare function local:render-raw($x) { $x };
Defensive patterns

Strategy: validation

Validate before calling

// Detect duplicate name#arity function declarations
var seen = {};
fnDecls.forEach(function(f) {
  var key = f.uri + '#' + f.name + '#' + f.params.length;
  if (seen[key]) { warn('Duplicate function ' + f.name + '#' + f.params.length); }
  seen[key] = true;
});

Try / catch

if (e.code === 'XQST0034') {
  highlight(e.pos, 'Rename one function or change its arity — same name+arity declared twice');
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14). Data as JSON: /api/errors/79aeb304eadb1c44. Report an issue: GitHub.