From 881c3637816850d010eb6dd3b92c0726174de8d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 20 Sep 2023 00:47:43 +0200 Subject: [PATCH] Catch some edge-cases reported by JET --- src/ambiguities.jl | 20 +++++++++++++++----- src/piracy.jl | 10 +++++++--- src/project_extras.jl | 5 ++++- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/ambiguities.jl b/src/ambiguities.jl index 0bff9fcf..432e37c6 100644 --- a/src/ambiguities.jl +++ b/src/ambiguities.jl @@ -64,7 +64,10 @@ normalize_exclude(::Any) = error("Only a function and type can be excluded.") function getobj((pkgid, name)::ExcludeSpec) nameparts = Symbol.(split(name, ".")) m = Base.require(pkgid) - return foldl(getproperty, nameparts, init = m) + for name in nameparts + m = getproperty(m, name) + end + return m end function normalize_and_check_exclude(exclude::AbstractVector) @@ -133,7 +136,14 @@ function _find_ambiguities( num_ambiguities = if succ 0 else - parse(Int, match(r"(\d+) ambiguities found", strout).captures[1]) + reg_match = match(r"(\d+) ambiguities found", strout) + + reg_match === nothing && error( + "Failed to parse output of `detect_ambiguities`. The output was:\n" * + strout, + ) + + parse(Int, reg_match.captures[1]) end return num_ambiguities, strout, strerr end @@ -154,11 +164,11 @@ end function reprpkgid(pkg::PkgId) name = pkg.name - if pkg.uuid === nothing + uuid = pkg.uuid + if uuid === nothing return "Base.PkgId($(repr(name)))" end - uuid = pkg.uuid.value - return "Base.PkgId(Base.UUID($(repr(uuid))), $(repr(name)))" + return "Base.PkgId(Base.UUID($(repr(uuid.value))), $(repr(name)))" end struct _NoValue end diff --git a/src/piracy.jl b/src/piracy.jl index ff2ca352..ef4cd115 100644 --- a/src/piracy.jl +++ b/src/piracy.jl @@ -104,7 +104,7 @@ function is_foreign(@nospecialize(T::DataType), pkg::Base.PkgId; treat_as_own) return is_foreign(first(params), pkg; treat_as_own = treat_as_own) else # Both the type itself and all of its parameters must be foreign - return !(C in treat_as_own) && + return !((C in treat_as_own)::Bool) && is_foreign_module(parentmodule(T), pkg) && all(param -> is_foreign(param, pkg; treat_as_own = treat_as_own), params) end @@ -153,8 +153,12 @@ function is_foreign_method(@nospecialize(T::DataType), pkg::Base.PkgId; treat_as end # fallback to general code - return !(T in treat_as_own) && - !(T <: Function && isdefined(T, :instance) && T.instance in treat_as_own) && + return !((T in treat_as_own)::Bool) && + !( + T <: Function && + isdefined(T, :instance) && + (T.instance in treat_as_own)::Bool + ) && is_foreign(T, pkg; treat_as_own = treat_as_own) end diff --git a/src/project_extras.jl b/src/project_extras.jl index d64bd50a..2c1adf1c 100644 --- a/src/project_extras.jl +++ b/src/project_extras.jl @@ -33,7 +33,10 @@ function _analyze_project_extras(pkg::PkgId) result isa LazyTestResult && return result root_project_path = result - pkgpath = dirname(dirname(Base.locate_package(pkg))) + package_loc = Base.locate_package(pkg) + package_loc === nothing && + return LazyTestResult(label, "Base.locate_package failed.", false) + pkgpath = dirname(dirname(package_loc)) test_project_path, found = project_toml_path(joinpath(pkgpath, "test")) if !found return LazyTestResult(label, "test/Project.toml file does not exist.", true)