dostuff(r); (File<Open> f, FileRef<Void> r) = f.unborrow(r);
Of course, files are tricky since they can change their state themselves (like IO error). Doing that statically would require some kind of branching mechanism with a try-catch that jumps to a different location where the file type changes to "File<Error>"...
Sounds non-trivial to bolt onto an existing language.