encore icon indicating copy to clipboard operation
encore copied to clipboard

Restrictive forward's type

Open PhucVH888 opened this issue 7 years ago • 1 comments

The forward's type is too restrictive. When using nested forward in the following example, an extra variable arg1 is necessary for passing the typecheck. A better way is to relax the forward's type so that no extra variable is used to do the trick.

active class Base
  def base() : int
    42
  end
end

active class Bar
  def bar() : int
    24
  end
end

active class Foo
  def foo(b : bool) : int
    val arg1 = (new Bar) ! bar()
    val arg2 = (new Base) ! base()
    forward(if b then
              forward(arg1)
              arg1 -- required to make typecheck
            else
              arg2
            end)
  end
end

active class Main
  def main() : unit
    println("{}", get((new Foo) ! foo(true)))
    println("{}", get((new Foo) ! foo(false)))
  end
end

PhucVH888 avatar May 03 '17 08:05 PhucVH888

It seems that return and abort() have the same problem.

supercooldave avatar May 11 '17 09:05 supercooldave