Open
Description
Given the following examples I can't quite figure out what the compiler is doing here.
type InnerRecord = { Id: int }
[<Struct>]
type StructRecord = { Value: obj }
// Ok
let nullable = Nullable({Value = 1 })
[<Struct>]
type StructRecord2 = { Value: InnerRecord }
// A generic construct requires that the type 'StructRecord2' have a public default constructor
let nullable = Nullable({Value = { Id = 1 }})
[<Struct>]
type StructType(value: obj) =
member _.Value = value
// Ok
let nullable = Nullable(StructType(1))
[<Struct>]
type StructType2(value: InnerRecord) =
member _.Value = value
// A generic construct requires that the type 'StructType2' have a public default constructor
let nullable = Nullable(StructType2({ Id = 1 }))
[<Struct>]
type StructType3(value: StructType) =
member _.Value = value
// Ok
let nullable = Nullable(StructType3(StructType()))
[<Struct>]
type InnerStructRecord = { Id: int }
[<Struct>]
type StructType4(value: InnerStructRecord) =
member _.Value = value
// Ok
let nullable = Nullable(StructType4({ Id = 1 }))
Why specifically is it not allowed to store a struct that has a reference type record as one of its fields? (And then secondly, if it is expected behavior the error is supremely unhelpful in figuring this out)
This issue seems related to a previous issue #7946 (comment) but the linked explanation reads like it should only apply to generic structs.
Metadata
Metadata
Assignees
Type
Projects
Status
In Progress