The following program:
class box B
class box A
let bs: Array[B] = Array[B]
new create(bs': Array[B box] box) =>
bs.append(bs')
actor Main
new create(env: Env) =>
let bs: Array[B val] trn = [ recover B end ]
let bs': Array[B val] val = consume bs
let a = A(bs')
env.out.print("done")
https://playground.ponylang.io/?gist=5cdad1a2e82f962b034e277e23d1a91f
Produces the errors:
main.pony:14:15: argument not assignable to parameter
let a = A(bs')
^
Info:
main.pony:14:15: argument type is Array[B val] val
let a = A(bs')
^
main.pony:7:14: parameter type requires Array[B box] box^
new create(bs': Array[B box] box) =>
^
main.pony:7:25: B box is not a subtype of B val: box is not a subcap of val
new create(bs': Array[B box] box) =>
^
main.pony:13:14: Array[B val] val has different type arguments than Array[B box] box^
let bs': Array[B val] val = consume bs
^
Where the compiler is not allowing us to pass an Array[B val] to a parameter of type Array[B box]. It would be nice to allow covariance for type parameters' capabilities so that we could do this.
The code in question seems to be
|
if(!is_eq_typeargs(sub, super, errorf, opt)) |
; there is some discussion on Zulip:
https://ponylang.zulipchat.com/#narrow/stream/189985-beginner-help/topic/parameter.20subtyping
The following program:
https://playground.ponylang.io/?gist=5cdad1a2e82f962b034e277e23d1a91f
Produces the errors:
Where the compiler is not allowing us to pass an
Array[B val]to a parameter of typeArray[B box]. It would be nice to allow covariance for type parameters' capabilities so that we could do this.The code in question seems to be
ponyc/src/libponyc/type/subtype.c
Line 836 in cb2f814