Skip to content

Commit

Permalink
fixes copy(::Formula) when rhs is a single Symbol (#68)
Browse files Browse the repository at this point in the history
* fixes copy(::Formula) when rhs is a single Symbol

* fixes copy(::Formula) when rhs is a single Symbol

* reverted whitespace
  • Loading branch information
AsafManela authored and kleinschmidt committed Jun 27, 2018
1 parent 73c21ac commit e03d866
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/formula.jl
Expand Up @@ -360,9 +360,11 @@ function Formula(t::Terms)
Formula(ex, ex, lhs,rhs)
end

copyside(s) = copy(s)
copyside(s::Symbol) = s

function Base.copy(f::Formula)
lhs = isa(f.lhs, Symbol) ? f.lhs : copy(f.lhs)
return Formula(copy(f.ex_orig), copy(f.ex), lhs, copy(f.rhs))
return Formula(copy(f.ex_orig), copy(f.ex), copyside(f.lhs), copyside(f.rhs))
end

"""
Expand Down
7 changes: 7 additions & 0 deletions test/formula.jl
Expand Up @@ -124,4 +124,11 @@
# Incorrect formula separator
@test_throws ArgumentError @formula(y => x + 1)

# copying formulas
f = @formula(foo ~ 1 + bar)
@test f == copy(f)

f = @formula(foo ~ bar)
@test f == copy(f)

end

0 comments on commit e03d866

Please sign in to comment.