Skip to content

Commit 3046f23

Browse files
Stephan SahmStephan Sahm
authored andcommitted
cleanup and bugfixes
1 parent 53a70bf commit 3046f23

1 file changed

Lines changed: 4 additions & 26 deletions

File tree

src/convert.jl

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Base.convert(::Type{<:Vector}, x::ContextManager) = [x(identity)]
1414
# -----
1515

1616
function Base.convert(::Type{Const}, x::Vector)
17-
@assert !isempty(x) "can only convert empty Vector to Nothing, got $(x)"
18-
Const([])
17+
@assert isempty(x) "can only convert empty Vector to Nothing, got $(x)"
18+
Const(nothing) # == Option()
1919
end
2020

2121
# Identity
@@ -43,30 +43,8 @@ Base.convert(::Type{<:ContextManager}, x::Identity) = @ContextManager cont -> co
4343
# while ContextManager should only have one call to `cont`.
4444

4545

46-
# conversions among Union Types
47-
# =============================
48-
49-
# Option
50-
# ------
51-
52-
# we need to overwrite convert, because in the case that no conversion is possible, we currently get the super uninformative error
53-
# ERROR: could not compute non-nothing type
54-
# Stacktrace:
55-
# [1] nonnothingtype_checked(::Type) at ./some.jl:29
56-
# [2] convert(::Type{Union{Nothing, Some{T}} where T}, ::Int64) at ./some.jl:34
57-
# [3] top-level scope at none:0
58-
# importantly, we should only add clauses for Type{Option} and not Type{<:Option} to not interfere with existing code
59-
Base.convert(::Type{Option}, x::Option) = x
60-
61-
Base.convert(::Type{Option{T}}, x::Identity) where T = Identity(Base.convert(T, x))
62-
Base.convert(::Type{Option{T}}, x::Identity{T}) where T = x # nothing to convert
63-
Base.convert(::Type{Option{T}}, x::Const{Nothing}) where T = x # nothing to convert
64-
Base.convert(::Type{Option}, x::Const{Nothing}) = x # nothing to convert
65-
Base.convert(::Type{Option}, x::Identity) = x # nothing to convert
66-
67-
68-
# Either
69-
# ------
46+
# Option, Either, Try
47+
# -------------------
7048

7149
Base.convert(::Type{Either{L, R}}, x::Identity) where {L, R} = Identity(Base.convert(R, x.value))
7250
Base.convert(::Type{Either{L, R}}, x::Identity{R}) where {L, R} = x # nothing to convert

0 commit comments

Comments
 (0)