Skip to content

fix: preserve switch diagnostic type casing - W-24796367 - #836

Open
peternhale wants to merge 2 commits into
ph/W-24799682-fix-invocation-result-targetsfrom
ph/W-24796367-switch-diagnostic-type-casing
Open

peternhale wants to merge 2 commits into
ph/W-24799682-fix-invocation-result-targetsfrom
ph/W-24796367-switch-diagnostic-type-casing

Conversation

@peternhale

@peternhale peternhale commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Preserves Apex/Jorje type-name casing in switch diagnostics while retaining normalized type names for semantic comparisons.

  • Uses parser and symbol type spelling when it is available.
  • Canonicalizes parser-derived intrinsic types such as Integer, String, and Id for diagnostic display.
  • Adds exact-message regressions for unsupported switch expressions and incompatible when expression types.

What issues does this PR fix or reference?

@W-24796367@

Test Plan

  • pnpm exec vitest run packages/apex-parser-ast/test/semantics/validation/validators/SwitchStatementValidator.test.ts --reporter=default
    • 24 passed
  • pnpm --filter @salesforce/apex-lsp-parser-ast run lint
  • pnpm --filter @salesforce/apex-lsp-parser-ast run test
    • 2,821 passed, 446 skipped

@peternhale
peternhale added this pull request to stack #818 November 16, 2026 18:10
@peternhale peternhale changed the title ph/W 24796367 switch diagnostic type casing fix: preserve switch diagnostic type casing - W-24796367 Nov 16, 2026
@peternhale
peternhale marked this pull request as ready for review November 16, 2026 18:25
@peternhale
peternhale requested a review from a team as a code owner November 16, 2026 18:25
@peternhale
peternhale requested a review from mshanemc November 16, 2026 18:25
@peternhale
peternhale force-pushed the ph/W-24796367-switch-diagnostic-type-casing branch from 3d8b6b5 to a30b11a Compare November 16, 2026 18:25
@github-actions

Copy link
Copy Markdown
Contributor

E2E Test Results Summary

Run: 2227

Test Results

  • Passed: 85
  • Failed: 1
  • Errors: 1
  • Total: 87

Passing Rate by File

  • apex-extension-core.spec.ts/junit.xml: 100.0% (1/1 passed)
  • apex-extract-constant.spec.ts/junit.xml: 100.0% (1/1 passed)
  • apex-hover.spec.ts/junit.xml: 100.0% (21/21 passed)
  • apex-extract-variable.spec.ts/junit.xml: 100.0% (3/3 passed)
  • apex-goto-definition.spec.ts/junit.xml: 100.0% (20/20 passed)
  • apex-hover-stdlib.spec.ts/junit.xml: 0.0% (0/1 passed)
  • apex-outline.spec.ts/junit.xml: 100.0% (11/11 passed)
  • apex-goto-definition-advanced.spec.ts/junit.xml: 87.5% (7/8 passed)
  • apex-lsp-integration.spec.ts/junit.xml: 100.0% (16/16 passed)
  • apex-rename-symbol.spec.ts/junit.xml: 100.0% (2/2 passed)
  • apex-capability-gating.spec.ts/junit.xml: 100.0% (3/3 passed)

Artifacts

View detailed test reports in the Artifacts section.

Some tests failed

@madhur310 madhur310 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix — the displayType split cleanly separates the case-insensitive comparison path from diagnostic rendering, and the new exact-message tests lock in the expected output.

One minor gap worth a follow-up: canonicalization is inconsistent depending on how the type was resolved.

  • Literal when-values always go through literalTypeDisplay (SwitchStatementValidator.ts:315), so 123 renders as Integer regardless of source casing.
  • Identifier/variable-resolved types (resolveIdentifierType, SwitchStatementValidator.ts:293-312) and the semanticType branch of switchTypeDisplay (SwitchStatementValidator.ts:319-324) just echo symbol.type.originalTypeString/semanticType.originalTypeString verbatim.

Since Apex primitive keywords are case-insensitive, a declaration like public static final integer MY_CONST = 1; (lowercase integer) used in a when/switch expression will still render as "integer" in the diagnostic rather than "Integer" — which seems to contradict the PR description's second bullet about canonicalizing intrinsic types for display. Not a functional bug (comparisons are unaffected), just an inconsistency in the cosmetic casing fix. No test currently exercises a lowercase-declared primitive, so it's easy to miss.

Approving since this is a real improvement and the gap is narrow/cosmetic — happy to see it addressed in a follow-up.

@peternhale
peternhale force-pushed the ph/W-24796367-switch-diagnostic-type-casing branch 2 times, most recently from 7af589f to ba672dd Compare November 17, 2026 15:48
@peternhale
peternhale force-pushed the ph/W-24796367-switch-diagnostic-type-casing branch from 43762aa to 749a3c1 Compare November 18, 2026 13:35

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants