Skip to content

Instantly share code, notes, and snippets.

@frabbit
Created August 3, 2012 19:53
Show Gist options
  • Save frabbit/3250869 to your computer and use it in GitHub Desktop.
Save frabbit/3250869 to your computer and use it in GitHub Desktop.
public static function getFirstPath (from:ClassType, to:ClassType):Option<Path>
{
function loop(from:ClassType, to:ClassType, path:Path)
{
trace(loop); // boom, loop is null in my case
function findInSuperOrInterface ()
{
function findInSuper ()
{
var sc = from.superClass;
return if (sc != null) loop(sc.t.get(), to, path.concat([SuperClass])) else None;
}
function findInInterfaces ()
{
function findInInterface (cur, index) return loop(cur.t.get(), to, path.concat([InterfaceAt(index)]));
function findFirst (acc:Option<Path>, cur, index) return acc.orElse(findInInterface.partial1_2(cur, index));
return from.interfaces.foldLeftWithIndex(findFirst, None);
}
return findInSuper().orElse(findInInterfaces);
}
return if (ClassTypes.eq(from, to)) Some(path) else findInSuperOrInterface();
}
trace(loop); // #function:3, everything is fine here
return loop(from, to, []);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment