{"record":{"id":"7f64fedc24ee8958","repo":"dianping/cat","slug":"xqst0049","errorCode":"XQST0049","errorMessage":"\"{name}\": duplicate variable declaration","messagePattern":"\"(.+?)\": duplicate variable declaration","errorType":"error_code","errorClass":"StaticError","httpStatus":null,"severity":"error","filePath":"cat-home/src/main/webapp/assets/js/editor/worker-xquery.js","lineNumber":1903,"sourceCode":"                qname.name = value.substring(idx + 1);\n            }\n            return qname;\n        },\n        \n        variables: {},\n        varRefs: {},\n        functionCalls: {},\n    \n        addVariable: function(qname, type, pos){\n            if(\n                type === 'VarDecl' && 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 = getVarKey(qname);\n            if(type === 'VarDecl' && this.variables[key]) {\n                throw new StaticError('XQST0049', '\"' + qname.name + '\": duplicate variable declaration', pos);\n            }\n            this.variables[key] = {\n                type: type,\n                pos: pos,\n                qname: qname,\n                annotations: {}\n            };\n            return this;\n        },\n        \n        getVariables: function(){\n            var variables = {};\n            var that = this;\n            var handler = function(key){\n                if(!variables[key]){\n                    variables[key] = that.variables[key];\n                }\n            };","sourceCodeStart":1885,"sourceCodeEnd":1921,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-home/src/main/webapp/assets/js/editor/worker-xquery.js#L1885-L1921","documentation":"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.","triggerScenarios":"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.","commonSituations":"Merging query prologs that both declare $foo; copy-paste of variable blocks; renaming a variable to a name that already exists in the prolog.","solutions":["Rename one of the duplicated variable declarations.","Remove the leftover declaration after merging prologs.","If the variables live in different modules, give each module's variable its module-namespace-prefixed name so the expanded QNames differ."],"exampleFix":"// before\ndeclare variable $max as xs:int := 10;\ndeclare variable $max as xs:int := 99;\n\n// after\ndeclare variable $max as xs:int := 10;\ndeclare variable $limit as xs:int := 99;","handlingStrategy":"validation","validationCode":"// Detect duplicate declared variable QNames before analysis\nvar seen = {};\nvarDecls.forEach(function(d) {\n  var key = d.uri + '#' + d.name;\n  if (seen[key]) { warn('Duplicate variable $' + d.name); }\n  seen[key] = true;\n});","typeGuard":null,"tryCatchPattern":"if (e.code === 'XQST0049') {\n  highlight(e.pos, 'Rename one of the duplicate variable declarations');\n}","preventionTips":["After merging prologs, scan for repeated 'declare variable $name' entries.","Use distinct, descriptive variable names rather than generic $tmp/$result repeated in blocks."],"tags":["xquery","variable-declaration","duplicate"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}