Last active
April 10, 2017 07:11
-
-
Save mfelsche/75f131df83d2546d25128ba4bc2f201e to your computer and use it in GitHub Desktop.
Array Literal Types in Pony
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type MyUnionType is (U32|I32|U8) | |
actor Main | |
new create(env: Env) => | |
let union_array: Array[MyUnionType] = [ | |
as MyUnionType: U32(1) | |
I32(-1) | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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) => | |
^ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To me it seems that
Array[(I32|U32)]
, the type of the array literal, actually is a subtype of the variable typeArray[MyUnionType] -> Array[(I32IU32IU8)]
. In other words, the array literal seems to fulfil the constraints given by the variable type it is assigned to.