Skip to content

Commit

Permalink
fix Complex constructor on 0.3, fixes #54
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebolewski committed Mar 19, 2015
1 parent c4413a8 commit 3582cf1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,15 @@ function _compat(ex::Expr)
ex = rewrite_split(ex, f)
elseif VERSION < v"0.4.0-dev+3732" && haskey(calltypes, f) && length(ex.args) > 1
T = ex.args[1]
ex = Expr(:(::), Expr(:call, :convert, T, ex.args[2:end]...), T)
if T in (:Complex32, :Complex64, :Complex128)
if length(ex.args) < 3
ex = Expr(:call, T, ex.args[2], zero(ex.args[2]))

This comment has been minimized.

Copy link
@stevengj

stevengj Apr 2, 2015

Member

This looks wrong, e.g. for @compat Complex128(3+4im)

This comment has been minimized.

Copy link
@stevengj

stevengj Apr 2, 2015

Member

Seems like it would be better to just call complex128(args...) etc, since those do the right thing in 0.3 for 1 or 2 arguments.

else
ex = Expr(:call, T, ex.args[2:end]...)
end
else
ex = Expr(:(::), Expr(:call, :convert, T, ex.args[2:end]...), T)
end
elseif VERSION < v"0.4.0-dev+3732" && (f == :map && haskey(calltypes, ex.args[2]) && length(ex.args) > 2)
ex = Expr(:call, calltypes[ex.args[2]], ex.args[3:end]...)
end
Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ let convert_funcs_and_types =
end
@test (@compat Bool(1))
@test !(@compat Bool(0))

# issue #54
c = @compat Complex128(1)
@test c.re == 1
@test c.im == 0

c = @compat Complex128(1,1)
@test c.re == 1
@test c.im == 1
end

type Test3609
Expand Down

0 comments on commit 3582cf1

Please sign in to comment.