#811 Is this normal ?

tcolar Wed 11 Nov 2009

This compiles fine:

static CatalogNode? findNode(CatalogNode[] rootNodes, Str nodeGuid)
{
  return rootNodes.eachWhile |CatalogNode node|
  {
      findANode(node, nodeGuid)
  }
}

This doesn't (compiler says Cannot return netColarCrmCat::CatalogNode? as sys::Void)

static CatalogNode? findNode(CatalogNode[] rootNodes, Str nodeGuid)
{
  return rootNodes.eachWhile |CatalogNode node|
  {
      echo("hello")
      return findANode(node, nodeGuid)
  }
}

tcolar Wed 11 Nov 2009

Figure it out

static CatalogNode? findNode(CatalogNode[] rootNodes, Str nodeGuid)
{
  return rootNodes.eachWhile |CatalogNode node -> CatalogNode?|
  {
      echo("hello")
      return findANode(node, nodeGuid)
  }
}

brian Wed 11 Nov 2009

I believe the way closure type inference works today is that all the parameters must have unspecified types if you wish to infer the return type. Not sure that is really the best rule

Login or Signup to reply.