Skip to content

NullReferenceException breaks IDE syntax coloring on unlinked placeholder entities (e.g. broken code mid-edit) #20269

Description

@xperiandri

Succinct description:
NullReferenceException (NRE) in TypedTree during semantic classification crashes entire document coloring in F# IDE/LSP/VS Code/VS.

Root cause: Mid-edit broken/unresolved symbols → null entity_modul_type / Entity (unlinked placeholders). Derefs like entity_modul_type.Force() / entity.DisplayName → NRE → full pipeline crash.

Fix ready in staged changes: Defensive null-guards + comments in TypedTree.Construct.NewModified*, FreeVars etc. Partial classification survives.
See detailed doc, #20269.

Repro steps

  1. VS/VS Code: New F# file (*.fs).
type Foo =  // Delete 'type' → unresolved
  member x.Bar = ()
  1. Save → trigger typecheck/classification (edit/save).
  2. Observe: Entire file loses semantic colors (keywords gray, no blue types/keywords).

Pre-fix: NRE in VS Output (F#) / VS Code DevTools Console (LSP).

Expected behavior

Partial/resilient classification:

  • Valid code: Full semantic colors (blue types, green keywords).
  • Broken symbol: Isolated error (gray/underline), rest intact.

Actual behavior

NRE propagates:

TypedTree.fs / TypedTreeOps.Remapping.fs → entity_modul_type.Force() → NRE  
↑  
LanguageService.fs → DocumentCache.fs → classification crash  
↓  
LSP: semanticTokens/full → empty → no colors for whole file

UX: Plain syntax-only text mid-edit.

Known workarounds

  • Fix broken symbol immediately.
  • Restart IDE / Reload VS Code window (Ctrl+Shift+P > "Developer: Reload Window").
  • Disable semantic highlighting (VS Code: fsharp.semanticHighlighting.enabled: false).

Related information

  • OS: Windows (tested; likely cross-platform).
  • .NET Runtime: net9.0 (F# compiler).
  • Editing Tools:
    • Visual Studio 17.12+ (F# workload).
    • VS Code + F# extension (LSP).

Staged fix files (git diff --staged):

M src/Compiler/TypedTree/TypedTree.fs          // Null-guards + comments
M src/Compiler/TypedTree/TypedTree.fsi         // Sigs
M src/Compiler/TypedTree/TypedTreeOps.Remapping.fs
M src/Compiler/Utilities/lib.fs
M vsintegration/src/FSharp.Editor/*            // LS/cache resilience

Validation: ./build.sh -c Release --testcoreclr clean. IDE resilient.
Commit: Fix NRE in TypedTree: resilient IDE classification (#20269)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status
    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions