File tree Expand file tree Collapse file tree 6 files changed +46
-15
lines changed Expand file tree Collapse file tree 6 files changed +46
-15
lines changed Original file line number Diff line number Diff line change 11__precompile__ (true )
22module Setfield
33
4- # hack to support static arrays
5- if Pkg. installed (" StaticArrays" ) != nothing
6- import StaticArrays
7- Base. setindex (arr:: StaticArrays.StaticArray , args... ) = StaticArrays. setindex (arr,args... )
8- end
9-
104if isdefined (Base, :getproperty )
115 using Base: getproperty
126else
Original file line number Diff line number Diff line change @@ -2,7 +2,10 @@ export @settable
22using MacroTools: prewalk, splitdef, combinedef
33
44macro settable (ex)
5- esc (settable (ex))
5+ if VERSION < v " 0.7-"
6+ __module__ = current_module ()
7+ end
8+ esc (settable (__module__, ex))
69end
710
811function arg_type (ex):: Tuple
@@ -96,8 +99,7 @@ function add_posonly_constructor(ex::Expr)::Expr
9699 end
97100end
98101
99- function settable (code):: Expr
100- M = current_module ()
102+ function settable (M, code):: Expr
101103 code = macroexpand (M, code)
102104 MacroTools. postwalk (code) do ex
103105 ret = if isstructdef (ex)
Original file line number Diff line number Diff line change 11module TestSetfield
22
3+ @static if VERSION < v " 0.7-"
4+ using Base. Test
5+ else
6+ using Test
7+ end
8+
9+ macro test_deprecated07 (ex)
10+ if VERSION < v " 0.7-"
11+ return esc (ex)
12+ else
13+ return esc (:(Test. @test_deprecated $ ex))
14+ end
15+ end
16+
317using Setfield
4- using Base. Test
518
619@testset " core" begin
720 include (" test_core.jl" )
2235 include (" test_kwonly.jl" )
2336end
2437
38+ @static if VERSION < v " 0.7-"
2539@testset " QuickTypes.jl" begin
2640 include (" test_quicktypes.jl" )
2741end
42+ end
2843
2944end # module
Original file line number Diff line number Diff line change @@ -187,11 +187,26 @@ end
187187 @test v_init[1 ] == 2
188188 @test v === v_init
189189
190+ # Julia 0.7 with --depwarn=error:
191+ is_deperror07 = VERSION >= v " 0.7-" && Base. JLOptions (). depwarn == 2
192+
190193 v = randn (3 )
191- @set! v[:] = 1
194+ # @set! v[:] .= 0 # dot-call not supported
195+ @test_broken v == [0 ,0 ,0. ]
196+ if is_deperror07
197+ v[:] .= 1
198+ else
199+ v = @test_deprecated07 (@set! v[:] = 1 ; v)
200+ end
192201 @test v == [1 ,1 ,1. ]
193- @set! v[2 : 3 ] = 4
202+ if is_deperror07
203+ v[2 : 3 ] .= 4
204+ else
205+ v = @test_deprecated07 (@set! v[2 : 3 ] = 4 ; v)
206+ end
194207 @test v == [1 ,4 ,4 ]
208+ # @set! v[1:2] .= 5 # dot-call not supported
209+ @test_broken v == [5 ,5 ,4 ]
195210 end
196211
197212 @testset " @set vs @set!" begin
253268@testset " show_generic" begin
254269 l = @lens _[1 ]
255270 s = sprint (Setfield. show_generic,l)
256- l2 = eval (parse (s))
271+ l2 = eval (Meta . parse (s))
257272 @test l == l2
258273end
Original file line number Diff line number Diff line change 11using Kwonly
2- using Base. Test
32using Setfield
43
54@settable struct AKW
Original file line number Diff line number Diff line change 11module TestQuicktypes
2+
3+ @static if VERSION < v " 0.7-"
4+ using Base. Test
5+ else
6+ using Test
7+ end
8+
29import Base: ==
3- using Base. Test
410import MacroTools
511
612using QuickTypes
You can’t perform that action at this time.
0 commit comments