Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/Setfield.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
__precompile__(true)
module Setfield

# hack to support static arrays
if Pkg.installed("StaticArrays") != nothing
import StaticArrays
Base.setindex(arr::StaticArrays.StaticArray, args...) = StaticArrays.setindex(arr,args...)
end

if isdefined(Base, :getproperty)
using Base: getproperty
else
Expand Down
8 changes: 5 additions & 3 deletions src/settable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ export @settable
using MacroTools: prewalk, splitdef, combinedef

macro settable(ex)
esc(settable(ex))
if VERSION < v"0.7-"
__module__ = current_module()
end
esc(settable(__module__, ex))
end

function arg_type(ex)::Tuple
Expand Down Expand Up @@ -96,8 +99,7 @@ function add_posonly_constructor(ex::Expr)::Expr
end
end

function settable(code)::Expr
M = current_module()
function settable(M, code)::Expr
code = macroexpand(M, code)
MacroTools.postwalk(code) do ex
ret = if isstructdef(ex)
Expand Down
17 changes: 16 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
module TestSetfield

@static if VERSION < v"0.7-"
using Base.Test
else
using Test
end

macro test_deprecated07(ex)
if VERSION < v"0.7-"
return esc(ex)
else
return esc(:(Test.@test_deprecated $ex))
end
end

using Setfield
using Base.Test

@testset "core" begin
include("test_core.jl")
Expand All @@ -22,8 +35,10 @@ end
include("test_kwonly.jl")
end

@static if VERSION < v"0.7-"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the problem QuickTypes not working with 0.7 or is there a problem with our macros, do you know?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QuickTypes.jl itself doesn't work with the nighly at the moment. I don't know if our macro has any problems. I tried to fix QuickTypes.jl but it's tricky so I thought I'd skip testing for now.

@testset "QuickTypes.jl" begin
include("test_quicktypes.jl")
end
end

end # module
21 changes: 18 additions & 3 deletions test/test_core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,26 @@ end
@test v_init[1] == 2
@test v === v_init

# Julia 0.7 with --depwarn=error:
is_deperror07 = VERSION >= v"0.7-" && Base.JLOptions().depwarn == 2

v = randn(3)
@set! v[:] = 1
# @set! v[:] .= 0 # dot-call not supported
@test_broken v == [0,0,0.]
if is_deperror07
v[:] .= 1
else
v = @test_deprecated07 (@set! v[:] = 1; v)
end
@test v == [1,1,1.]
@set! v[2:3] = 4
if is_deperror07
v[2:3] .= 4
else
v = @test_deprecated07 (@set! v[2:3] = 4; v)
end
@test v == [1,4,4]
# @set! v[1:2] .= 5 # dot-call not supported
@test_broken v == [5,5,4]
end

@testset "@set vs @set!" begin
Expand Down Expand Up @@ -253,6 +268,6 @@ end
@testset "show_generic" begin
l = @lens _[1]
s = sprint(Setfield.show_generic,l)
l2 = eval(parse(s))
l2 = eval(Meta.parse(s))
@test l == l2
end
1 change: 0 additions & 1 deletion test/test_kwonly.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Kwonly
using Base.Test
using Setfield

@settable struct AKW
Expand Down
8 changes: 7 additions & 1 deletion test/test_quicktypes.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
module TestQuicktypes

@static if VERSION < v"0.7-"
using Base.Test
else
using Test
end

import Base: ==
using Base.Test
import MacroTools

using QuickTypes
Expand Down