Skip to content

Commit

Permalink
Avoid unintended materialization in @!
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Aug 28, 2019
1 parent 6b5fc66 commit e33e260
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 8 additions & 1 deletion src/macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ macro !(expr)
lhs, rhs = x.args
return :($lhs = $materialize!!(
$Base.@isdefined($lhs) ? $lhs : $(Undefined()),
$rhs,
$air.($rhs),
))
end
return x
Expand All @@ -39,3 +39,10 @@ function undotoperator(x::Symbol)
Base.isoperator(op) || return nothing
return op
end

function air end
struct Aired{T}
value::T
end
@inline Broadcast.broadcasted(::typeof(air), x) = Aired(x)
@inline Broadcast.materialize(x::Aired) = x.value
8 changes: 1 addition & 7 deletions test/test_materialize.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
module TestMaterialize

include("preamble.jl")

function air end
struct Aired{T}
value::T
end
@inline Broadcast.broadcasted(::typeof(air), x) = Aired(x)
@inline Broadcast.materialize(x::Aired) = x.value
using BangBang: air

@testset begin
@test materialize!!(nothing, air.([0, 1] .+ 2))::Vector{Int} == [2, 3]
Expand Down

0 comments on commit e33e260

Please sign in to comment.