Linear component is abandoned ...

68 views
Skip to first unread message

aditya siram

unread,
May 27, 2018, 9:19:19 PM5/27/18
to ats-lang-users
Hi,
I have the following simplified version of assiging to a stack variable and am getting the following error:

"linear component of the following type is abandoned: [S2Eapp(S2Ecst(option_vt0ype_bool_vtype); S2Eapp(S2Ecst(g0int_t0ype); [1]), S2Evar(b$8622$8623(14297)))]"

I searched around and the only reference I see to this error is about using a global variable in a function scope.

Any help is appreciated.

Thanks!
-deech
extern fun add1(
  n
: Option_vt(int)
) : Option_vt(int)

implement add1
(n) =
  let
    fun add1_
( n:Option_vt(int), res: &Option_vt(int) >> Option_vt(int) ) : void =
     
case+ n of
       
| ~Some_vt(i) => res := Some_vt(i+1)
       
| ~None_vt() => ()
   
var res : Option_vt(int) = None_vt()
    val
() = add1_(n,res)
 
in
    res
 
end


Artyom Shalkhakov

unread,
May 27, 2018, 9:23:20 PM5/27/18
to ats-lang-users
Hi Aditya,

I guess you will need to free it?

пн, 28 мая 2018 г., 7:19 aditya siram <aditya...@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-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at https://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/e51eb3bb-a5cb-4615-a87b-f2aa275fc5a4%40googlegroups.com.

aditya siram

unread,
May 27, 2018, 9:37:38 PM5/27/18
to ats-lang-users
In my haste I didn't include the line number of the error but it points to 'res := Some_vt(i+1)'.

Artyom Shalkhakov

unread,
May 27, 2018, 9:40:29 PM5/27/18
to ats-lang-users
Indeed, in this case, the old value of the mutable variable is abandoned.

You could free res first, and then assign. 

пн, 28 мая 2018 г., 7:37 aditya siram <aditya...@gmail.com>:

Hongwei Xi

unread,
May 27, 2018, 9:46:03 PM5/27/18
to ats-lan...@googlegroups.com
Or you can do something like:

implement
add1(n) =
let
  fun add1_( n: Option_vt(int), res: &Option_vt(int)? >> _ ) : void =
  case+ n of
  | ~None_vt() => res := None_vt()

  | ~Some_vt(i) => res := Some_vt(i+1)

  var res : Option_vt(int)?

  val () = add1_(n,res)
in
  res
end

To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-users+unsubscribe@googlegroups.com.
To post to this group, send email to ats-lang-users@googlegroups.com.

aditya siram

unread,
May 27, 2018, 9:53:12 PM5/27/18
to ats-lang-users
Awesome, thanks! Yet again my instincts to always initialize a variable lead me astray in ATS. :)
Reply all
Reply to author
Forward
0 new messages