Skip to content

Fix #7776: Detect missing implementations for C# 'abstract override' methods#19503

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-9141961-29048891-e5251906-967f-417d-825d-702105d947cd
Draft

Fix #7776: Detect missing implementations for C# 'abstract override' methods#19503
Copilot wants to merge 3 commits intomainfrom
copilot/fix-9141961-29048891-e5251906-967f-417d-825d-702105d947cd

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 26, 2026

The F# compiler did not report an error when a non-abstract F# class inherited from a C# class with abstract override members (e.g., public abstract override string ToString()) without providing implementations. This caused a TypeLoadException at runtime with no compile-time warning.

Root Cause

The IgnoreOverrides filter in InfoReader.FilterOverrides was incorrectly removing C# abstract override methods from the method set. These methods have IL flags Abstract=true, Virtual=true, NewSlot=false, and the filter treated them as equivalent to the base virtual method they re-abstract (e.g., Object.ToString()), discarding them. This caused GetClassDispatchSlots to only see the original non-abstract base method, which was marked as "optional" (already has an implementation), so no FS0365 error was reported.

Fix

Added an isAbstract parameter to the FilterOverrides function in InfoReader.fs. In the IgnoreOverrides path, abstract methods from derived types are now preserved even when they're signature-equivalent to virtual methods in supertypes. This ensures GetClassDispatchSlots correctly identifies abstract override methods as required (non-optional) dispatch slots.

Changes

  • src/Compiler/Checking/InfoReader.fs: Added isAbstract to FilterOverrides parameter tuple and the IgnoreOverrides keepTest condition so abstract re-declarations are not filtered out.
  • tests/.../AbstractMembers/AbstractMembers.fs: Added 6 regression tests covering: missing implementation error for abstract override ToString(), missing implementation for custom abstract override method, successful compilation when implementation is provided, abstract F# subclass allowed without implementation, and object expression with implementation.
  • docs/release-notes/.FSharp.Compiler.Service/11.0.100.md: Added release note.

Testing

  • All 6 new regression tests pass
  • 2871 Conformance tests: 0 failures
  • 250 OO type definition tests: 0 failures
  • 97 Interop tests: 0 failures

💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

@T-Gro
Copy link
Copy Markdown
Member

T-Gro commented Mar 27, 2026

@copilot : Try again

@T-Gro
Copy link
Copy Markdown
Member

T-Gro commented Mar 27, 2026

@copilot : Try again.

@abonie
Copy link
Copy Markdown
Member

abonie commented Mar 31, 2026

@copilot Try again

Copilot AI and others added 2 commits March 31, 2026 14:26
…methods

The IgnoreOverrides filter in InfoReader.fs incorrectly removed abstract
override methods (e.g. C# 'abstract override string ToString()') because
they were signature-equivalent to the base virtual method. This caused
GetClassDispatchSlots to miss these as required dispatch slots.

The fix adds an isAbstract check to the FilterOverrides function so that
abstract methods from derived types are preserved even when they override
an equivalent virtual in a supertype. This ensures the compiler correctly
reports FS0365 when a non-abstract F# class inherits from a C# class with
abstract override members without providing implementations.

Agent-Logs-Url: https://github.com/dotnet/fsharp/sessions/1d6d6e17-b57c-435f-b144-0d3146d9cbd8

Co-authored-by: abonie <20281641+abonie@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 31, 2026

@copilot Try again

Implemented the fix in commit ab7b03c.

Root cause: The IgnoreOverrides filter in InfoReader.FilterOverrides was removing C# abstract override methods because they're signature-equivalent to the base virtual they re-abstract. This caused GetClassDispatchSlots to miss them as required dispatch slots.

Fix: Added an isAbstract check to the FilterOverrides keepTest so abstract methods from derived types are preserved. This ensures GetClassDispatchSlots correctly identifies them as required (non-optional) dispatch slots, and the compiler reports FS0365.

6 regression tests added, all 2871 Conformance tests pass with 0 regressions.

Copilot AI changed the title [WIP] Copilot Request Fix #7776: Detect missing implementations for C# 'abstract override' methods Mar 31, 2026
Copilot AI requested a review from abonie March 31, 2026 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

3 participants