You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
C# immutable collections are useful data types for building truly immutable Bond structs.
Bond doesn't properly support using them as custom type aliases, for the following reasons:
Generated classes always use the new ImmutableX() as the default constructor, but those do not exist for immutable collections; they are instead constructed with the static field ImmutableX<T>.Empty.
Serialization works, but deserialization fails since the compiler assumes that all BT_LIST/BT_SET aliases properly implement ICollection<T>.Add(), but all mutation methods from ICollection<T>throw a NotSupportedException for immutable collections. Same issue with BT_MAP, but with the setter IDictionary<K, V>.Item[].
Based on my initial investigation, the following would need to be done:
Modify the C# compiler to detect immutable collections and use the static field to construct them, rather than a parameterless constructor.
Modify the C# deserializer to specially handle reconstructing immutable collections, either using their builders as an intermediary, using the specific Add methods for the BT_LIST/BT_SET objects, and the SetItem method for the BT_MAP objects.
The text was updated successfully, but these errors were encountered:
C# immutable collections are useful data types for building truly immutable Bond structs.
Bond doesn't properly support using them as custom type aliases, for the following reasons:
new ImmutableX()
as the default constructor, but those do not exist for immutable collections; they are instead constructed with the static fieldImmutableX<T>.Empty
.ICollection<T>.Add()
, but all mutation methods fromICollection<T>
throw a NotSupportedException for immutable collections. Same issue with BT_MAP, but with the setterIDictionary<K, V>.Item[]
.The desired mappings would be:
BT_LIST -> ImmutableArray<T>, ImmutableList<T>
BT_SET -> ImmutableHashSet<T>, ImmutableSortedSet<T>
BT_MAP -> ImmutableDictionary<T>, ImmutableSortedDictionary<T>
Based on my initial investigation, the following would need to be done:
Add
methods for the BT_LIST/BT_SET objects, and theSetItem
method for the BT_MAP objects.The text was updated successfully, but these errors were encountered: