Skip to content

Commit ead23db

Browse files
authored
improve type stability of stat (#58212)
Make sure that its return type is inferred to be `String`. Allows JET to not report false positive errors from `@report_call Downloads.download(::String)`
1 parent 8a8e3d1 commit ead23db

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

base/filesystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export File,
139139
import .Base:
140140
IOError, _UVError, _sizeof_uv_fs, check_open, close, closewrite, eof, eventloop, fd, isopen,
141141
bytesavailable, position, read, read!, readbytes!, readavailable, seek, seekend, show,
142-
skip, stat, unsafe_read, unsafe_write, write, transcode, uv_error,
142+
skip, stat, unsafe_read, unsafe_write, write, transcode, uv_error, _uv_error,
143143
setup_stdio, rawhandle, OS_HANDLE, INVALID_OS_HANDLE, windowserror, filesize,
144144
isexecutable, isreadable, iswritable, MutableDenseArrayType, truncate
145145

base/libuv.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ struverror(err::Int32) = unsafe_string(ccall(:uv_strerror, Cstring, (Int32,), er
103103
uverrorname(err::Int32) = unsafe_string(ccall(:uv_err_name, Cstring, (Int32,), err))
104104

105105
uv_error(prefix::Symbol, c::Integer) = uv_error(string(prefix), c)
106-
uv_error(prefix::AbstractString, c::Integer) = c < 0 ? throw(_UVError(prefix, c)) : nothing
106+
uv_error(prefix::AbstractString, c::Integer) = c < 0 ? _uv_error(prefix, c) : nothing
107+
_uv_error(prefix::AbstractString, c::Integer) = throw(_UVError(prefix, c))
107108

108109
## event loop ##
109110

base/stat.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ show(io::IO, ::MIME"text/plain", st::StatStruct) = show_statstruct(io, st, false
183183

184184
# stat & lstat functions
185185

186-
checkstat(s::StatStruct) = Int(s.ioerrno) in (0, Base.UV_ENOENT, Base.UV_ENOTDIR, Base.UV_EINVAL) ? s : uv_error(string("stat(", repr(s.desc), ")"), s.ioerrno)
186+
checkstat(s::StatStruct) = Int(s.ioerrno) in (0, Base.UV_ENOENT, Base.UV_ENOTDIR, Base.UV_EINVAL) ? s :
187+
_uv_error(string("stat(", repr(s.desc), ")"), s.ioerrno)
187188

188189
macro stat_call(sym, arg1type, arg)
189190
return quote

stdlib/FileWatching/src/FileWatching.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,12 +488,11 @@ end
488488

489489
function getproperty(fdw::FDWatcher, s::Symbol)
490490
# support deprecated field names
491-
s === :readable && return fdw.mask.readable
492-
s === :writable && return fdw.mask.writable
491+
s === :readable && return getfield(fdw, :mask).readable
492+
s === :writable && return getfield(fdw, :mask).writable
493493
return getfield(fdw, s)
494494
end
495495

496-
497496
close(t::_FDWatcher, mask::FDEvent) = close(t, mask.readable, mask.writable)
498497
function close(t::_FDWatcher, readable::Bool, writable::Bool)
499498
iolock_begin()

test/file.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,3 +2165,5 @@ end
21652165
@test dstat.total < 32PB
21662166
@test dstat.used + dstat.available == dstat.total
21672167
end
2168+
2169+
@test Base.infer_return_type(stat, (String,)) == Base.Filesystem.StatStruct

0 commit comments

Comments
 (0)