AndreVanDelft / scala

The SubScript extension to the Scala programming language
http://www.subscript-lang.org/
12 stars 1 forks source link

Impossible to assign one script variable to another script variable #52

Closed anatoliykmetyuk closed 9 years ago

anatoliykmetyuk commented 9 years ago

Consider the following script:

  def script live = (
    val i = 4
    val j = i
  )

It will fail to compile, because "i cannot be found". This is so, because the right-hand side of the assignment is supposed to be an ordinary Scala code that doesn't belong to any node, and, hence, doesn't have a here variable in scope. Hence, i can't be evaluated.

A workaround goes as follows:

  def script live = (
    val i = 4
    val j: Int = 0
    {j = i}
  )

A good way to solve the problem would be to include the implicit here variable to the right-hand side block of the assignment. The here variable can evaluate to the n-ary operator the assignment belongs to - the sequential operator in the latter example.

AndreVanDelft commented 9 years ago

Solved. However, for the time being local script vars and vals must be explicitly typed.