@@ -997,19 +997,21 @@ end
997997
998998let
999999 local z = complex (3 , 4 )
1000- v = Int[0 ,0 ]
1001- for i= 1 : 2
1000+ v = Int[0 , 0 ]
1001+ for i = 1 : 2
10021002 v[i] = getfield (z, i)
10031003 end
1004- @test v == [3 ,4 ]
1005- @test_throws BoundsError getfield (z, - 1 )
1006- @test_throws BoundsError getfield (z, 0 )
1007- @test_throws BoundsError getfield (z, 3 )
1004+ @test v == [3 , 4 ]
1005+ @test_throws BoundsError (z, - 1 ) getfield (z, - 1 )
1006+ @test_throws BoundsError (z, 0 ) getfield (z, 0 )
1007+ @test_throws BoundsError (z, 3 ) getfield (z, 3 )
10081008
10091009 strct = LoadError (" yofile" , 0 , " bad" )
1010- @test_throws BoundsError getfield (strct, 10 )
1011- @test_throws ErrorException setfield! (strct, 0 , " " )
1012- @test_throws ErrorException setfield! (strct, 4 , " " )
1010+ @test nfields (strct) == 3 # sanity test
1011+ @test_throws BoundsError (strct, 10 ) getfield (strct, 10 )
1012+ @test_throws ErrorException (" type LoadError is immutable" ) setfield! (strct, 0 , " " )
1013+ @test_throws ErrorException (" type LoadError is immutable" ) setfield! (strct, 4 , " " )
1014+ @test_throws ErrorException (" type is immutable" ) setfield! (strct, :line , 0 )
10131015 @test strct. file == " yofile"
10141016 @test strct. line == 0
10151017 @test strct. error == " bad"
@@ -1018,15 +1020,17 @@ let
10181020 @test getfield (strct, 3 ) == " bad"
10191021
10201022 mstrct = TestMutable (" melm" , 1 , nothing )
1021- setfield ! (mstrct, 2 , 8 )
1023+ Base . setproperty ! (mstrct, :line , 8.0 )
10221024 @test mstrct. line == 8
1025+ @test_throws TypeError (:setfield! , " " , Int, 8.0 ) setfield! (mstrct, :line , 8.0 )
1026+ @test_throws TypeError (:setfield! , " " , Int, 8.0 ) setfield! (mstrct, 2 , 8.0 )
10231027 setfield! (mstrct, 3 , " hi" )
10241028 @test mstrct. error == " hi"
10251029 setfield! (mstrct, 1 , " yo" )
10261030 @test mstrct. file == " yo"
1027- @test_throws BoundsError getfield (mstrct, 10 )
1028- @test_throws BoundsError setfield! (mstrct, 0 , " " )
1029- @test_throws BoundsError setfield! (mstrct, 4 , " " )
1031+ @test_throws BoundsError (mstrct, 10 ) getfield (mstrct, 10 )
1032+ @test_throws BoundsError (mstrct, 0 ) setfield! (mstrct, 0 , " " )
1033+ @test_throws BoundsError (mstrct, 4 ) setfield! (mstrct, 4 , " " )
10301034end
10311035
10321036# allow typevar in Union to match as long as the arguments contain
@@ -2175,10 +2179,9 @@ g7652() = fieldtype(DataType, :types)
21752179h7652 () = setfield! (a7652, 1 , 2 )
21762180h7652 ()
21772181@test a7652. a == 2
2178- # commented out due to issue #16195: setfield! does not perform conversions
2179- # i7652() = setfield!(a7652, 1, 3.0)
2180- # i7652()
2181- # @test a7652.a == 3
2182+ i7652 () = Base. setproperty! (a7652, :a , 3.0 )
2183+ i7652 ()
2184+ @test a7652. a == 3
21822185
21832186# issue #7679
21842187@test map (f-> f (), Any[ ()-> i for i= 1 : 3 ]) == Any[1 ,2 ,3 ]
@@ -2358,49 +2361,53 @@ let
23582361end
23592362
23602363# pull request #9534
2361- @test try ; a,b,c = 1 ,2 ; catch ex; (ex:: BoundsError ). a === (1 ,2 ) && ex. i == 3 ; end
2362- # @test try; [][]; catch ex; isempty((ex::BoundsError).a::Array{Any,1}) && ex.i == (1,); end # TODO : Re-enable after PLI
2363- @test try ; [][1 ,2 ]; catch ex; isempty ((ex:: BoundsError ). a:: Array{Any,1} ) && ex. i == (1 ,2 ); end
2364- @test try ; [][10 ]; catch ex; isempty ((ex:: BoundsError ). a:: Array{Any,1} ) && ex. i == (10 ,); end
2365- f9534a () = (a= 1 + 2im ; getfield (a, - 100 ))
2366- f9534a (x) = (a= 1 + 2im ; getfield (a, x))
2367- @test try ; f9534a () catch ex; (ex:: BoundsError ). a === 1 + 2im && ex. i == - 100 ; end
2368- @test try ; f9534a (3 ) catch ex; (ex:: BoundsError ). a === 1 + 2im && ex. i == 3 ; end
2369- f9534b () = (a= (1 ,2. ," " ); a[5 ])
2370- f9534b (x) = (a= (1 ,2. ," " ); a[x])
2371- @test try ; f9534b () catch ex; (ex:: BoundsError ). a == (1 ,2. ," " ) && ex. i == 5 ; end
2372- @test try ; f9534b (4 ) catch ex; (ex:: BoundsError ). a == (1 ,2. ," " ) && ex. i == 4 ; end
2373- f9534c () = (a= (1 ,2. ); a[3 ])
2374- f9534c (x) = (a= (1 ,2. ); a[x])
2375- @test try ; f9534c () catch ex; (ex:: BoundsError ). a === (1 ,2. ) && ex. i == 3 ; end
2376- @test try ; f9534c (0 ) catch ex; (ex:: BoundsError ). a === (1 ,2. ) && ex. i == 0 ; end
2377- f9534d () = (a= (1 ,2 ,4 ,6 ,7 ); a[7 ])
2378- f9534d (x) = (a= (1 ,2 ,4 ,6 ,7 ); a[x])
2379- @test try ; f9534d () catch ex; (ex:: BoundsError ). a === (1 ,2 ,4 ,6 ,7 ) && ex. i == 7 ; end
2380- @test try ; f9534d (- 1 ) catch ex; (ex:: BoundsError ). a === (1 ,2 ,4 ,6 ,7 ) && ex. i == - 1 ; end
2381- f9534e (x) = (a= IOBuffer (); setfield! (a, x, 3 ))
2382- @test try ; f9534e (- 2 ) catch ex; isa ((ex:: BoundsError ). a,Base. IOBuffer) && ex. i == - 2 ; end
2383- f9534f () = (a= IOBuffer (); getfield (a, - 2 ))
2384- f9534f (x) = (a= IOBuffer (); getfield (a, x))
2385- @test try ; f9534f () catch ex; isa ((ex:: BoundsError ). a,Base. IOBuffer) && ex. i == - 2 ; end
2386- @test try ; f9534f (typemin (Int)+ 2 ) catch ex; isa ((ex:: BoundsError ). a,Base. IOBuffer) && ex. i == typemin (Int)+ 2 ; end
2364+ @test_throws BoundsError ((1 , 2 ), 3 ) begin ; a, b, c = 1 , 2 ; end
2365+ let a = []
2366+ @test_broken try ; a[]; catch ex; (ex:: BoundsError ). a === a && ex. i == (1 ,); end # TODO : Re-enable after PLI
2367+ @test_throws BoundsError (a, (1 , 2 )) a[1 , 2 ]
2368+ @test_throws BoundsError (a, (10 ,)) a[10 ]
2369+ end
2370+ f9534a () = (a = 1 + 2im ; getfield (a, - 100 ))
2371+ f9534a (x) = (a = 1 + 2im ; getfield (a, x))
2372+ @test_throws BoundsError (1 + 2im , - 100 ) f9534a ()
2373+ @test_throws BoundsError (1 + 2im , 3 ) f9534a (3 )
2374+ f9534b () = (a = (1 , 2. , " " ); a[5 ])
2375+ f9534b (x) = (a = (1 , 2. , " " ); a[x])
2376+ @test_throws BoundsError ((1 , 2. , " " ), 5 ) f9534b ()
2377+ @test_throws BoundsError ((1 , 2. , " " ), 4 ) f9534b (4 )
2378+ f9534c () = (a = (1 , 2. ); a[3 ])
2379+ f9534c (x) = (a = (1 , 2. ); a[x])
2380+ @test_throws BoundsError ((1 , 2. ), 3 ) f9534c ()
2381+ @test_throws BoundsError ((1 , 2. ), 0 ) f9534c (0 )
2382+ f9534d () = (a = (1 , 2 , 4 , 6 , 7 ); a[7 ])
2383+ f9534d (x) = (a = (1 , 2 , 4 , 6 , 7 ); a[x])
2384+ @test_throws BoundsError ((1 , 2 , 4 , 6 , 7 ), 7 ) f9534d ()
2385+ @test_throws BoundsError ((1 , 2 , 4 , 6 , 7 ), - 1 ) f9534d (- 1 )
2386+ let a = IOBuffer ()
2387+ f9534e (x) = setfield! (a, x, 3 )
2388+ @test_throws BoundsError (a, - 2 ) f9534e (- 2 )
2389+ f9534f () = getfield (a, - 2 )
2390+ f9534f (x) = getfield (a, x)
2391+ @test_throws BoundsError (a, - 2 ) f9534f ()
2392+ @test_throws BoundsError (a, typemin (Int) + 2 ) f9534f (typemin (Int) + 2 )
2393+ end
23872394x9634 = 3
2388- @test try ; getfield ( 1 + 2im , x9634); catch ex; (ex :: BoundsError ) . a === 1 + 2im && ex . i == 3 ; end
2389- @test try ; throw (BoundsError ()) catch ex; ! isdefined ((ex:: BoundsError ), :a ) && ! isdefined ((ex:: BoundsError ), :i ); end
2390- @test try ; throw (BoundsError (Int)) catch ex; (ex:: BoundsError ). a == Int && ! isdefined ((ex:: BoundsError ), :i ); end
2391- @test try ; throw ( BoundsError (Int, typemin (Int))) catch ex; (ex :: BoundsError ) . a == Int && (ex :: BoundsError ) . i == typemin (Int); end
2392- @test try ; throw ( BoundsError (Int, (:a ,))) catch ex; (ex :: BoundsError ) . a == Int && (ex :: BoundsError ) . i == ( : a ,); end
2393- f9534g (a,b, c... ) = c[0 ]
2394- @test try ; f9534g ( 1 , 2 , 3 , 4 , 5 , 6 ) catch ex; (ex :: BoundsError ) . a === ( 3 , 4 , 5 , 6 ) && ex . i == 0 ; end
2395- f9534h (a,b, c... ) = c[a]
2396- @test f9534h (4 ,2 , 3 , 4 , 5 , 6 ) == 6
2397- @test try ; f9534h ( 5 , 2 , 3 , 4 , 5 , 6 ) catch ex; (ex :: BoundsError ) . a === ( 3 , 4 , 5 , 6 ) && ex . i == 5 ; end
2395+ @test_throws BoundsError ( 1 + 2im , 3 ) getfield ( 1 + 2im , x9634)
2396+ @test try ; throw (BoundsError ()); catch ex; ! isdefined ((ex:: BoundsError ), :a ) && ! isdefined ((ex:: BoundsError ), :i ); end
2397+ @test try ; throw (BoundsError (Int)); catch ex; (ex:: BoundsError ). a == Int && ! isdefined ((ex:: BoundsError ), :i ); end
2398+ @test_throws BoundsError (Int, typemin (Int)) throw ( BoundsError ( Int, typemin (Int)))
2399+ @test_throws BoundsError (Int, (:a ,)) throw ( BoundsError ( Int, ( : a ,)))
2400+ f9534g (a, b, c... ) = c[0 ]
2401+ @test_throws BoundsError (( 3 , 4 , 5 , 6 ), 0 ) f9534g ( 1 , 2 , 3 , 4 , 5 , 6 )
2402+ f9534h (a, b, c... ) = c[a]
2403+ @test f9534h (4 , 2 , 3 , 4 , 5 , 6 ) == 6
2404+ @test_throws BoundsError (( 3 , 4 , 5 , 6 ), 5 ) f9534h ( 5 , 2 , 3 , 4 , 5 , 6 )
23982405
23992406# issue #7978, comment 332352438
24002407f7978a () = 1
2401- @test try ; a, b = f7978a () catch ex; (ex :: BoundsError ) . a == 1 && ex . i == 2 ; end
2408+ @test_throws BoundsError ( 1 , 2 ) begin ; a, b = f7978a (); end
24022409f7978b () = 1 , 2
2403- @test try ; a, b, c = f7978b () catch ex; (ex :: BoundsError ) . a == ( 1 , 2 ) && ex . i == 3 ; end
2410+ @test_throws BoundsError (( 1 , 2 ), 3 ) begin ; a, b, c = f7978b () ; end
24042411
24052412# issue #9535
24062413counter9535 = 0
0 commit comments