But second calling `wg_input` causes error:

```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
}

datatype 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 >> 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 = Af_inet @{
    sin_port = 1,
    sin_addr = 2,
    sin_zero = 3
  }
  var so6: sockaddr = Af_inet6 @{
    sin6_port = 1,
    sin6_flowinfo = 2,
    sin6_addr = 3,
    sin6_scope_id = 4
  }

  prval pre = view@e
  prval prso = view@so
  val () = wg_input(pre, prso | addr@e, addr@so)
  prval () = view@e := pre
  prval () = view@so := prso

  prval pre = view@e
  prval prso6 = view@so6
  val () = wg_input(pre, prso6 | addr@e, addr@so6)
  prval () = view@e := pre
  prval () = view@so6 := prso6
}
```

```
$ patscc -o a.out main.dats -DATS_MEMALLOC_LIBC
/home/kiwamu/src/practice-ats/tagged_union/main.dats: 1042(line=56,
offs=21) -- 1045(line=56, offs=24): error(3): the dynamic expression
cannot be assigned the type [S2Eat(S2Etyrec(flt0; npf=-1;
 e_remote=S2Etop(knd=0; S2Ecst(sockaddr))), S2EVar(5246))].
/home/kiwamu/src/practice-ats/tagged_union/main.dats: 1042(line=56,
offs=21) -- 1045(line=56, offs=24): error(3): mismatch of static terms
(tyleq):
The actual term is: S2Ecst(sockaddr)
The needed term is: S2Ecst(ptr_type)
/home/kiwamu/src/practice-ats/tagged_union/main.dats: 1042(line=56,
offs=21) -- 1045(line=56, offs=24): error(3): mismatch of static terms
(tyleq):
The actual term is: S2Etyrec(flt0; npf=-1; e_remote=S2Ecst(sockaddr))
The needed term is: S2Etyrec(flt0; npf=-1; e_remote=S2Etop(knd=0;
S2Ecst(sockaddr)))
/home/kiwamu/src/practice-ats/tagged_union/main.dats: 1042(line=56,
offs=21) -- 1045(line=56, offs=24): error(3): mismatch of static terms
(tyleq):
The actual term is: S2Eat(S2Etyrec(flt0; npf=-1;
e_remote=S2Ecst(sockaddr)); S2Evar(e(8482)))
The needed term is: S2Eat(S2Etyrec(flt0; npf=-1;
e_remote=S2Etop(knd=0; S2Ecst(sockaddr)));
S2EVar(5246->S2Evar(e(8482))))
```

Following patch does fix the error:

```diff
--- a/tagged_union/main.dats
+++ b/tagged_union/main.dats
@@ -51,6 +51,7 @@ implement main0 () = {
   prval () = view@e := pre
   prval () = view@so := prso

+  var e: wg_endpoint
   prval pre = view@e
   prval prso6 = view@so6
   val () = wg_input(pre, prso6 | addr@e, addr@so6)
```

How to re-use initialized argument on `wg_input` function?

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/CAEvX6d%3Dzhbz4Oxtu1vTLjRBjov0pnxDKDrF16hoOmrADz0hoQg%40mail.gmail.com.

Reply via email to