@@ -34,27 +34,33 @@ final class TemporaryFileSapiEmitter implements EmitterInterface {
3434
3535 $body = $response -> getBody();
3636
37- /* HH_FIXME[4053] */
38- $path = $body -> getPath();
39-
40- $path as File \Path ;
37+ // Lambda is used to force $path to be string, not TAny (`_`).
38+ $path = (): string ==> {
39+ /* HH_FIXME[4053] getPath is not part of the WriteHandle interface.*/
40+ $path_maybe_object = $body -> getPath();
41+ // Path is going to be removed from the hsl.
42+ // We just used `->toString()` anyway.
43+ // This hacky expression is needed, because `$path_maybe_object`
44+ // is of the TAny type (`_`), so the typechecker won't error when
45+ // `->getPath()` starts returning a string.
46+ // This expression works for both Path and string.
47+ return $path_maybe_object |> $$ is string ? $$ : $$-> toString();
48+ }();
4149
4250 $this -> writeStatusLine($response );
4351 $this -> writeHeaders($response );
4452
45- $temporary_file_path = $path -> toString();
46-
4753 if ($body is IO \CloseableHandle ) {
4854 $body -> close();
4955 }
5056
51- $read_handle = File \open_read_only ($temporary_file_path );
57+ $read_handle = File \open_read_only ($path );
5258 using ($read_handle -> closeWhenDisposed()) {
5359 $out = IO \request_output ();
5460 $content = await $read_handle -> readAllAsync();
5561 await $out -> writeAllAsync($content );
5662 };
57- \unlink ($temporary_file_path );
63+ \unlink ($path );
5864 }
5965
6066 /**
0 commit comments