Skip to content

Fix FS1182 not reported for unused let functions in class types#19805

Open
T-Gro wants to merge 3 commits into
mainfrom
fix/issue-13849
Open

Fix FS1182 not reported for unused let functions in class types#19805
T-Gro wants to merge 3 commits into
mainfrom
fix/issue-13849

Conversation

@T-Gro
Copy link
Copy Markdown
Member

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

Summary

Fix #13849: FS1182 ("unused binding") warning was not reported for unused let function bindings inside class types.

Problem

Class-let function bindings are promoted to compiler-generated members, which sets IsCompiledAsTopLevel=true. The reportIfUnused helper in CheckIncrementalClasses.IncrClassReprInfo.ChooseRepresentation had a not v.IsCompiledAsTopLevel guard that silently suppressed FS1182 for these bindings.

Fix

Removed the not v.IsCompiledAsTopLevel guard from the local reportIfUnused helper. This helper is scoped to class-binding representation choice, so the change cannot introduce module-level false positives.

Test

Added test cases in tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/warnon/warnon.fs verifying that FS1182 is correctly emitted for unused let functions in class types.

Fixes #13849

T-Gro and others added 2 commits May 25, 2026 21:20
Removed the 'not v.IsCompiledAsTopLevel' guard in the local 'reportIfUnused' helper inside CheckIncrementalClasses.IncrClassReprInfo.ChooseRepresentation. Class-let function bindings are promoted to compiler-generated members, which sets IsCompiledAsTopLevel=true and previously silently suppressed FS1182. The helper is local to class-binding representation choice, so this change cannot introduce module-level false positives.

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

❗ Release notes required


✅ Found changes and release notes in following paths:

Warning

No PR link found in some release notes, please consider adding it.

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/11.0.100.md No current pull request URL (#19805) found, please consider adding it

@github-actions github-actions Bot added the AI-Tooling-Check-Bypassed Tooling check: non-fork PR, not diff-analyzed label May 25, 2026
Copy link
Copy Markdown
Member Author

@T-Gro T-Gro left a comment

Choose a reason for hiding this comment

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

Review Summary

Looks good — Clean, well-scoped fix with thorough test coverage.

Analysis

The root cause is correctly identified: class let-functions are promoted to compiler-generated members via AdjustValToHaveValReprInfo (line 370), which sets ValReprInfo, making IsCompiledAsTopLevel = true. The old not v.IsCompiledAsTopLevel guard in reportIfUnused() then silently suppressed FS1182 for all class let-functions.

Why the fix is safe:

  1. No module-level false positivesreportIfUnused() is local to IncrClassReprInfo.ChooseRepresentation, which only processes class-level bindings. Module-level bindings go through PostInferenceChecks.BindVal which has its own independent IsCompiledAsTopLevel guard (line 315 in PostInferenceChecks.fs).

  2. No duplicate warnings — After AdjustValToHaveValReprInfo runs, the class let-function has IsCompiledAsTopLevel = true, so PostInferenceChecks.BindVal won't also emit FS1182 (its condition not v.IsCompiledAsTopLevel || topLevelBindingHiddenBySignatureFile() evaluates to false for class let-functions that aren't module bindings).

  3. HasBeenReferenced is reliable — This flag is set during type-checking when the value is referenced, and applies uniformly to let-values and let-functions.

Tests

Excellent coverage:

  • RED tests pin the bug fix (unused let-function variants, mixed used/unused, static let-function)
  • GUARD tests prevent regressions (used functions, recursive self-reference, module-level, underscore-prefixed)

Minor

The release notes entry should include the PR link (as noted by the bot): [PR #19805](https://github.com/dotnet/fsharp/pull/19805).

@T-Gro T-Gro added the AI-reviewed PR reviewed by AI review council label May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-reviewed PR reviewed by AI review council AI-Tooling-Check-Bypassed Tooling check: non-fork PR, not diff-analyzed

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

Unused binding warning isn't reported for recursive binding in a type

1 participant