>>val () = !e.e_remote := so The original linear content in !e.e_remote is discarded, resulting in a leak. Also, 'so' is a pointer (instead of a sockaddr).
On Sun, Apr 4, 2021 at 1:33 AM Kiwamu Okabe <kiw...@debian.or.jp> wrote: > I think I miss-undertood datavtype. > In this case, it doesn't need to depend to int. > > Following is a more simple version: > > ```ats > #include "share/atspre_define.hats" > #include "share/atspre_staload.hats" > > typedef sockaddr_in = @{ > sin_port = int, > sin_addr = int, > sin_zero = int > } > > typedef sockaddr_in6 = @{ > sin6_port = int, > sin6_flowinfo = int, > sin6_addr = int, > sin6_scope_id = int > } > > datavtype sockaddr = > | Af_inet of sockaddr_in > | Af_inet6 of sockaddr_in6 > > vtypedef wg_endpoint = @{ > e_remote = sockaddr > } > > fun wg_input > {l1,l2:addr} > (pfe: !wg_endpoint@l1, pfso: !sockaddr@l2 | e: ptr l1, so: ptr l2): > void = let > val () = !e.e_remote := so > in > () > end > > implement main0 () = { > var e: wg_endpoint > var so: sockaddr > prval pre = view@e > prval prso = view@so > // val () = wg_input(pre, prso | e, so) > prval () = view@e := pre > prval () = view@so := prso > } > ``` > > But above causes the other errors: > > ``` > $ patscc -o a.out main.dats -DATS_MEMALLOC_LIBC > /home/kiwamu/src/practice-ats/tagged_union/main.dats: 511(line=29, > offs=14) -- 528(line=29, offs=31): error(3): a linear component of the > following type is abandoned: [S2Ecst(sockaddr)]. > /home/kiwamu/src/practice-ats/tagged_union/main.dats: 538(line=31, > offs=5) -- 540(line=31, offs=7): error(3): the linear dynamic variable > [pfe$4738(-1)] is preserved but with an incompatible typ > e. > /home/kiwamu/src/practice-ats/tagged_union/main.dats: 538(line=31, > offs=5) -- 540(line=31, offs=7): error(3): mismatch of static terms > (tyleq): > The actual term is: S2Eapp(S2Ecst(ptr_addr_type); S2Evar(l2(8481))) > The needed term is: S2Ecst(sockaddr) > /home/kiwamu/src/practice-ats/tagged_union/main.dats: 538(line=31, > offs=5) -- 540(line=31, offs=7): error(3): mismatch of static terms > (tyleq): > The actual term is: S2Etyrec(flt0; npf=-1; > e_remote=S2Eapp(S2Ecst(ptr_addr_type); S2Evar(l2(8481)))) > The needed term is: S2Etyrec(flt0; npf=-1; e_remote=S2Ecst(sockaddr)) > /home/kiwamu/src/practice-ats/tagged_union/main.dats: 538(line=31, > offs=5) -- 540(line=31, offs=7): error(3): mismatch of static terms > (tyleq): > The actual term is: S2Eat(S2Etyrec(flt0; npf=-1; > e_remote=S2Eapp(S2Ecst(ptr_addr_type); S2Evar(l2(8481)))); > S2Evar(l1(8480))) > The needed term is: S2Eat(S2Etyrec(flt0; npf=-1; > e_remote=S2Ecst(sockaddr)); S2Evar(l1(8480))) > ``` > > Something is wrong? > > Best regards, > -- > Kiwamu Okabe > > -- > You received this message because you are subscribed to the Google Groups > "ats-lang-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to ats-lang-users+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ats-lang-users/CAEvX6dmgZGvdUkVG93ajPVscqD44A8t2P4_ucemqPkR%2BA52mCQ%40mail.gmail.com > . > -- You received this message because you are subscribed to the Google Groups "ats-lang-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLq9dGuDo-SkoLsX6u4SacUwhhbfuSSEupOqCq0wBoo-5g%40mail.gmail.com.