Skip to content

Commit 355b830

Browse files
authored
Merge pull request #41 from JuliaDiff/npr/dont-shadow-methoderrors
Change to more appropraite error types
2 parents 049695a + 93accdb commit 355b830

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/differentials.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ struct Wirtinger{P,C} <: AbstractDifferential
6767
conjugate::Union{Number,AbstractDifferential})
6868
return new{typeof(primal),typeof(conjugate)}(primal, conjugate)
6969
end
70-
function Wirtinger(primal, conjugate)
71-
error("`Wirtinger` only supports elements of type <: Union{Number,AbstractDifferential} for now")
72-
end
7370
end
7471

7572
wirtinger_primal(x::Wirtinger) = x.primal
@@ -78,15 +75,16 @@ wirtinger_primal(x) = x
7875
wirtinger_conjugate(x::Wirtinger) = x.conjugate
7976
wirtinger_conjugate(::Any) = Zero()
8077

81-
extern(x::Wirtinger) = error("`Wirtinger` cannot be converted into an external type.")
78+
extern(x::Wirtinger) = throw(ArgumentError("`Wirtinger` cannot be converted to an external type."))
8279

8380
Base.Broadcast.broadcastable(w::Wirtinger) = Wirtinger(broadcastable(w.primal),
8481
broadcastable(w.conjugate))
8582

8683
Base.iterate(x::Wirtinger) = (x, nothing)
8784
Base.iterate(::Wirtinger, ::Any) = nothing
8885

89-
Base.conj(x::Wirtinger) = error("`conj(::Wirtinger)` not yet defined")
86+
# TODO: define `conj` for` `Wirtinger`
87+
Base.conj(x::Wirtinger) = throw(MethodError(conj, x))
9088

9189

9290
#####
@@ -147,7 +145,9 @@ is not defined.
147145
"""
148146
struct DNE <: AbstractDifferential end
149147

150-
extern(x::DNE) = error("`DNE` cannot be converted into an external type.")
148+
function extern(x::DNE)
149+
throw(ArgumentError("Derivative does not exit. Cannot be converted to an external type."))
150+
end
151151

152152
Base.Broadcast.broadcastable(::DNE) = Ref(DNE())
153153

@@ -190,7 +190,7 @@ macro thunk(body)
190190
return :(Thunk(() -> $(esc(body))))
191191
end
192192

193-
@inline extern(x::Thunk{F}) where {F} = x.f()
193+
@inline extern(x::Thunk) = x.f()
194194

195195
Base.Broadcast.broadcastable(x::Thunk) = broadcastable(extern(x))
196196

test/differentials.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
# TODO: other + methods stack overflow
1313
@test_throws ErrorException w*w
14-
@test_throws ErrorException extern(w)
14+
@test_throws ArgumentError extern(w)
1515
for x in w
1616
@test x === w
1717
end
1818
@test broadcastable(w) == w
19-
@test_throws ErrorException conj(w)
19+
@test_throws MethodError conj(w)
2020
end
2121
@testset "Zero" begin
2222
z = Zero()

0 commit comments

Comments
 (0)