diff --git a/src/Setfield.jl b/src/Setfield.jl index c5ba0ce..62bc9bb 100644 --- a/src/Setfield.jl +++ b/src/Setfield.jl @@ -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 diff --git a/src/settable.jl b/src/settable.jl index 5ee08b9..1368d53 100644 --- a/src/settable.jl +++ b/src/settable.jl @@ -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 @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index 0309247..ba6813a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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") @@ -22,8 +35,10 @@ end include("test_kwonly.jl") end +@static if VERSION < v"0.7-" @testset "QuickTypes.jl" begin include("test_quicktypes.jl") end +end end # module diff --git a/test/test_core.jl b/test/test_core.jl index 3dc4efe..e4a40c2 100644 --- a/test/test_core.jl +++ b/test/test_core.jl @@ -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 @@ -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 diff --git a/test/test_kwonly.jl b/test/test_kwonly.jl index fc7ecff..3e3c358 100644 --- a/test/test_kwonly.jl +++ b/test/test_kwonly.jl @@ -1,5 +1,4 @@ using Kwonly -using Base.Test using Setfield @settable struct AKW diff --git a/test/test_quicktypes.jl b/test/test_quicktypes.jl index 852b7e0..cdae5a8 100644 --- a/test/test_quicktypes.jl +++ b/test/test_quicktypes.jl @@ -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