question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nested reference type record values and nullable constraints

See original GitHub issue

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 https://github.com/dotnet/fsharp/issues/7946#issuecomment-687266672 but the linked explanation reads like it should only apply to generic structs.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
NinoFloriscommented, Jul 12, 2022

Workaround for now shows how busted the compiler behavior is here.

[<Struct>]
type Holder<'T> = Value of 'T
and 't holder = Holder<'t>

type InnerRecord = { Id: int }

[<Struct>]
type StructRecord2 = { Value: InnerRecord holder }
// Ok
let nullable = Nullable({Value = Holder.Value { Id = 1 }}) 

0reactions
dsymecommented, Nov 28, 2022

@NinoFloris Thanks, I’ll take a look

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nullable reference types - specification - C# 9.0 draft ...
This feature specification provides a more complete specification for nullable reference types.
Read more >
BigQuery - Nested and Repeated not allowing to insert Null ...
I have a field with mutiplt Nested and Repeated fields inside it. It is not allowing me to Insert null values or null...
Read more >
Specify nested and repeated columns in table schemas
Nested and repeated schemas are subject to the following limitations: A schema cannot contain more than 15 levels of nested RECORD types. Columns...
Read more >
Constraints on Databricks
Columns nested within array or map types do not accept NOT NULL constraints. See CREATE TABLE [USING] and ALTER TABLE ALTER COLUMN.
Read more >
Considerations for Semi-structured Data Stored in VARIANT
This rule ensures that information is not lost, i.e, the difference between VARIANT “null” values and SQL NULL values is not obfuscated. Elements...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found