Skip to content

Commit f89bb27

Browse files
Stephan SahmStephan Sahm
authored andcommitted
fixing Const and Identity conversion to not forget the given Container type
1 parent 3046f23 commit f89bb27

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/Const.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ Iterators.flatten(c::Const) = c
3636

3737
Base.eltype(::Type{<:Const}) = Any
3838

39-
Base.convert(::Type{Const{T}}, x::Const) where {T} = Const(Base.convert(T, x.value))
39+
Base.convert(::Type{Const{T}}, x::Const{T}) where {T} = x
40+
Base.convert(::Type{Const{T}}, x::Const) where {T} = Const{T}(convert(T, x.value))
41+
4042
# Const is covariate
4143
# promote_rule only works on concrete types, more general checks Type{<:Const} may overwrite
4244
# unintentionally more specific promote_rule types

src/Identity.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ Base.foreach(f, a::Identity) = begin f(a.value); nothing; end
3838
Base.map(f, a::Identity) = Identity(f(a.value))
3939
Base.Iterators.flatten(a::Identity) = convert(Identity, a.value)
4040

41-
Base.convert(::Type{Identity{T}}, x::Identity) where {T} = Identity(Base.convert(T, x.value))
41+
Base.convert(::Type{Identity{T}}, x::Identity{T}) where {T} = x
42+
Base.convert(::Type{Identity{T}}, x::Identity) where {T} = Identity{T}(convert(T, x.value))
43+
4244
# Identity is covariate
4345
# promote_rule only works on concrete types, more general checks Type{<:Const} may overwrite
4446
# unintentionally more specific promote_rule types

0 commit comments

Comments
 (0)