Skip to content

Nullness issue - units of measure don't work with nullables #19657

@Lanayx

Description

@Lanayx

Issue description

I expect string-based measure types (for example using Fsharp.UMX library) to work with null, however it doesn't work.
Linked issue: fsprojects/FSharp.UMX#33

Choose one or more from the following categories of impact

  • Unexpected nullness warning (false positive in nullness checking, code uses --checknulls and langversion:preview).
  • Missing nullness warning in a case which can produce nulls (false negative, code uses --checknulls and langversion:preview).
  • Breaking change related to older null constructs in code not using the checknulls switch.
  • Breaking change related to generic code and explicit type constraints (null, not null).
  • Type inference issue (i.e. code worked without type annotations before, and applying the --checknulls enforces type annotations).
  • C#/F# interop issue related to nullness metadata.
  • Other (none of the categories above apply).

Operating System

Windows (Default)

What .NET runtime/SDK kind are you seeing the issue on

.NET SDK 10.0.202

.NET Runtime/SDK version

No response

Reproducible code snippet and actual behavior

module Program

[<MeasureAnnotatedAbbreviation>] type string<[<Measure>] 'm> = string
[<Measure>] type private test
type TestType = string<test>

[<EntryPoint>]
let main _ = 
    let x: (TestType | null) = Unchecked.defaultof<TestType>
    0

Produces error
Error FS0043 : A generic construct requires that the type 'TestType' have reference semantics, but it does not, i.e. it is a struct

Possible workarounds

There is no workaround

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

Status

New

Relationships

None yet

Development

No branches or pull requests

Issue actions