Skip to content

Commit

Permalink
Fix a JET warning (#44)
Browse files Browse the repository at this point in the history
In the 'else' path, JET cannot prove that SCRATCH_DIR_OVERRIDE[] is
(still) 'nothing', and thus reports a possible error. This then is also
shown when analyzing packages that use Scratch. This can be resolved by
assigning it first to a temporary variable.
  • Loading branch information
fingolfin authored Nov 1, 2023
1 parent b00c915 commit 465b5fa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
julia = "1"

[extras]
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Pkg"]
test = ["JET", "Test", "Pkg"]
5 changes: 3 additions & 2 deletions src/Scratch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ Returns a path within the current depot's `scratchspaces` directory. This locat
be overridden via `with_scratch_directory()`.
"""
function scratch_dir(args...)
if SCRATCH_DIR_OVERRIDE[] === nothing
override = SCRATCH_DIR_OVERRIDE[]
if override === nothing
return abspath(first(Base.DEPOT_PATH), "scratchspaces", args...)
else
# If we've been given an override, use _only_ that directory.
return abspath(SCRATCH_DIR_OVERRIDE[], args...)
return abspath(override, args...)
end
end

Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,11 @@ if VERSION >= v"1.6.0-DEV.676"
end
end
end

if Base.VERSION >= v"1.7"
using JET

@testset "test_package" begin
test_package("Scratch")
end
end

0 comments on commit 465b5fa

Please sign in to comment.