Skip to content

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

Merged
T-Gro merged 12 commits into
mainfrom
fix/issue-13849
Jun 12, 2026
Merged

Fix FS1182 not reported for unused let functions in class types#19805
T-Gro merged 12 commits into
mainfrom
fix/issue-13849

Conversation

@T-Gro

Copy link
Copy Markdown
Member

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-Groand 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

github-actionsBot commented May 25, 2026

Copy link
Copy Markdown
Contributor

❗ Release notes required

You can open this PR in browser to add release notes: open in github.dev


✅ Found changes and release notes in following paths:

Change pathRelease notes pathDescription
src/Compilerdocs/release-notes/.FSharp.Compiler.Service/11.0.100.md

@github-actionsgithub-actionsBot added the AI-Tooling-Check-Bypassed Tooling check: non-fork PR, not diff-analyzed label May 25, 2026

@T-GroT-Gro left a comment

Copy link
Copy Markdown
MemberAuthor

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-GroT-Gro added the AI-reviewed PR reviewed by AI review council label May 26, 2026
@T-Gro
T-Gro requested a review from abonieMay 29, 2026 12:02
Copilotand others added 5 commits June 2, 2026 11:10
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Remove unused 'addHash' in FSharpProjectSnapshot (dead code in class)
- Remove unused 'removeImplFilesThatHaveSignatures' in TransparentCompiler
(dead code, only referenced in commented-out line)
- Suppress FS1182 in FSharp.Compiler.Interactive.Settings (empty .txt
resource file generates unreferenced GetStringFunc boilerplate)
- Add #nowarn 1182 to code generator preamble for long-term fix
- Add PR link to release notes entry
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- DependencyManagerInteractiveTests: prefix unused 'getErrors' with '_'
(only referenced in commented-out test)
- FSharpScriptTests: guard 'copyHousingToTemp' with #if NETSTANDARD
(only used inside NETSTANDARD-conditional member)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@T-Gro

T-Gro commented Jun 3, 2026

Copy link
Copy Markdown
MemberAuthor

/azp run fsharp-ci

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@github-actionsgithub-actionsBot added the ⚠️ Affects-Build-Infra Tooling check: PR touches build infrastructure label Jun 3, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Tooling Safety Check — Affects-Build-Infra
Affects-Build-Infra: adds MSBuild property to .fsproj + modifies FSharpEmbedResourceText.fs build task

Generated by PR Tooling Safety Check · opus46 7.5M ·

@T-Gro
T-Gro enabled auto-merge (squash) June 4, 2026 12:10
@github-project-automationgithub-project-automationBot moved this from New to In Progress in F# Compiler and ToolingJun 10, 2026
Copilotand others added 3 commits June 12, 2026 12:56
Address review feedback: remove the unused _getErrors helper function
and the commented-out test that references it, since both have been
dead code for years.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
MSBuild 18.9+ transitively brings System.Resources.Extensions and
System.Text.Json which reference System.ValueTuple 4.0.5.0, conflicting
with the .NET Framework 4.7.2 facade (4.0.2.0). Binding redirects
resolve this at runtime; suppress the build error under /warnaserror.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@T-Gro
T-Gro merged commit 439bfb9 into mainJun 12, 2026
50 checks passed
@github-project-automationgithub-project-automationBot moved this from In Progress to Done in F# Compiler and ToolingJun 12, 2026
T-Gro added a commit that referenced this pull request Jun 12, 2026
Branch was behind main by 7 commits, most notably #19805 (Fix FS1182 not
reported for unused let functions in class types). Diff vs origin/main
was showing #19805's changes as 'reverted' by this branch — pure noise
from stale base. Auto-merge takes main's version for all those files,
shrinking the PR diff by ~110 LOC.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚠️ Affects-Build-InfraTooling check: PR touches build infrastructureAI-reviewedPR reviewed by AI review councilAI-Tooling-Check-BypassedTooling check: non-fork PR, not diff-analyzed

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

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

2 participants

@T-Gro@abonie