#258 Another compiler error

cbeust Tue 24 Jun 2008

How come the following compiles fine:

Void process2(|Int -> Void |[] functions)
{
  functions.each | | Int -> Void| fun, Int index |
  {
    fun(0)
  }
}

but if I change the return type of the closure to Void, the compiler complains:

Void process(|Void -> Void |[] functions)
{
  functions.each | | Void -> Void| fun, Int index |
  {
    fun()
  }
}

The error corresponds to the fun() invocation:

/Users/cbeust/fan/curry.fan(30,7): Invalid args |sys::Void|, not ()

-- Cedric

brian Tue 24 Jun 2008

Like method signatures, you only use Void for return. Unlike methods, you can omit the Void return (it is optional):

|Void -> Void| fun  // illegal just like Void m(Void) would be
|->Void| fun        // ok
|,| fun             // shortcut for above
|Int->Void| fun     // ok
|Int| fun           // shortcut for above

tompalmer Tue 24 Jun 2008

Can I count these questions as evidence that it's confusing when methods put the return type on the left but function types and closures put the return type on the right?

helium Wed 25 Jun 2008

No

Login or Signup to reply.