@@ -1557,7 +1557,7 @@ let ex = Meta.parse("@test27521(2) do y; y; end")
15571557 fex = Expr (:(-> ), Expr (:tuple , :y ), Expr (:block , LineNumberNode (1 ,:none ), :y ))
15581558 @test ex == Expr (:do , Expr (:macrocall , Symbol (" @test27521" ), LineNumberNode (1 ,:none ), 2 ),
15591559 fex)
1560- @test macroexpand (@__MODULE__ , ex) == Expr (:tuple , fex, 2 )
1560+ @test macroexpand (@__MODULE__ , ex). args[ 1 ] == Expr (:tuple , esc ( fex) , 2 )
15611561end
15621562
15631563# issue #43018
@@ -3530,110 +3530,4 @@ end
35303530@test eval (:(if false
35313531 elseif false || (()-> true )()
35323532 42
3533- end )) == 42
3534-
3535- macro _macroexpand (x, m= __module__)
3536- :($ __source__; macroexpand ($ m, Expr (:var"hygienic-scope" , $ (esc (Expr (:quote , x))), $ m)))
3537- end
3538-
3539- @testset " unescaping in :global expressions" begin
3540- m = @__MODULE__
3541- @test @_macroexpand (global x:: T ) == :(global x:: $ (GlobalRef (m, :T )))
3542- @test @_macroexpand (global (x, $ (esc (:y )))) == :(global (x, y))
3543- @test @_macroexpand (global (x:: S , $ (esc (:y )):: $ (esc (:T )))) ==
3544- :(global (x:: $ (GlobalRef (m, :S )), y:: T ))
3545- @test @_macroexpand (global (; x, $ (esc (:y )))) == :(global (; x, y))
3546- @test @_macroexpand (global (; x:: S , $ (esc (:y )):: $ (esc (:T )))) ==
3547- :(global (; x:: $ (GlobalRef (m, :S )), y:: T ))
3548-
3549- @test @_macroexpand (global x:: T = a) == :(global x:: $ (GlobalRef (m, :T )) = $ (GlobalRef (m, :a )))
3550- @test @_macroexpand (global (x, $ (esc (:y ))) = a) == :(global (x, y) = $ (GlobalRef (m, :a )))
3551- @test @_macroexpand (global (x:: S , $ (esc (:y )):: $ (esc (:T ))) = a) ==
3552- :(global (x:: $ (GlobalRef (m, :S )), y:: T ) = $ (GlobalRef (m, :a )))
3553- @test @_macroexpand (global (; x, $ (esc (:y ))) = a) == :(global (; x, y) = $ (GlobalRef (m, :a )))
3554- @test @_macroexpand (global (; x:: S , $ (esc (:y )):: $ (esc (:T ))) = a) ==
3555- :(global (; x:: $ (GlobalRef (m, :S )), y:: T ) = $ (GlobalRef (m, :a )))
3556- end
3557-
3558- # issue #49920
3559- let line1 = (quote end ). args[1 ],
3560- line2 = (quote end ). args[1 ],
3561- line3 = (quote end ). args[1 ]
3562- @test 1 === eval (Meta. lower (Main, Expr (:block , line1, 1 , line2, line3)))
3563- end
3564-
3565- # issue #49984
3566- macro z49984 (s); :(let a; $ (esc (s)); end ); end
3567- @test let a = 1 ; @z49984 (a) === 1 ; end
3568-
3569- # issues #37783, #39929, #42552, #43379, and #48332
3570- let x = 1 => 2
3571- @test_throws ErrorException @eval a => b = 2
3572- @test_throws " function Base.=> must be explicitly imported to be extended" @eval a => b = 2
3573- end
3574-
3575- # Splatting in non-final default value (Ref #50518)
3576- for expr in (quote
3577- function g1 (a= (1 ,2 ). .. , b... = 3 )
3578- b
3579- end
3580- end ,quote
3581- function g2 (a= (1 ,2 ). .. , b= 3 , c= 4 )
3582- (b, c)
3583- end
3584- end ,quote
3585- function g3 (a= (1 ,2 ). .. , b= 3 , c... = 4 )
3586- (b, c)
3587- end
3588- end )
3589- let exc = try eval (expr); catch exc; exc end
3590- @test isa (exc, ErrorException)
3591- @test startswith (exc. msg, " syntax: invalid \" ...\" in non-final positional argument default value" )
3592- end
3593- end
3594-
3595- # Test that bad lowering does not segfault (ref #50518)
3596- @test_throws ErrorException (" syntax: Attempted to use slot marked unused" ) @eval function funused50518 (:: Float64 )
3597- $ (Symbol (" #unused#" ))
3598- end
3599-
3600- @testset " public keyword" begin
3601- p (str) = Base. remove_linenums! (Meta. parse (str))
3602- # tests ported from JuliaSyntax.jl
3603- @test p (" function f(public)\n public + 3\n end" ) == Expr (:function , Expr (:call , :f , :public ), Expr (:block , Expr (:call , :+ , :public , 3 )))
3604- @test p (" public A, B" ) == Expr (:public , :A , :B )
3605- @test p (" if true \n public *= 4 \n end" ) == Expr (:if , true , Expr (:block , Expr (:*= , :public , 4 )))
3606- @test p (" module Mod\n public A, B \n end" ) == Expr (:module , true , :Mod , Expr (:block , Expr (:public , :A , :B )))
3607- @test p (" module Mod2\n a = 3; b = 6; public a, b\n end" ) == Expr (:module , true , :Mod2 , Expr (:block , Expr (:(= ), :a , 3 ), Expr (:(= ), :b , 6 ), Expr (:public , :a , :b )))
3608- @test p (" a = 3; b = 6; public a, b" ) == Expr (:toplevel , Expr (:(= ), :a , 3 ), Expr (:(= ), :b , 6 ), Expr (:public , :a , :b ))
3609- @test_throws Meta. ParseError p (" begin \n public A, B \n end" )
3610- @test_throws Meta. ParseError p (" if true \n public A, B \n end" )
3611- @test_throws Meta. ParseError p (" public export=true foo, bar" )
3612- @test_throws Meta. ParseError p (" public experimental=true foo, bar" )
3613- @test p (" public(x::String) = false" ) == Expr (:(= ), Expr (:call , :public , Expr (:(:: ), :x , :String )), Expr (:block , false ))
3614- @test p (" module M; export @a; end" ) == Expr (:module , true , :M , Expr (:block , Expr (:export , :var"@a" )))
3615- @test p (" module M; public @a; end" ) == Expr (:module , true , :M , Expr (:block , Expr (:public , :var"@a" )))
3616- @test p (" module M; export ⤈; end" ) == Expr (:module , true , :M , Expr (:block , Expr (:export , :⤈ )))
3617- @test p (" module M; public ⤈; end" ) == Expr (:module , true , :M , Expr (:block , Expr (:public , :⤈ )))
3618- @test p (" public = 4" ) == Expr (:(= ), :public , 4 )
3619- @test p (" public[7] = 5" ) == Expr (:(= ), Expr (:ref , :public , 7 ), 5 )
3620- @test p (" public() = 6" ) == Expr (:(= ), Expr (:call , :public ), Expr (:block , 6 ))
3621- end
3622-
3623- @testset " removing argument sideeffects" begin
3624- # Allow let blocks in broadcasted LHSes, but only evaluate them once:
3625- execs = 0
3626- array = [1 ]
3627- let x = array; execs += 1 ; x; end .+ = 2
3628- @test array == [3 ]
3629- @test execs == 1
3630- let ; execs += 1 ; array; end .= 4
3631- @test array == [4 ]
3632- @test execs == 2
3633- let x = array; execs += 1 ; x; end :: Vector{Int} .+ = 2
3634- @test array == [6 ]
3635- @test execs == 3
3636- let ; execs += 1 ; array; end :: Vector{Int} .= 7
3637- @test array == [7 ]
3638- @test execs == 4
3639- end
3533+ end )) == 42
0 commit comments