Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch some edge-cases reported by JET #190

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/ambiguities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 7 additions & 3 deletions src/piracy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion src/project_extras.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading