Skip to content

Commit 53c8b59

Browse files
author
Ary Borenszweig
committedMar 2, 2017
Fixed #4062: Setting atomic reference to nil crashes the compiler
1 parent 1ec9806 commit 53c8b59

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed
 

Diff for: ‎spec/std/atomic_spec.cr

+10
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,16 @@ describe Atomic do
148148
atomic.get.should eq(2)
149149
end
150150

151+
it "#set with nil (#4062)" do
152+
atomic = Atomic(String?).new(nil)
153+
154+
atomic.set("foo")
155+
atomic.get.should eq("foo")
156+
157+
atomic.set(nil)
158+
atomic.get.should eq(nil)
159+
end
160+
151161
it "#lazy_set" do
152162
atomic = Atomic.new(1)
153163
atomic.lazy_set(2).should eq(2)

Diff for: ‎src/atomic.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ struct Atomic(T)
168168
# atomic.get # => 10
169169
# ```
170170
def set(value : T)
171-
Ops.store(pointerof(@value), value, :sequentially_consistent, true)
171+
Ops.store(pointerof(@value), value.as(T), :sequentially_consistent, true)
172172
value
173173
end
174174

0 commit comments

Comments
 (0)
Please sign in to comment.