tree-sitter/tree-sitter · error · Error
Supertype rule \`${symbol.symbol.name}\` is not defined.
Error message
Supertype rule \`${symbol.symbol.name}\` is not defined. What it means
While mapping the supertypes array, the DSL detects its undefined-rule sentinel: accessing an unknown name on the rule-builder Proxy returns a ReferenceError object that carries the missing rule name on `.symbol.name`, and that name is interpolated into this message. Unlike `inline`, where unknown rules only log warnings, an undefined supertype is a hard error because supertypes shape node visibility in queries.
Source
Thrown at crates/generate/src/dsl.js:450
}).map(symbol => symbol.name);
}
let supertypes = baseGrammar.supertypes;
if (options.supertypes) {
if (typeof options.supertypes !== "function") {
throw new Error("Grammar's 'supertypes' property must be a function.");
}
const baseSupertypeRules = baseGrammar.supertypes.map(sym);
const supertypeRules = options.supertypes.call(ruleBuilder, ruleBuilder, baseSupertypeRules);
if (!Array.isArray(supertypeRules)) {
throw new Error("Grammar's supertypes must be an array of rules.");
}
supertypes = supertypeRules.map(symbol => {
if (symbol.name === 'ReferenceError') {
throw new Error(`Supertype rule \`${symbol.symbol.name}\` is not defined.`);
}
return symbol.name;
});
}
let precedences = baseGrammar.precedences;
if (options.precedences) {
if (typeof options.precedences !== "function") {
throw new Error("Grammar's 'precedences' property must be a function");
}
precedences = options.precedences.call(ruleBuilder, ruleBuilder, baseGrammar.precedences);
if (!Array.isArray(precedences)) {
throw new Error("Grammar's precedences must be an array of arrays of rules.");
}
precedences = precedences.map(list => {
if (!Array.isArray(list)) {
throw new Error("Grammar's precedences must be an array of arrays of rules.");
}View on GitHub (pinned to dff1fd868c)
Solutions
- Read the rule name from the message and compare it letter-by-letter with your `rules` keys.
- Fix the typo, or define the rule in this grammar or in the inherited base.
- Re-run `tree-sitter generate`.
Example fix
// before supertypes: $ => [$.statment] // typo // after supertypes: $ => [$.statement]
Defensive patterns
Strategy: validation
Validate before calling
const SUPER = ['expression', 'type'];
const ruleNames = new Set(Object.keys(rules)); // your rules object literal
for (const name of SUPER) {
if (!ruleNames.has(name)) {
throw new Error(`supertype '${name}' is not defined`);
}
}
// then use: supertypes: $ => SUPER.map(n => $[n]), Prevention
- Define supertype names in one array and reuse it for both rules and the option.
- Grep for stale names after renames.
- Run `tree-sitter generate` in CI.
When it happens
Trigger: `supertypes: $ => [$.statment]` — a typo for `statement`. Referencing a rule that exists only in a grammar that was not inherited with `grammar(base, {...})`.
Common situations: Renaming rules without updating the supertypes list. Dialect grammars assuming a base rule the base grammar never defined.
Related errors
- Grammar's 'word' property must be a valid rule name.
- Grammar's 'supertypes' property must be a function.
- Grammar's supertypes must be an array of rules.
- Invalid alias value ${value}
- Invalid field name '${name}': field names must start with a
AI-assisted analysis of tree-sitter/tree-sitter@dff1fd868c (2026-08-16).
Data as JSON: /api/errors/38a1f51b89a363ad.
Report an issue: GitHub.