Skip to content

Fix #16432: Report FS0039 only once for undefined type in inherit clause#19862

Open
T-Gro wants to merge 6 commits into
mainfrom
fix/issue-16432
Open

Fix #16432: Report FS0039 only once for undefined type in inherit clause#19862
T-Gro wants to merge 6 commits into
mainfrom
fix/issue-16432

Conversation

@T-Gro
Copy link
Copy Markdown
Member

@T-Gro T-Gro commented May 29, 2026

Summary

Fixes #16432 — When a class inherit clause references an undefined base type, the compiler previously reported FS0039 three times (once for each type-checking pass). This PR deduplicates that diagnostic so only one error is emitted.

Changes

  • src/Compiler/Checking/CheckBasics.fs/.fsi — Added a deduplication set (ReportedInheritUndefinedNames) to the type-checking environment (cenv), tracking (range × idText) pairs that have already been reported.
  • src/Compiler/Checking/CheckDeclarations.fs — Guard Phase 1F inherit type resolution and Phase 2A \Phase2AInherit\ processing so that \UndefinedName\ diagnostics for the same identifier and range are only emitted once.
  • tests/.../InheritsDeclarations.fs — New component tests confirming exactly one FS0039 is reported for single and multiple inherit clauses with undefined types.
  • docs/release-notes — Added entry under \Fixed\ for 11.0.100.

Testing

  • New tests pass verifying a single FS0039 per unique undefined type in inherit clauses.
  • Existing tests remain green.

Copilot and others added 5 commits May 29, 2026 13:15
…f unknown type

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Multiple typecheck passes (EstablishTypeDefinitionCores FirstPass and SecondPass, plus Phase2AInherit's TcType/TcNewExpr) each emit the same FS0039 for an undefined base type in an 'inherit'/'interface inherit' clause, surfacing three identical diagnostics. Introduce a DedupInheritDiagnosticsLogger overlay scoped via UseTransformedDiagnosticsLogger to TcMutRecDefinitions. The dedup key is the formatted message of UndefinedName so duplicate FS0039s for the same identifier collapse to one while unrelated diagnostics, including FS0039 for distinct identifiers, pass through unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds a cenv-scoped `(range, idText)` dedup of `UndefinedName` diagnostics applied around Phase 1F inherit type checking and Phase 2A `Phase2AInherit` processing in CheckDeclarations.fs. Resolves the triple-reporting in #16432 without changing the surface API.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Switch reportedUndefinedNames to ConcurrentDictionary<struct (range * string), unit> for consistency with the sibling argInfoCache field and to be defensive against any future parallel cenv use.

- Forward CheckForRealErrorsIgnoringWarnings to the wrapped logger so the InheritDedupDiagnosticsLogger is a faithful pass-through for everything other than the intended UndefinedName dedup.

- Document the rationale for unwrapping only WrappedError in isDuplicateUndefinedName.

Expert reviewer item 1 (merging suggestions from later UndefinedName into the first) intentionally not applied: in the inherit-clause case the colliding diagnostics carry identical suggestion sets, and merging would couple this site to NameResolution.AddResults internals.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 29, 2026

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/11.0.100.md

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment on lines +56 to +58
type private InheritDedupDiagnosticsLogger
(seen: ConcurrentDictionary<struct (range * string), unit>, inner: DiagnosticsLogger) =
inherit DiagnosticsLogger("InheritDedupDiagnosticsLogger")
Copy link
Copy Markdown
Member

@auduchinok auduchinok May 29, 2026

Choose a reason for hiding this comment

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

@T-Gro Can we find out why the error is reported twice in the first place? It should probably not be raised/committed multiple times, and the results should flow between the stages?

@github-actions github-actions Bot added the AI-Tooling-Check-Scanned-Clean Tooling check: diff analyzed, no interesting infrastructure files label May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-Tooling-Check-Scanned-Clean Tooling check: diff analyzed, no interesting infrastructure files

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

Unresolved name error in 'inherit' member reported multiple times

3 participants