Skip to content

SOSL: WITH SPELL_CORRECTION clause missing from soslClauses — parse failure on valid Apex #145

Closed

Description

@madders26

The soslClauses rule in antlr/ApexParser.g4 does not include the WITH SPELL_CORRECTION clause, so valid Apex containing a SOSL query like:

List<List<SObject>> results = [
    FIND :searchTerm IN ALL FIELDS
    RETURNING Contact(Id, FirstName, LastName)
    WITH SPELL_CORRECTION = true
];

fails to parse:

Syntax error at L:C: no viable alternative at input 'WITH SPELL_CORRECTION'
Syntax error at L:C: extraneous input ']' expecting ';'

WITH SPELL_CORRECTION = { true | false } is a documented SOSL clause (see the SOSL reference, "WITH SPELL_CORRECTION"): it toggles spell-corrected search for the query and is accepted by the platform compiler.

Current soslClauses enumerates WITH DIVISION, WITH DATA CATEGORY, WITH SNIPPET, WITH NETWORK, WITH PRICEBOOKID, and WITH METADATA, but not SPELL_CORRECTION (and, from the same family, WITH HIGHLIGHT appears absent as well — I have only reproduced SPELL_CORRECTION).

Downstream impact: PMD 7.x's Apex module (via Summit AST, which builds on this grammar) reports the whole file as a processing error, so classes using this clause silently contribute zero findings to static analysis. Reproduced with PMD 7.25.0 and 7.26.0; two production classes in our org (3,900+ and 4,300+ lines) are entirely invisible to PMD because of a handful of these clauses. Prior art for the same class of gap: pmd/pmd#5055 (WITH USER_MODE / WITH SYSTEM_MODE in SOSL), pmd/pmd#5163 (toLabel in SOSL).

Happy to provide additional repro detail if useful.

Activity

  1. added a commit that references this issue on Aug 19, 2026
    7cd3451
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions