@@ -371,7 +371,7 @@ begin
371
371
global f7234_cnt += - 10000
372
372
end
373
373
end
374
- @test_throws UndefVarError f7234_a ()
374
+ @test_throws UndefVarError ( :glob_x2 ) f7234_a ()
375
375
@test f7234_cnt == 1
376
376
begin
377
377
global glob_x2 = 24
@@ -381,11 +381,11 @@ begin
381
381
global f7234_cnt += - 10000
382
382
end
383
383
end
384
- @test_throws UndefVarError f7234_b ()
384
+ @test_throws UndefVarError ( :glob_x2 ) f7234_b ()
385
385
@test f7234_cnt == 2
386
- # existing globals can be inherited by non-function blocks
386
+ # globals can accessed if declared
387
387
for i = 1 : 2
388
- glob_x2 += 1
388
+ global glob_x2 += 1
389
389
end
390
390
@test glob_x2 == 26
391
391
# globals declared as such in a non-global scope are inherited
@@ -454,15 +454,15 @@ function const_implies_local()
454
454
end
455
455
@test const_implies_local () === (1 , 0 )
456
456
457
- a = Vector {Any} (3 )
458
- for i= 1 : 3
457
+ a_global_closure_vector = Vector {Any} (3 )
458
+ for i = 1 : 3
459
459
let ii = i
460
- a [i] = x-> x + ii
460
+ a_global_closure_vector [i] = x -> x + ii
461
461
end
462
462
end
463
- @test a [1 ](10 ) == 11
464
- @test a [2 ](10 ) == 12
465
- @test a [3 ](10 ) == 13
463
+ @test a_global_closure_vector [1 ](10 ) == 11
464
+ @test a_global_closure_vector [2 ](10 ) == 12
465
+ @test a_global_closure_vector [3 ](10 ) == 13
466
466
467
467
# issue #22032
468
468
let a = [], fs = []
499
499
@test_throws UndefVarError f21900 ()
500
500
@test f21900_cnt == 1
501
501
502
- @test_throws UndefVarError @eval begin
502
+ # use @eval so this runs as a toplevel scope block
503
+ @test_throws UndefVarError (:foo21900 ) @eval begin
503
504
for i21900 = 1 : 10
505
+ local bar21900
504
506
for j21900 = 1 : 10
505
507
foo21900 = 10
506
508
end
511
513
@test ! @isdefined (foo21900)
512
514
@test ! @isdefined (bar21900)
513
515
bar21900 = 0
514
- @test_throws UndefVarError @eval begin
516
+ @test_throws UndefVarError ( :foo21900 ) @eval begin
515
517
for i21900 = 1 : 10
518
+ global bar21900
516
519
for j21900 = 1 : 10
517
520
foo21900 = 10
518
521
end
523
526
@test bar21900 == - 1
524
527
@test ! @isdefined foo21900
525
528
foo21900 = 0
526
- @test nothing === @eval begin
529
+ @test nothing === begin
527
530
for i21900 = 1 : 10
531
+ global bar21900, foo21900
528
532
for j21900 = 1 : 10
529
533
foo21900 = 10
530
534
end
@@ -682,40 +686,47 @@ end
682
686
683
687
# try/finally
684
688
begin
685
- after = 0
686
- b = try
689
+ try_finally_glo_after = 0
690
+ try_finally_loc_after = 0
691
+ try_finally_glo_b = try
687
692
1 + 2
688
693
finally
689
- after = 1
694
+ # try_finally_loc_after = 1 # enable with #19324
695
+ global try_finally_glo_after = 1
690
696
end
691
- @test b == 3
692
- @test after == 1
697
+ @test try_finally_loc_after == 0
698
+ @test try_finally_glo_b == 3
699
+ @test try_finally_glo_after == 1
693
700
694
- after = 0
701
+ try_finally_glo_after = 0
695
702
gothere = 0
696
703
try
697
704
try
698
705
error (" " )
699
706
finally
700
- after = 1
707
+ # try_finally_loc_after = 1 # enable with #19324
708
+ global try_finally_glo_after = 1
701
709
end
702
- gothere = 1
710
+ global gothere = 1
703
711
end
704
- @test after == 1
712
+ @test try_finally_loc_after == 0
713
+ @test try_finally_glo_after == 1
705
714
@test gothere == 0
706
715
707
- after = 0
708
- b = try
716
+ try_finally_glo_after = 0
717
+ try_finally_glo_b = try
709
718
error (" " )
710
719
catch
711
720
42
712
721
finally
713
- after = 1
722
+ # try_finally_loc_after = 1 # enable with #19324
723
+ global try_finally_glo_after = 1
714
724
end
715
- @test b == 42
716
- @test after == 1
725
+ @test try_finally_loc_after == 0
726
+ @test try_finally_glo_b == 42
727
+ @test try_finally_glo_after == 1
717
728
718
- glo = 0
729
+ global glo = 0
719
730
function retfinally ()
720
731
try
721
732
return 5
@@ -1223,7 +1234,7 @@ C3729{D} = Vector{Vector{D}}
1223
1234
# issue #3789
1224
1235
x3789 = 0
1225
1236
while (all ([false for idx in 1 : 10 ]))
1226
- x3789 = 1
1237
+ global x3789 = 1
1227
1238
end
1228
1239
@test x3789 == 0
1229
1240
@@ -1446,7 +1457,7 @@ b4688(y) = "not an Int"
1446
1457
begin
1447
1458
a4688 (y:: Int ) = " an Int"
1448
1459
let x = true
1449
- b4688 (y:: Int ) = x == true ? a4688 (y) : a4688 (y)
1460
+ global b4688 (y:: Int ) = x == true ? a4688 (y) : a4688 (y)
1450
1461
end
1451
1462
end
1452
1463
@test b4688 (1 ) == " an Int"
@@ -1540,9 +1551,8 @@ function tupledispatch(a::TupleParam{(1,:a)})
1540
1551
a. x
1541
1552
end
1542
1553
1543
- let
1544
- # tuples can be used as type params
1545
- t1 = TupleParam {(1,:a)} (true )
1554
+ # tuples can be used as type params
1555
+ let t1 = TupleParam {(1,:a)} (true ),
1546
1556
t2 = TupleParam {(1,:b)} (true )
1547
1557
1548
1558
# tuple type params can't contain invalid type params
@@ -2003,11 +2013,13 @@ function issue7897!(data, arr)
2003
2013
a = arr[1 ]
2004
2014
end
2005
2015
2006
- a = ones (UInt8, 10 )
2007
- sa = view (a,4 : 6 )
2008
- # This can throw an error, but shouldn't segfault
2009
- try
2010
- issue7897! (sa, zeros (10 ))
2016
+ let
2017
+ a = ones (UInt8, 10 )
2018
+ sa = view (a, 4 : 6 )
2019
+ # This can throw an error, but shouldn't segfault
2020
+ try
2021
+ issue7897! (sa, zeros (10 ))
2022
+ end
2011
2023
end
2012
2024
2013
2025
# issue #7582
@@ -3813,7 +3825,8 @@ end
3813
3825
# issue #15283
3814
3826
j15283 = 0
3815
3827
let
3816
- k15283 = j15283+= 1
3828
+ global j15283
3829
+ k15283 = (j15283 += 1 )
3817
3830
end
3818
3831
@test j15283 == 1
3819
3832
@test ! @isdefined k15283
@@ -4467,12 +4480,12 @@ end
4467
4480
@test_throws ErrorException main18986 ()
4468
4481
4469
4482
# issue #18085
4470
- f18085 (a,x... ) = (0 ,)
4471
- for (f,g) in ((:asin ,:sin ), (:acos ,:cos ))
4483
+ f18085 (a, x... ) = (0 , )
4484
+ for (f, g) in ((:asin , :sin ), (:acos , :cos ))
4472
4485
gx = eval (g)
4473
- f18085 (:: Type{Val{f}} ,x... ) = map (x-> 2 gx (x), f18085 (Val{g},x... ))
4486
+ global f18085 (:: Type{Val{f}} , x... ) = map (x -> 2 gx (x), f18085 (Val{g}, x... ))
4474
4487
end
4475
- @test f18085 (Val{:asin },3 ) === (0.0 ,)
4488
+ @test f18085 (Val{:asin }, 3 ) === (0.0 ,)
4476
4489
4477
4490
# issue #18236 constant VecElement in ast triggers codegen assertion/undef
4478
4491
# VecElement of scalar
0 commit comments