Skip to content

Supertype patterns silently never match — reject them until implemented #417

Description

@zharinov

Problem

Tree-sitter grammars define supertypes — abstract categories like statement in JavaScript that group concrete node kinds (lexical_declaration, expression_statement, …). Tree-sitter never produces a node whose kind is the supertype itself, so a pattern like (statement) can never match anything. Plotnik currently accepts such patterns and emits bytecode that silently never matches:

cargo run -p plotnik -- run -q 'Q = (program (statement)* @s)' -s 'let x;' -l javascript
# → {"s":[]}, exit 0   (silently empty — the worst failure mode)

The narrowing syntax — native (statement#lexical_declaration) and the deprecated tree-sitter (statement/lexical_declaration) — parses and type-checks, but the subtype is recorded in the CST and then dropped: the pattern collapses to the bare supertype and silently never matches either. (The syntax has landed; semantics are deliberately deferred to this issue and #423.)

Approach (interim — fail loudly)

This issue is NOT about implementing supertypes (see #423). The goal is to convert the silent no-match into an error so the feature can be safely postponed:

  • At analyze/link time, when a named node's kind resolves to a supertype of the linked grammar, emit a diagnostic: the supertype name, a note that supertype patterns are not yet supported, and a suggestion to list concrete kinds in an alternation instead. When a subtype refinement is present in the CST, name it in the message.
  • This fires for all three spellings: (statement), native (statement#lexical_declaration), and deprecated (statement/lexical_declaration) — they share one AST (subtype ignored). The / form additionally still emits its parser deprecation warning; the link-time rejection stacks on top.
  • The grammar side already has the data: Grammar::subtypes() exists in plotnik-core (currently zero consumers).
  • Diagnostics live in crates/plotnik-compiler/src/diagnostics/; resolution happens in crates/plotnik-compiler/src/analyze/link.rs.

Acceptance

  • check fails with the diagnostic for (statement), (statement#...), and (statement/...) on linked queries.
  • The run repro above becomes a compile-time error instead of {"s":[]}.
  • Unlinked compilation (no -l) is unaffected — supertypes are a grammar concept; without a grammar there is nothing to resolve against. The parser-level /# deprecation warning still applies unlinked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions