Skip to content

Commit

Permalink
Merge pull request #56 from MilesCranmer/cleaner-print
Browse files Browse the repository at this point in the history
docs: clean up printing of error type
  • Loading branch information
MilesCranmer authored Jul 21, 2024
2 parents 09a5c94 + fb7e4b5 commit 50faa81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/printing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ using .._Errors: AllowUnstableDataRace, TypeInstabilityError, TypeInstabilityWar
Base.showerror(io::IO, e::AllowUnstableDataRace) = print(io, e.msg)

function _print_msg(io::IO, e::Union{TypeInstabilityError,TypeInstabilityWarning})
print(io, "$(typeof(e)): Instability detected in $(e.f)")
print(
io,
"DispatchDoctor.TypeInstability",
e isa TypeInstabilityError ? "Error" : "Warning",
": Instability detected in ",
e.f,
)
if e.source_info !== nothing
print(io, " defined at ", e.source_info)
end
Expand All @@ -25,7 +31,7 @@ function _print_msg(io::IO, e::Union{TypeInstabilityError,TypeInstabilityWarning
join(io, parts, " and ")
end
print(io, ". ")
return print(io, "Inferred to be `$(e.return_type)`, which is not a concrete type.")
return print(io, "Inferred to be `", e.return_type, "`, which is not a concrete type.")
end
typeinfo(x) = specializing_typeof(x)
typeinfo(u::Unknown) = u
Expand Down
4 changes: 2 additions & 2 deletions test/unittests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ end

if DispatchDoctor.JULIA_OK
msg = @capture_err f(1)
@test occursin("TypeInstabilityWarning", msg)
@test occursin("DispatchDoctor.TypeInstabilityWarning", msg)
end
end
@testitem "disable @stable using env variable" begin
Expand Down Expand Up @@ -1192,7 +1192,7 @@ end
@test occursin("The `warnonly` option is deprecated", msg)
msg2 = @capture_err f(1)

@test occursin("TypeInstabilityWarning", msg2)
@test occursin("DispatchDoctor.TypeInstabilityWarning", msg2)

@stable enable = false function f(x)
return x > 0 ? x : 0.0
Expand Down

0 comments on commit 50faa81

Please sign in to comment.