Skip to content

Instantly share code, notes, and snippets.

@mfelsche
Last active April 10, 2017 07:11
Show Gist options
  • Save mfelsche/75f131df83d2546d25128ba4bc2f201e to your computer and use it in GitHub Desktop.
Save mfelsche/75f131df83d2546d25128ba4bc2f201e to your computer and use it in GitHub Desktop.
Array Literal Types in Pony
type MyUnionType is (U32|I32|U8)
actor Main
new create(env: Env) =>
let union_array: Array[MyUnionType] = [
as MyUnionType: U32(1)
I32(-1)
]
$ CC=gcc ponyc --debug .
Building builtin -> /usr/lib/pony/0.12.3-3147.5a68e92/packages/builtin
Building . -> /home/mwahl/dev/pony/arrays
Error:
/home/mwahl/dev/pony/arrays/arrays.pony:5:41: right side must be a subtype of left side
let union_array: Array[MyUnionType] = [
^
Info:
/home/mwahl/dev/pony/arrays/arrays.pony:1:30: U8 val is not a subtype of U32 val
type MyUnionType is (U32|I32|U8)
^
/home/mwahl/dev/pony/arrays/arrays.pony:1:30: U8 val is not a subtype of I32 val
type MyUnionType is (U32|I32|U8)
^
/home/mwahl/dev/pony/arrays/arrays.pony:1:30: U8 val is not a subtype of any element of (U32 val | I32 val)
type MyUnionType is (U32|I32|U8)
^
/home/mwahl/dev/pony/arrays/arrays.pony:1:30: not every element of (U32 val | I32 val | U8 val) is a subtype of (U32 val | I32 val)
type MyUnionType is (U32|I32|U8)
^
/usr/lib/pony/0.12.3-3147.5a68e92/packages/builtin/array.pony:9:3: Array[(U32 val | I32 val)] ref has different type arguments than Array[(U32 val | I32 val | U8 val)] ref
new create(len: USize = 0) =>
^
@mfelsche
Copy link
Author

mfelsche commented Apr 8, 2017

To me it seems that Array[(I32|U32)], the type of the array literal, actually is a subtype of the variable type Array[MyUnionType] -> Array[(I32IU32IU8)]. In other words, the array literal seems to fulfil the constraints given by the variable type it is assigned to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment