dotnet / dotnet/fsharp

Recursive type with a legal Zero value fails to compile

Open
#12,379 1 comment 0 reactions 0 assignees View on GitHub
Area-Compiler-Checking Area-Compiler-SRTP Bug Impact-Low
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

Consider the following code:

```fsharp
type Foo<'t when 't : (static member Zero : 't)> =
| MkFoo of 't

type Bar =
| Nil
| MkBar of Foo // Error: The type 'Bar' does not support the operator 'get_Zero'

static member Zero
with get () = Nil

let zeroBar = LanguagePrimitives.GenericZero // this compiles fine, so Bar definitely has a legal Zero value
```

**Expected behavior**

Should compile with no problems.

**Actual behavior**

Compiler error: `The type 'Bar' does not support the operator 'get_Zero'`

**Known workarounds**

None

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.