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
When creating a static array with StaticArray.[] macro, the generic element type argument is inferred from the union of all macro argument types. However, there might be use-cases where the element type of the static array differs from the union of it's initial elements. This cannot be expressed using the [] macro.
As a workaround you need to use one of the constructors and assign the elements manually. It's more verbose but works. I'm not sure if this necessarily needs to change.
StaticArray#to_s and #pretty_print both stringify an instance as StaticArray[<element>] which suggests that this string representation can be used as a literal-like expression in source code representing the exact same value. But this is only the case is if T equals the union of all value types.
At least #pretty_print (and #inspect) should probably be more specific here because inspecting a static array should show the exact type. This could be improved by changing the print output to include T (for example StaticArray(Int32 | Float64)[1, 2, 3]) at least when it differs from the union of element types. However, this won't be usable in Crystal code because it is not a valid expression.
The text was updated successfully, but these errors were encountered:
When creating a static array with
StaticArray.[]
macro, the generic element type argument is inferred from the union of all macro argument types. However, there might be use-cases where the element type of the static array differs from the union of it's initial elements. This cannot be expressed using the[]
macro.As a workaround you need to use one of the constructors and assign the elements manually. It's more verbose but works. I'm not sure if this necessarily needs to change.
StaticArray#to_s
and#pretty_print
both stringify an instance asStaticArray[<element>]
which suggests that this string representation can be used as a literal-like expression in source code representing the exact same value. But this is only the case is ifT
equals the union of all value types.At least
#pretty_print
(and#inspect
) should probably be more specific here because inspecting a static array should show the exact type. This could be improved by changing the print output to includeT
(for exampleStaticArray(Int32 | Float64)[1, 2, 3]
) at least when it differs from the union of element types. However, this won't be usable in Crystal code because it is not a valid expression.The text was updated successfully, but these errors were encountered: