ponylang / ponyc

Pony is an open-source, actor-model, capabilities-secure, high performance programming language
http://www.ponylang.io
BSD 2-Clause "Simplified" License
5.73k stars 415 forks source link

union type bug #3543

Open damon-kwok opened 4 years ago

damon-kwok commented 4 years ago
use "collections"

primitive Seqx[A: Seq[B] ref = Array[I32], B: Comparable[B] #read = I32]
  fun each(a: A, f: ({(B)} val | {(B): B} val) ): A^ => a
  fun map(a: A, f: ({(B): B} val | {(USize, B): B} val)): A^ =>  a

primitive Num[A: (Real[A] val & Number) = I32]
  fun print(a: A): A => a

actor Main
  new create(env: Env) =>
    let arr_i: Array[I32] ref = [1; 2; 3]
    Seqx.>map(arr_i, Num~print())   // allow
    //Seqx.each(arr_i, Num~print()) // don't allow
SeanTAllen commented 4 years ago

@damon-kwok please include all the information in the issue rather than referring to Zulip otherwise people will have to refer to the zulip and someone else will have to copy it over. You can provide a link for additional context but enough information to start addressing the issue should be included. This is missing valuable information.

Thanks.

damon-kwok commented 4 years ago

Here are some zulip discussions that may be helpful in analyzing bugs:

@jasoncarr0 To add onto this: it does not work with: fun each(a: A, f: ({(B)} val | {(B): B} val) ): A^ => a but does work with: fun each(a: A, f: ({(B): B} val) ): A^ => a So I think there's an issue with unions here as the former should accept more arguments

@SeanTAllen: Yeah it appears to be a bug with the union type there, as it is rejecting it because it doesnt match one of them, rather than accepting it.