Skip to content

Commit e2a8e4c

Browse files
committed
fix up promotion and tests
1 parent 277d6ea commit e2a8e4c

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/fast-terms.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function Add(T, coeff, dict)
2323
return coeff
2424
elseif _iszero(coeff) && length(dict) == 1
2525
k,v = first(dict)
26-
return _isone(v) ? k : makemul(1, v, k)
26+
return _isone(v) ? k : Mul(T, makemul(1, v, k)...)
2727
end
2828

2929
Add{T, typeof(coeff), typeof(dict)}(coeff, dict, Ref{Any}(nothing))

src/methods.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,14 @@ for f in diadic
8484
S::Type{<:Number}) = promote_type(T, S)
8585
end
8686

87-
for f in [+, *, \, /, ^]
87+
for f in [+, -, *, \, /, ^]
8888
@eval promote_symtype(::$(typeof(f)),
8989
T::Type{<:Number},
9090
S::Type{<:Number}) = promote_type(T, S)
9191
end
92+
for f in [+, -, *]
93+
@eval promote_symtype(::$(typeof(f)), T::Type{<:Number}) = T
94+
end
9295

9396
promote_symtype(::typeof(rem2pi), T::Type{<:Number}, mode) = T
9497
Base.rem2pi(x::Symbolic, mode::Base.RoundingMode) = term(rem2pi, x, mode)

test/basics.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ end
5353
@testset "Base methods" begin
5454
@syms w::Complex z::Complex a::Real b::Real x
5555

56-
@test isequal(w + z, Add(0, Dict(w=>1, z=>1)))
57-
@test isequal(z + a, Add(0, Dict(z=>1, a=>1)))
58-
@test isequal(a + b, Add(0, Dict(a=>1, b=>1))) # TODO: make this Real
59-
@test isequal(a + x, Add(0, Dict(a=>1, x=>1)))
60-
@test isequal(a + z, Add(0, Dict(a=>1, z=>1)))
56+
@test isequal(w + z, Add(Number, 0, Dict(w=>1, z=>1)))
57+
@test isequal(z + a, Add(Number, 0, Dict(z=>1, a=>1)))
58+
@test isequal(a + b, Add(Real, 0, Dict(a=>1, b=>1)))
59+
@test isequal(a + x, Add(Number, 0, Dict(a=>1, x=>1)))
60+
@test isequal(a + z, Add(Number, 0, Dict(a=>1, z=>1)))
6161

6262
# promote_symtype of identity
6363
@test isequal(Term(identity, [w]), Term{Complex}(identity, [w]))

0 commit comments

Comments
 (0)