@@ -997,36 +997,44 @@ end
997
997
998
998
let
999
999
local z = complex (3 , 4 )
1000
- v = Int[0 ,0 ]
1001
- for i= 1 : 2
1002
- v[i] = getfield (z, i)
1000
+ v = Int[0 , 0 ]
1001
+ for i = 1 : 2
1002
+ v[i] = Core . getfield (z, i)
1003
1003
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 ) Core . getfield (z, - 1 )
1006
+ @test_throws BoundsError (z, 0 ) Core . getfield (z, 0 )
1007
+ @test_throws BoundsError (z, 3 ) Core . getfield (z, 3 )
1008
1008
1009
1009
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 ) Core. getfield (strct, 10 )
1012
+ @test_throws BoundsError (strct, 10 ) getfield (strct, 10 )
1013
+ @test_throws ErrorException (" type LoadError is immutable" ) Core. setfield! (strct, 0 , " " )
1014
+ @test_throws ErrorException (" type LoadError is immutable" ) Core. setfield! (strct, 4 , " " )
1015
+ @test_throws BoundsError (LoadError, 0 ) setfield! (strct, 0 , " " )
1016
+ @test_throws BoundsError (LoadError, 4 ) setfield! (strct, 4 , " " )
1013
1017
@test strct. file == " yofile"
1014
1018
@test strct. line == 0
1015
1019
@test strct. error == " bad"
1016
- @test getfield (strct, 1 ) == " yofile"
1017
- @test getfield (strct, 2 ) == 0
1018
- @test getfield (strct, 3 ) == " bad"
1020
+ @test Core . getfield (strct, 1 ) == " yofile"
1021
+ @test Core . getfield (strct, 2 ) == 0
1022
+ @test Core . getfield (strct, 3 ) == " bad"
1019
1023
1020
1024
mstrct = TestMutable (" melm" , 1 , nothing )
1021
- setfield! (mstrct, 2 , 8 )
1025
+ setfield! (mstrct, 2 , 8.0 )
1022
1026
@test mstrct. line == 8
1023
- setfield! (mstrct, 3 , " hi" )
1027
+ @test_throws TypeError (:setfield! , " " , Int, 8.0 ) Core. setfield! (mstrct, 2 , 8.0 )
1028
+ Core. setfield! (mstrct, 3 , " hi" )
1024
1029
@test mstrct. error == " hi"
1025
- setfield! (mstrct, 1 , " yo" )
1030
+ Core . setfield! (mstrct, 1 , " yo" )
1026
1031
@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 , " " )
1032
+ @test_throws BoundsError (mstrct, 10 ) Core. getfield (mstrct, 10 )
1033
+ @test_throws BoundsError (mstrct, 0 ) Core. setfield! (mstrct, 0 , " " )
1034
+ @test_throws BoundsError (mstrct, 4 ) Core. setfield! (mstrct, 4 , " " )
1035
+ @test_throws BoundsError (mstrct, 10 ) getfield (mstrct, 10 )
1036
+ @test_throws BoundsError (TestMutable, 0 ) setfield! (mstrct, 0 , " " )
1037
+ @test_throws BoundsError (TestMutable, 4 ) setfield! (mstrct, 4 , " " )
1030
1038
end
1031
1039
1032
1040
# allow typevar in Union to match as long as the arguments contain
@@ -2175,10 +2183,9 @@ g7652() = fieldtype(DataType, :types)
2175
2183
h7652 () = setfield! (a7652, 1 , 2 )
2176
2184
h7652 ()
2177
2185
@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
2186
+ i7652 () = setfield! (a7652, 1 , 3.0 )
2187
+ i7652 ()
2188
+ @test a7652. a == 3
2182
2189
2183
2190
# issue #7679
2184
2191
@test map (f-> f (), Any[ ()-> i for i= 1 : 3 ]) == Any[1 ,2 ,3 ]
@@ -2358,49 +2365,53 @@ let
2358
2365
end
2359
2366
2360
2367
# 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
2368
+ @test_throws BoundsError ((1 , 2 ), 3 ) begin ; a, b, c = 1 , 2 ; end
2369
+ let a = []
2370
+ @test_broken try ; a[]; catch ex; (ex:: BoundsError ). a === a && ex. i == (1 ,); end # TODO : Re-enable after PLI
2371
+ @test_throws BoundsError (a, (1 , 2 )) a[1 , 2 ]
2372
+ @test_throws BoundsError (a, (10 ,)) a[10 ]
2373
+ end
2374
+ f9534a () = (a = 1 + 2im ; Core. getfield (a, - 100 ))
2375
+ f9534a (x) = (a = 1 + 2im ; Core. getfield (a, x))
2376
+ @test_throws BoundsError (1 + 2im , - 100 ) f9534a ()
2377
+ @test_throws BoundsError (1 + 2im , 3 ) f9534a (3 )
2378
+ f9534b () = (a = (1 , 2. , " " ); a[5 ])
2379
+ f9534b (x) = (a = (1 , 2. , " " ); a[x])
2380
+ @test_throws BoundsError ((1 , 2. , " " ), 5 ) f9534b ()
2381
+ @test_throws BoundsError ((1 , 2. , " " ), 4 ) f9534b (4 )
2382
+ f9534c () = (a = (1 , 2. ); a[3 ])
2383
+ f9534c (x) = (a = (1 , 2. ); a[x])
2384
+ @test_throws BoundsError ((1 , 2. ), 3 ) f9534c ()
2385
+ @test_throws BoundsError ((1 , 2. ), 0 ) f9534c (0 )
2386
+ f9534d () = (a = (1 , 2 , 4 , 6 , 7 ); a[7 ])
2387
+ f9534d (x) = (a = (1 , 2 , 4 , 6 , 7 ); a[x])
2388
+ @test_throws BoundsError ((1 , 2 , 4 , 6 , 7 ), 7 ) f9534d ()
2389
+ @test_throws BoundsError ((1 , 2 , 4 , 6 , 7 ), - 1 ) f9534d (- 1 )
2390
+ let a = IOBuffer ()
2391
+ f9534e (x) = Core. setfield! (a, x, 3 )
2392
+ @test_throws BoundsError (a, - 2 ) f9534e (- 2 )
2393
+ f9534f () = Core. getfield (a, - 2 )
2394
+ f9534f (x) = Core. getfield (a, x)
2395
+ @test_throws BoundsError (a, - 2 ) f9534f ()
2396
+ @test_throws BoundsError (a, typemin (Int) + 2 ) f9534f (typemin (Int) + 2 )
2397
+ end
2387
2398
x9634 = 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
2399
+ @test_throws BoundsError ( 1 + 2im , 3 ) Core . getfield ( 1 + 2im , x9634)
2400
+ @test try ; throw (BoundsError ()); catch ex; ! isdefined ((ex:: BoundsError ), :a ) && ! isdefined ((ex:: BoundsError ), :i ); end
2401
+ @test try ; throw (BoundsError (Int)); catch ex; (ex:: BoundsError ). a == Int && ! isdefined ((ex:: BoundsError ), :i ); end
2402
+ @test_throws BoundsError (Int, typemin (Int)) throw ( BoundsError ( Int, typemin (Int)))
2403
+ @test_throws BoundsError (Int, (:a ,)) throw ( BoundsError ( Int, ( : a ,)))
2404
+ f9534g (a, b, c... ) = c[0 ]
2405
+ @test_throws BoundsError (( 3 , 4 , 5 , 6 ), 0 ) f9534g ( 1 , 2 , 3 , 4 , 5 , 6 )
2406
+ f9534h (a, b, c... ) = c[a]
2407
+ @test f9534h (4 , 2 , 3 , 4 , 5 , 6 ) == 6
2408
+ @test_throws BoundsError (( 3 , 4 , 5 , 6 ), 5 ) f9534h ( 5 , 2 , 3 , 4 , 5 , 6 )
2398
2409
2399
2410
# issue #7978, comment 332352438
2400
2411
f7978a () = 1
2401
- @test try ; a, b = f7978a () catch ex; (ex :: BoundsError ) . a == 1 && ex . i == 2 ; end
2412
+ @test_throws BoundsError ( 1 , 2 ) begin ; a, b = f7978a (); end
2402
2413
f7978b () = 1 , 2
2403
- @test try ; a, b, c = f7978b () catch ex; (ex :: BoundsError ) . a == ( 1 , 2 ) && ex . i == 3 ; end
2414
+ @test_throws BoundsError (( 1 , 2 ), 3 ) begin ; a, b, c = f7978b () ; end
2404
2415
2405
2416
# issue #9535
2406
2417
counter9535 = 0
0 commit comments