{"record":{"id":"f2fa68c4d5dc4ed5","repo":"oracle/graal","slug":"captured-node-s-has-differing-types","errorCode":null,"errorMessage":"Captured node \"%s\" has differing types","messagePattern":"Captured node \"(.+?)\" has differing types","errorType":"validation","errorClass":"RuleParseError","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler.processor/src/jdk/graal/compiler/core/match/processor/MatchProcessor.java","lineNumber":209,"sourceCode":"                    next();\n                    name = next();\n                }\n                originatingElements.addAll(type.originatingElements);\n            } else if (Character.isLowerCase(peek(\"name\").charAt(0))) {\n                name = next();\n                type = valueType;\n            } else {\n                throw new RuleParseError(\"Unexpected token \\\"%s\\\" when looking for name or node type\", peek(null));\n            }\n            requiredPackages.add(type.nodePackage);\n            if (name != null) {\n                if (!capturedNames.contains(name)) {\n                    capturedNames.add(name);\n                    capturedTypes.add(type);\n                } else {\n                    int index = capturedNames.indexOf(name);\n                    if (capturedTypes.get(index) != type) {\n                        throw new RuleParseError(\"Captured node \\\"%s\\\" has differing types\", name);\n                    }\n                }\n            }\n            return new MatchDescriptor(type, name, forExpression);\n        }\n\n        List<String> generateVariants() {\n            return matchDescriptor.generateVariants();\n        }\n\n        /**\n         * Recursively accumulate any required Position declarations.\n         */\n        void generatePositionDeclarations(Set<String> declarations) {\n            matchDescriptor.generatePositionDeclarations(declarations);\n        }\n\n        /**","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler.processor/src/jdk/graal/compiler/core/match/processor/MatchProcessor.java#L191-L227","documentation":"Thrown by RuleParser.parseType when the same captured name (lowercase identifier after '=') is bound to two different node types within one rule. Captured names are how a @MatchRule communicates matched nodes to the generated method parameters, so one name must consistently denote one type; reusing it for a different node type is rejected.","triggerScenarios":"A rule like \"Add(x = value, Mul(x = other))\" where 'x' binds first to an Add input type and then to a Mul type differing by reference equality (capturedTypes.get(index) != type). Note the check is exact TypeDescriptor identity, not name compatibility.","commonSituations":"Copy-pasting a sub-pattern and forgetting to rename its capture; rules grown organically where 'x'/'y' get reused; introducing a new sub-match that accidentally reuses an existing short name with a different node type.","solutions":["Rename one of the captures so each name maps to exactly one node type (x = a, x = b).","If both captures genuinely refer to the same node position, bind the name once and reuse it only for the identical type.","Adopt unique, descriptive capture names per rule to avoid collisions."],"exampleFix":"// before\n@MatchRule(\"Add(x = v, Mul(x = w))\")\n\n// after\n@MatchRule(\"Add(x = v, Mul(y = w))\")","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"Compile-time only; the diagnostic names the conflicting capture. No runtime handling possible.","preventionTips":["Give each captured name in a rule a unique, descriptive identifier.","Never reuse a short capture name for a different node type within one rule.","When copy-pasting sub-patterns, rename captures as you paste."],"tags":["graalvm","match-rules","annotation-processing","naming","compile-time"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}