{
  "slug": "semgrep-matches-class-names-for-metavariable-type-checks-ecc3c81a85d4",
  "title": "Semgrep matches class names for metavariable-type checks",
  "tools": [
    "semgrep"
  ],
  "tags": [
    "agent"
  ],
  "introduced_at": "2026-03-31T22:51:26.000Z",
  "announced_at": "2026-03-31T22:51:26.000Z",
  "effective_at": null,
  "date_basis": "source-publication",
  "status": "unknown",
  "how": {
    "incantation": "When a rule needs to match a class name in a method call and check that name’s type, match `$C.getInstance(...)` and apply `metavariable-type` to `$C`.",
    "examples": [
      "rules:\n  - id: class-name-type-check\n    languages: [java]\n    message: Matched class name with the requested type\n    severity: WARNING\n    patterns:\n      - pattern: $C.getInstance(...)\n      - metavariable-type:\n          metavariable: $C\n          type: <type-expression>",
      "patterns:\n  - pattern: $C.getInstance(...)\n  - metavariable-type:\n      metavariable: $C\n      types:\n        - <type-expression-1>\n        - <type-expression-2>"
    ],
    "gotchas": [
      "Version: 1.157.0",
      "pattern (required): Code expression to match; here `$C.getInstance(...)`.",
      "metavariable-type.metavariable (required): Metavariable whose type is checked; here `$C`.",
      "metavariable-type.type (required): One type expression to check against. Mutually exclusive with `types`.",
      "metavariable-type.types (required): List of type expressions to check against. Mutually exclusive with `type`.",
      "metavariable-type.language: Optional language string in the schema; its effect is not documented in the source inspected.",
      "languages (required): Rule language list; choose the target language for the code being matched."
    ]
  },
  "why_it_matters": "Write a rule that matches a class name in a method call and checks that class's type.",
  "before": "The release note says this match-and-type-check workflow became possible in v1.157.0; it does not specify the prior alternative.",
  "sources": [
    "https://github.com/semgrep/semgrep/releases/tag/v1.157.0",
    "https://github.com/semgrep/semgrep-interfaces/blob/main/rule_schema_v1.yaml",
    "https://docs.semgrep.dev/writing-rules/rule-syntax"
  ],
  "rank": 0.96022,
  "judge": {
    "publish": true,
    "judge_model": "codex-cli/gpt-6-luna+typesafe/jev-1.13.0",
    "prompt_version": "extract-v7+enrich-v2+judge-v2x3+jev-publish-v1"
  },
  "review_state": "approved",
  "provenance": {
    "run_id": "wave2b-20261017",
    "verdict_id": "wave2b-20261017:wave2b-20261017-b61b052141a4d003-1:gate",
    "evidence_hash": "4bec706eeda977e2d14dcdf1a98aadf4c582b7aa0eefafb65c712597f5450fd9"
  },
  "review": {
    "draft_hash": "927574401ea3da73b592c831c2e9112cbe66af5483e2c955229516748501aed1",
    "reviewer": "publication-gate",
    "reviewed_at": "2026-10-07T00:00:00.000Z",
    "decision": "wave2b-20261017:gate",
    "reason": "3 of 3 judge runs approved with p_yes >= 0.9 (mean 0.96 >= 0.9; 2 needed) and Jev gave 0.65 (>= 0.6 needed)."
  }
}
