F# compiler internal error FS0073 when merging duplicate property accessors for interface/class property implementation
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
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/fsharp
-
Needs-Triage
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
Bug Needs-Triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Needs-Triage
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Needs-Triage
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Needs-Triage
Difficulty 5/5 Over a week Newbie friendliness 48/100
Similar issues
-
compiler/runtime
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
objectionary/eo#8869 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
EricSpencer00/Resilient#4824 · 1 comment ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
objectionary/jeo-maven-plugin#1758 ·
-
generics
Difficulty 2/5 1-3 hours Newbie friendliness 82/100