Skip to content

Commit a326bf5

Browse files
committed
Add promote_symtype for ifelse
1 parent a1bfb6c commit a326bf5

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

src/methods.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ end
141141
function ifelse(_if::Symbolic{Bool}, _then, _else)
142142
Term{Union{symtype(_then), symtype(_else)}}(ifelse, Any[_if, _then, _else])
143143
end
144+
promote_symtype(::typeof(ifelse), _, ::Type{T}, ::Type{S}) where {T,S} = Union{T, S}
144145
Base.@deprecate cond(_if, _then, _else) ifelse(_if, _then, _else)
145146

146147
# Specially handle inv and literal pow

test/basics.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using SymbolicUtils: Sym, FnType, Term, Add, Mul, Pow, symtype, operation, arguments
22
using SymbolicUtils
3+
using IfElse: ifelse
34
using Test
45

56
@testset "@syms" begin
@@ -82,6 +83,7 @@ end
8283

8384
@test symtype(ifelse(true, 4, 5)) == Int
8485
@test symtype(ifelse(a < 0, b, w)) == Union{Real, Complex}
86+
@test SymbolicUtils.promote_symtype(ifelse, Bool, Int, Bool) == Union{Int, Bool}
8587
@test_throws MethodError w < 0
8688
@test isequal(w == 0, Term{Bool}(==, [w, 0]))
8789
end

0 commit comments

Comments
 (0)