F# compiler internal error FS0073 when merging duplicate property accessors for interface/class property implementation

Open Beginner friendly
#20,265 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
fsharp
Domain
compilers

Research direction

Start in src/Compiler/CodeGen/IlxGen.fs by reading MergeOptions and the surrounding property-merging logic. Add the suggested regression test for the class and interface property implementation, then run it to confirm the code compiles without FS0073.

Written by the indexing model from the issue text.

Description

Needs-Triage

Summary

The F# compiler can emit an internal compiler error (FS0073) in debug builds when a property is implemented both as a normal class member and as an explicit interface implementation of the same property signature.

The failure is not caused by user code; it is caused by a debug-only assertion in IL generation.

Repro

module Test

type IValue =
    abstract Value: int with get

type Value() =
    member _.Value = 1
    interface IValue with
        member _.Value = 1

Compiling this code can fail with:

error FS0073: internal error: MergeOptions: two values given

with a source span on the property implementation line.

Root cause

The bug is in the IL property merging logic in src/Compiler/CodeGen/IlxGen.fs.

let MergeOptions m o1 o2 =
    match o1, o2 with
    | Some x, None
    | None, Some x -> Some x
    | None, None -> None
    | Some x, Some _ ->
#if DEBUG
        errorR (InternalError("MergeOptions: two values given", m))
#else
        ignore m
#endif
        Some x

This function is used when multiple property definitions with the same name/signature are merged. In this scenario, a valid implementation can legitimately contain both a regular property accessor and an interface-implementation accessor for the same property. The merge is legal and should not be treated as a compiler-internal invariant violation.

Why this is a compiler bug

The code path is handling a valid property shape produced by the compiler itself. The debug-only assertion is effectively turning a legal merge into an internal error. This is a false-positive FS0073.

Expected behavior

The compiler should compile the code successfully, because the merge of duplicate property accessors is semantically redundant and harmless.

Proposed fix

Treat duplicate values as idempotent during merge, not as an internal error.

Minimal fix:

let MergeOptions _m o1 o2 =
    match o1, o2 with
    | Some x, None
    | None, Some x -> Some x
    | None, None -> None
    | Some x, Some _ -> Some x

This preserves the existing value and avoids crashing the compiler while still allowing the property merge logic to complete.

Additional context

This is particularly easy to trigger in debug builds because the assertion is compiled only inside #if DEBUG, but the underlying bug is still present in the merge semantics itself. The correct behavior is to merge duplicate accessors instead of raising an internal error.

Suggested regression test

[<Fact>]
let ``Property implementation can merge interface and class accessors`` () =
    FSharp
        """
        module Test

        type IValue =
            abstract Value: int with get

        type Value() =
            member _.Value = 1
            interface IValue with
                member _.Value = 1
        """
    |> compileAssembly
    |> ignore

This should compile without FS0073.

Dominant language
F#
Stars
4.3k
Forks
877
Avg merge
6d 5h
Merged PRs (30d)
163

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/fsharp

All issues in dotnet/fsharp

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.