@@ -740,7 +740,7 @@ let err_str
740740 @test occursin (Regex (" MethodError: no method matching one\\ (::.*HasNoOne; value::$(Int) \\ )" ), err_str)
741741 @test occursin (" `one` doesn't take keyword arguments, that would be silly" , err_str)
742742end
743- pop! (Base. Experimental. _hint_handlers[MethodError]) # order is undefined, don't copy this
743+ pop! (Base. Experimental. _hint_handlers[Core . typename ( MethodError) ]) # order is undefined, don't copy this
744744
745745function busted_hint (io, exc, notarg) # wrong number of args
746746 print (io, " \n I don't have a hint for you, sorry" )
@@ -752,7 +752,7 @@ catch ex
752752 io = IOBuffer ()
753753 @test_logs (:error , " Hint-handler busted_hint for DomainError in $(@__MODULE__ ) caused an error" ) showerror (io, ex)
754754end
755- pop! (Base. Experimental. _hint_handlers[DomainError]) # order is undefined, don't copy this
755+ pop! (Base. Experimental. _hint_handlers[Core . typename ( DomainError) ]) # order is undefined, don't copy this
756756
757757struct ANumber <: Number end
758758let err_str = @except_str ANumber ()(3 + 4 ) MethodError
@@ -1476,3 +1476,38 @@ let err_str
14761476 err_str = @except_str f56325 (1 ,2 ) MethodError
14771477 @test occursin (" The anonymous function" , err_str)
14781478end
1479+
1480+ # Test that error hints catch abstract exception supertypes (issue #58367)
1481+
1482+ module Hinterland
1483+
1484+ abstract type AbstractHintableException <: Exception end
1485+ struct ConcreteHintableException <: AbstractHintableException end
1486+ gonnathrow () = throw (ConcreteHintableException ())
1487+
1488+ function Base. showerror (io:: IO , exc:: ConcreteHintableException )
1489+ print (io, " This is my exception" )
1490+ Base. Experimental. show_error_hints (io, exc)
1491+ end
1492+
1493+ function __init__ ()
1494+ Base. Experimental. register_error_hint (ConcreteHintableException) do io, exc
1495+ print (io, " \n This hint caught my concrete exception type" )
1496+ end
1497+ Base. Experimental. register_error_hint (AbstractHintableException) do io, exc
1498+ print (io, " \n This other hint caught my abstract exception supertype" )
1499+ end
1500+ end
1501+
1502+ end
1503+
1504+ @testset " Hints for abstract exception supertypes" begin
1505+ exc = try
1506+ Hinterland. gonnathrow ()
1507+ catch e
1508+ e
1509+ end
1510+ exc_print = sprint (Base. showerror, exc)
1511+ @test occursin (" This hint caught my concrete exception type" , exc_print)
1512+ @test occursin (" This other hint caught my abstract exception supertype" , exc_print)
1513+ end
0 commit comments