`NullReferenceException` breaks IDE syntax coloring on unlinked placeholder entities (e.g. broken code mid-edit)
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 22h
- Merged PRs (30d)
- 144
Description
**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](NullRef-TypedTree-Classification-Fix.md), [#20269](https://github.com/dotnet/fsharp/issues/20269).
**Repro steps**
1. VS/VS Code: New F# file (`*.fs`).
```
type Foo = // Delete 'type' → unresolved
member x.Bar = ()
```
2. Save → trigger typecheck/classification (edit/save).
3. **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)`
Contributor guide
Research direction
Start with the staged changes in src/Compiler/TypedTree/TypedTree.fs, TypedTree.fsi, TypedTreeOps.Remapping.fs, Utilities/lib.fs, and the vsintegration/src/FSharp.Editor files, then reproduce the broken F# file and inspect the classification path. Run ./build.sh -c Release --testcoreclr; done means broken symbols no longer remove coloring from the rest of the document and the validation remains clean.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fsharp
- Domain
- compilers, developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100