dianping/cat · error · StaticError

XQST0049

XQST0049

Error message

"{name}": duplicate variable declaration

What it means

XQST0049 is the standard duplicate-variable-declaration error. addVariable() builds a key from the variable QName (getVarKey) and, for type 'VarDecl', rejects the declaration if this.variables already contains that key — two declared variables in the same static context cannot have the same expanded QName.

Source

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

                qname.name = value.substring(idx + 1);
            }
            return qname;
        },
        
        variables: {},
        varRefs: {},
        functionCalls: {},
    
        addVariable: function(qname, type, pos){
            if(
                type === 'VarDecl' && 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 = getVarKey(qname);
            if(type === 'VarDecl' && this.variables[key]) {
                throw new StaticError('XQST0049', '"' + qname.name + '": duplicate variable declaration', pos);
            }
            this.variables[key] = {
                type: type,
                pos: pos,
                qname: qname,
                annotations: {}
            };
            return this;
        },
        
        getVariables: function(){
            var variables = {};
            var that = this;
            var handler = function(key){
                if(!variables[key]){
                    variables[key] = that.variables[key];
                }
            };

View on GitHub (pinned to e815e74d4c)

Solutions

  1. Rename one of the duplicated variable declarations.
  2. Remove the leftover declaration after merging prologs.
  3. If the variables live in different modules, give each module's variable its module-namespace-prefixed name so the expanded QNames differ.

Example fix

// before
declare variable $max as xs:int := 10;
declare variable $max as xs:int := 99;

// after
declare variable $max as xs:int := 10;
declare variable $limit as xs:int := 99;
Defensive patterns

Strategy: validation

Validate before calling

// Detect duplicate declared variable QNames before analysis
var seen = {};
varDecls.forEach(function(d) {
  var key = d.uri + '#' + d.name;
  if (seen[key]) { warn('Duplicate variable $' + d.name); }
  seen[key] = true;
});

Try / catch

if (e.code === 'XQST0049') {
  highlight(e.pos, 'Rename one of the duplicate variable declarations');
}

Prevention

When it happens

Trigger: Two 'declare variable $x ...' statements whose QNames expand to the same namespace URI and local name within one module/context; importing the same variable twice is not the cause — only explicit VarDecl entries are checked.

Common situations: Merging query prologs that both declare $foo; copy-paste of variable blocks; renaming a variable to a name that already exists in the prolog.

Related errors


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