AndreVanDelft / scala

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

Local output parameters sometimes break sequential operators #82

Closed anatoliykmetyuk closed 9 years ago

anatoliykmetyuk commented 9 years ago

This code's firstScript:

  def script..
    firstScript = var x: String = ""
                  setStr(x)
                  {println("From the main script: " + x)}

    setStr(??x: String) = {println("Setting the value of: " + x)}
                          {x = "Hello World!"}
                          {println("New value: " + x)}

outputs:

Setting the value of: 
New value: Hello World!

The sequence of firstScript doesn't continue after the setStr(x) call. If called with ?x, everything works fine. Normally, x should also work fine, since it is converted to an ActualOutputParameter by a DSL conversion method.

AndreVanDelft commented 9 years ago

A formal parameter with "?" is an output parameter. A second "??" there means that the actual parameter may be an output parameter, but it may also have a constraint, or it may be forcing. E.g. in

setStr("")

you give it a value; now when body of setStr succeeds (as after the "New value" printing), then the values of the actual paramter ("Hello World!") is matched against the one of the formal parameter (""). These do not match, hence the success is not propagated upwards through the call. Effectively we have then deadlock which is what you observed.

So the issue is closed. A bit harder issue is how we should write down tests for these particularities with all these parameters. FTTB when we don't have a good way of writing such tests we can leave it like it is now.