Skip to content

Commit

Permalink
Fixed #4062: Setting atomic reference to nil crashes the compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Mar 2, 2017
1 parent 1ec9806 commit 53c8b59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions spec/std/atomic_spec.cr
Expand Up @@ -148,6 +148,16 @@ describe Atomic do
atomic.get.should eq(2)
end

it "#set with nil (#4062)" do
atomic = Atomic(String?).new(nil)

atomic.set("foo")
atomic.get.should eq("foo")

atomic.set(nil)
atomic.get.should eq(nil)
end

it "#lazy_set" do
atomic = Atomic.new(1)
atomic.lazy_set(2).should eq(2)
Expand Down
2 changes: 1 addition & 1 deletion src/atomic.cr
Expand Up @@ -168,7 +168,7 @@ struct Atomic(T)
# atomic.get # => 10
# ```
def set(value : T)
Ops.store(pointerof(@value), value, :sequentially_consistent, true)
Ops.store(pointerof(@value), value.as(T), :sequentially_consistent, true)
value
end

Expand Down

0 comments on commit 53c8b59

Please sign in to comment.