"Fossies" - the Fresh Open Source Software Archive

Member "julia-1.1.1/share/julia/test/syntax.jl" (16 May 2019, 55710 Bytes) of package /linux/misc/julia-1.1.1-linux-i686.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Julia source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # This file is a part of Julia. License is MIT: https://julialang.org/license
    2 
    3 # tests for parser and syntax lowering
    4 
    5 using Random
    6 
    7 import Base.Meta.ParseError
    8 
    9 function parseall(str)
   10     pos = firstindex(str)
   11     exs = []
   12     while pos <= lastindex(str)
   13         ex, pos = Meta.parse(str, pos)
   14         push!(exs, ex)
   15     end
   16     if length(exs) == 0
   17         throw(ParseError("end of input"))
   18     elseif length(exs) == 1
   19         return exs[1]
   20     else
   21         return Expr(:block, exs...)
   22     end
   23 end
   24 
   25 # issue #9684
   26 let
   27     undot(op) = Symbol(string(op)[2:end])
   28     for (ex1, ex2) in [("5 .≠ x", "5 .!= x"),
   29                        ("5 .≥ x", "5 .>= x"),
   30                        ("5 .≤ x", "5 .<= x")]
   31         ex1 = Meta.parse(ex1); ex2 = Meta.parse(ex2)
   32         @test ex1.head === :call && (ex1.head === ex2.head)
   33         @test ex1.args[2] === 5 && ex2.args[2] === 5
   34         @test Core.eval(Main, undot(ex1.args[1])) === Core.eval(Main, undot(ex2.args[1]))
   35         @test ex1.args[3] === :x && (ex1.args[3] === ex2.args[3])
   36     end
   37 end
   38 
   39 # issue #9704
   40 let a = :a
   41     @test :(try
   42             catch $a
   43             end) == :(try
   44                       catch a
   45                       end)
   46     @test :(module $a end) == :(module a
   47                                 end)
   48 end
   49 
   50 # string literals
   51 macro test999_str(args...); args; end
   52 @test test999"a"b == ("a","b")
   53 @test test999"""a"""b == ("a","b")
   54 @test test999"
   55     a
   56     b" == ("
   57     a
   58     b",)
   59 @test test999"""
   60     a
   61     b""" == ("a\nb",)
   62 
   63 # issue #5997
   64 @test_throws ParseError Meta.parse(": x")
   65 @test_throws ParseError Meta.parse("""begin
   66     :
   67     x""")
   68 @test_throws ParseError Meta.parse("d[: 2]")
   69 
   70 # issue #6770
   71 @test_throws ParseError Meta.parse("x.3")
   72 
   73 # issue #8763
   74 @test_throws ParseError Meta.parse("sqrt(16)2")
   75 @test_throws ParseError Meta.parse("x' y")
   76 @test_throws ParseError Meta.parse("x 'y")
   77 @test Meta.parse("x'y") == Expr(:call, :*, Expr(Symbol("'"), :x), :y)
   78 
   79 # issue #18851
   80 @test Meta.parse("-2[m]") == Expr(:call, :-, Expr(:ref, 2, :m))
   81 @test Meta.parse("+2[m]") == Expr(:call, :+, Expr(:ref, 2, :m))
   82 @test Meta.parse("!2[3]") == Expr(:call, :!, Expr(:ref, 2, 3))
   83 @test Meta.parse("-2{m}") == Expr(:call, :-, Expr(:curly, 2, :m))
   84 @test Meta.parse("+2{m}") == Expr(:call, :+, Expr(:curly, 2, :m))
   85 @test Meta.parse("-2(m)") == Expr(:call, :*, -2, :m)
   86 
   87 # issue #8301
   88 @test_throws ParseError Meta.parse("&*s")
   89 
   90 # issue #10677
   91 @test_throws ParseError Meta.parse("/1")
   92 @test_throws ParseError Meta.parse("/pi")
   93 @test Meta.parse("- = 2") == Expr(:(=), :(-), 2)
   94 @test Meta.parse("/ = 2") == Expr(:(=), :(/), 2)
   95 @test_throws ParseError Meta.parse("< : 2")
   96 @test_throws ParseError Meta.parse("+ : 2")
   97 @test_throws ParseError Meta.parse("< :2")
   98 @test Meta.parse("+ :2") == Expr(:call, :(+), QuoteNode(2))
   99 
  100 # issue #10900
  101 @test_throws ParseError Meta.parse("+=")
  102 @test_throws ParseError Meta.parse(".")
  103 @test_throws ParseError Meta.parse("...")
  104 
  105 # issue #10901
  106 @test Meta.parse("/([1], 1)[1]") == :(([1] / 1)[1])
  107 
  108 # issue #10997
  109 @test Meta.parse(":(x.\$f[i])") == Expr(:quote,
  110                                    Expr(:ref,
  111                                         Expr(Symbol("."), :x,
  112                                              QuoteNode(Expr(:$, :f))),
  113                                         :i))
  114 
  115 # issue #10994
  116 @test Meta.parse("1 + #= \0 =# 2") == :(1 + 2)
  117 
  118 # issue #10910
  119 @test Meta.parse(":(using A)") == Expr(:quote, Expr(:using, Expr(:., :A)))
  120 @test Meta.parse(":(using A.b, B)") == Expr(:quote,
  121                                        Expr(:using,
  122                                             Expr(:., :A, :b),
  123                                             Expr(:., :B)))
  124 @test Meta.parse(":(using A: b, c.d)") == Expr(:quote,
  125                                           Expr(:using,
  126                                                Expr(:(:),
  127                                                     Expr(:., :A),
  128                                                     Expr(:., :b),
  129                                                     Expr(:., :c, :d))))
  130 
  131 @test Meta.parse(":(import A)") == Expr(:quote, Expr(:import, Expr(:., :A)))
  132 @test Meta.parse(":(import A.b, B)") == Expr(:quote,
  133                                         Expr(:import,
  134                                              Expr(:., :A, :b),
  135                                              Expr(:., :B)))
  136 @test Meta.parse(":(import A: b, c.d)") == Expr(:quote,
  137                                            Expr(:import,
  138                                                 Expr(:(:),
  139                                                      Expr(:., :A),
  140                                                      Expr(:., :b),
  141                                                      Expr(:., :c, :d))))
  142 
  143 # issue #11332
  144 @test Meta.parse("export \$(Symbol(\"A\"))") == :(export $(Expr(:$, :(Symbol("A")))))
  145 @test Meta.parse("export \$A") == :(export $(Expr(:$, :A)))
  146 @test Meta.parse("using \$a.\$b") == Expr(:using, Expr(:., Expr(:$, :a), Expr(:$, :b)))
  147 @test Meta.parse("using \$a.\$b, \$c") == Expr(:using,
  148                                                Expr(:., Expr(:$, :a), Expr(:$, :b)),
  149                                                Expr(:., Expr(:$, :c)))
  150 @test Meta.parse("using \$a: \$b, \$c.\$d") ==
  151     Expr(:using,
  152          Expr(:(:), Expr(:., Expr(:$, :a)), Expr(:., Expr(:$, :b)),
  153               Expr(:., Expr(:$, :c), Expr(:$, :d))))
  154 
  155 # fix pr #11338 and test for #11497
  156 @test parseall("using \$\na") == Expr(:block, Expr(:using, Expr(:., :$)), :a)
  157 @test parseall("using \$,\na") == Expr(:using, Expr(:., :$), Expr(:., :a))
  158 @test parseall("using &\na") == Expr(:block, Expr(:using, Expr(:., :&)), :a)
  159 
  160 @test parseall("a = &\nb") == Expr(:block, Expr(:(=), :a, :&), :b)
  161 @test parseall("a = \$\nb") == Expr(:block, Expr(:(=), :a, :$), :b)
  162 @test parseall(":(a = &\nb)") == Expr(:quote, Expr(:(=), :a, Expr(:&, :b)))
  163 @test parseall(":(a = \$\nb)") == Expr(:quote, Expr(:(=), :a, Expr(:$, :b)))
  164 
  165 # issue 11970
  166 @test parseall("""
  167     macro f(args...) end; @f "macro argument"
  168 """) == Expr(:toplevel,
  169              Expr(:macro, Expr(:call, :f, Expr(:..., :args)), Expr(:block, LineNumberNode(1, :none))),
  170              Expr(:macrocall, Symbol("@f"), LineNumberNode(1, :none), "macro argument"))
  171 
  172 # blocks vs. tuples
  173 @test Meta.parse("()") == Expr(:tuple)
  174 @test Meta.parse("(;)") == Expr(:block)
  175 @test Meta.parse("(;;;;)") == Expr(:block)
  176 @test_throws ParseError Meta.parse("(,)")
  177 @test_throws ParseError Meta.parse("(;,)")
  178 @test_throws ParseError Meta.parse("(,;)")
  179 # TODO: would be nice to make these errors, but needed to parse e.g. `(x;y,)->x`
  180 #@test_throws ParseError Meta.parse("(1;2,)")
  181 #@test_throws ParseError Meta.parse("(1;2,;)")
  182 #@test_throws ParseError Meta.parse("(1;2,;3)")
  183 @test Meta.parse("(x;)") == Expr(:block, :x)
  184 @test Meta.parse("(;x)") == Expr(:tuple, Expr(:parameters, :x))
  185 @test Meta.parse("(;x,)") == Expr(:tuple, Expr(:parameters, :x))
  186 @test Meta.parse("(x,)") == Expr(:tuple, :x)
  187 @test Meta.parse("(x,;)") == Expr(:tuple, Expr(:parameters), :x)
  188 @test Meta.parse("(x;y)") == Expr(:block, :x, LineNumberNode(1,:none), :y)
  189 @test Meta.parse("(x...;)") == Expr(:tuple, Expr(:parameters), Expr(:(...), :x))
  190 @test Meta.parse("(;x...)") == Expr(:tuple, Expr(:parameters, Expr(:(...), :x)))
  191 @test Meta.parse("(x...;y)") == Expr(:tuple, Expr(:parameters, :y), Expr(:(...), :x))
  192 @test Meta.parse("(x;y...)") == Expr(:block, :x, LineNumberNode(1,:none), Expr(:(...), :y))
  193 @test Meta.parse("(x=1;y=2)") == Expr(:block, Expr(:(=), :x, 1), LineNumberNode(1,:none), Expr(:(=), :y, 2))
  194 @test Meta.parse("(x,;y)") == Expr(:tuple, Expr(:parameters, :y), :x)
  195 @test Meta.parse("(x,;y=1)") == Expr(:tuple, Expr(:parameters, Expr(:kw, :y, 1)), :x)
  196 @test Meta.parse("(x,a;y=1)") == Expr(:tuple, Expr(:parameters, Expr(:kw, :y, 1)), :x, :a)
  197 @test Meta.parse("(x,a;y=1,z=2)") == Expr(:tuple, Expr(:parameters, Expr(:kw,:y,1), Expr(:kw,:z,2)), :x, :a)
  198 @test Meta.parse("(a=1, b=2)") == Expr(:tuple, Expr(:(=), :a, 1), Expr(:(=), :b, 2))
  199 @test_throws ParseError Meta.parse("(1 2)") # issue #15248
  200 
  201 @test Meta.parse("f(x;)") == Expr(:call, :f, Expr(:parameters), :x)
  202 
  203 @test Meta.parse("1 == 2|>3") == Expr(:call, :(==), 1, Expr(:call, :(|>), 2, 3))
  204 
  205 # issue #24153
  206 @test Meta.parse("a|>b|>c|>d") == Meta.parse("((a|>b)|>c)|>d")
  207 @test Meta.parse("a<|b<|c<|d") == Meta.parse("a<|(b<|(c<|d))")
  208 
  209 # issue #12501 and pr #12502
  210 Meta.parse("""
  211       baremodule A
  212       "a" in b
  213       end
  214       """)
  215 Meta.parse("""
  216       baremodule A
  217       "a"
  218       end
  219       """)
  220 
  221 # issue #12626
  222 @test Meta.parse("a .÷ 1") == Expr(:call, :.÷, :a, 1)
  223 @test Meta.parse("a .÷= 1") == Expr(:.÷=, :a, 1)
  224 
  225 # issue #12771
  226 @test -(3)^2 == -9
  227 
  228 # issue #13302
  229 let p = Meta.parse("try
  230             a
  231         catch
  232             b, c = t
  233         end")
  234     @test isa(p,Expr) && p.head === :try
  235     @test p.args[2] === false
  236     @test p.args[3].args[end] == Meta.parse("b,c = t")
  237 end
  238 
  239 # pr #13078
  240 @test Meta.parse("a in b in c") == Expr(:comparison, :a, :in, :b, :in, :c)
  241 @test Meta.parse("a||b→c&&d") == Expr(:call, :,
  242                                  Expr(Symbol("||"), :a, :b),
  243                                  Expr(Symbol("&&"), :c, :d))
  244 
  245 # issue #11988 -- normalize \r and \r\n in literal strings to \n
  246 @test "foo\nbar" == Meta.parse("\"\"\"\r\nfoo\r\nbar\"\"\"") ==
  247     Meta.parse("\"\"\"\nfoo\nbar\"\"\"") == Meta.parse("\"\"\"\rfoo\rbar\"\"\"") ==
  248     Meta.parse("\"foo\r\nbar\"") == Meta.parse("\"foo\rbar\"") == Meta.parse("\"foo\nbar\"")
  249 @test '\r' == first("\r") == first("\r\n") # still allow explicit \r
  250 
  251 # allow invalid UTF-8 in string literals
  252 @test "\ud800"[1] == Char(0xd800)
  253 @test "\udfff"[1] == Char(0xdfff)
  254 @test length("\xc0\xb0") == 1
  255 @test "\xc0\xb0"[1] == reinterpret(Char, 0xc0b00000)
  256 
  257 # issue #14561 - generating 0-method generic function def
  258 let fname = :f
  259     @test :(function $fname end) == Expr(:function, :f)
  260 end
  261 
  262 # issue #14977
  263 @test Meta.parse("x = 1", 1) == (:(x = 1), 6)
  264 @test Meta.parse("x = 1", 6) == (nothing, 6)
  265 @test_throws BoundsError Meta.parse("x = 1", 0)
  266 @test_throws BoundsError Meta.parse("x = 1", -1)
  267 @test_throws BoundsError Meta.parse("x = 1", 7)
  268 
  269 # issue #14683
  270 @test_throws ParseError Meta.parse("'\\A\"'")
  271 @test Meta.parse("'\"'") == Meta.parse("'\\\"'") == '"' == "\""[1] == '\42'
  272 
  273 # issue #24558
  274 @test_throws ParseError Meta.parse("'\\xff'")
  275 @test_throws ParseError Meta.parse("'\\x80'")
  276 @test_throws ParseError Meta.parse("'ab'")
  277 @test '\u2200' == "\u2200"[1]
  278 
  279 @test_throws ParseError Meta.parse("f(2x for x=1:10, y")
  280 
  281 # issue #15223
  282 call0(f) = f()
  283 call1(f,x) = f(x)
  284 call2(f,x,y) = f(x,y)
  285 @test (call0() do; 42 end) == 42
  286 @test (call1(42) do x; x+1 end) == 43
  287 @test (call2(42,1) do x,y; x+y+1 end) == 44
  288 
  289 # definitions using comparison syntax
  290 let a⊂b = reduce(&, x ∈ b for x in a) && length(b)>length(a)
  291     @test [1,2] ⊂ [1,2,3,4]
  292     @test !([1,2] ⊂ [1,3,4])
  293     @test !([1,2] ⊂ [1,2])
  294 end
  295 
  296 # issue #9503
  297 @test Meta.parse("x<:y") == Expr(:(<:), :x, :y)
  298 @test Meta.parse("x>:y") == Expr(:(>:), :x, :y)
  299 @test Meta.parse("x<:y<:z").head === :comparison
  300 @test Meta.parse("x>:y<:z").head === :comparison
  301 
  302 # reason PR #19765, <- operator, was reverted
  303 @test -2<-1 # DO NOT ADD SPACES
  304 
  305 # issue #11169
  306 uncalled(x) = @test false
  307 fret() = uncalled(return true)
  308 @test fret()
  309 
  310 # issue #9617
  311 let p = 15
  312     @test 2p+1 == 31  # not a hex float literal
  313 end
  314 
  315 function test_parseerror(str, msg)
  316     try
  317         Meta.parse(str)
  318         @test false
  319     catch e
  320         @test isa(e,ParseError) && e.msg == msg
  321     end
  322 end
  323 test_parseerror("0x", "invalid numeric constant \"0x\"")
  324 test_parseerror("0b", "invalid numeric constant \"0b\"")
  325 test_parseerror("0o", "invalid numeric constant \"0o\"")
  326 test_parseerror("0x0.1", "hex float literal must contain \"p\" or \"P\"")
  327 test_parseerror("0x1.0p", "invalid numeric constant \"0x1.0\"")
  328 
  329 # issue #15798
  330 @test Meta.lower(Main, Base.parse_input_line("""
  331               try = "No"
  332            """)) == Expr(:error, "unexpected \"=\"")
  333 
  334 # issue #19861 make sure macro-expansion happens in the newest world for top-level expression
  335 @test eval(Base.parse_input_line("""
  336            macro X19861()
  337                return 23341
  338            end
  339            @X19861
  340            """)::Expr) == 23341
  341 
  342 # test parse_input_line for a streaming IO input
  343 let b = IOBuffer("""
  344                  let x = x
  345                      x
  346                  end
  347                  f()
  348                  """)
  349     @test Base.parse_input_line(b) == Expr(:let, Expr(:(=), :x, :x), Expr(:block, LineNumberNode(2, :none), :x))
  350     @test Base.parse_input_line(b) == Expr(:call, :f)
  351     @test Base.parse_input_line(b) === nothing
  352 end
  353 
  354 # issue #15763
  355 test_parseerror("if\nfalse\nend", "missing condition in \"if\" at none:1")
  356 test_parseerror("if false\nelseif\nend", "missing condition in \"elseif\" at none:2")
  357 
  358 # issue #15828
  359 @test Meta.lower(Main, Meta.parse("x...")) == Expr(:error, "\"...\" expression outside call")
  360 
  361 # issue #15830
  362 @test Meta.lower(Main, Meta.parse("foo(y = (global x)) = y")) == Expr(:error, "misplaced \"global\" declaration")
  363 
  364 # issue #15844
  365 function f15844(x)
  366     x
  367 end
  368 
  369 g15844 = let
  370     local function f15844(x::Int32)
  371         2x
  372     end
  373 end
  374 
  375 function add_method_to_glob_fn!()
  376     @eval global function f15844(x::Int64)
  377         3x
  378     end
  379 end
  380 
  381 add_method_to_glob_fn!()
  382 @test g15844 !== f15844
  383 @test g15844(Int32(1)) == 2
  384 @test f15844(Int32(1)) == 1
  385 @test f15844(Int64(1)) == 3
  386 
  387 # issue #15661
  388 @test_throws ParseError Meta.parse("function catch() end")
  389 @test_throws ParseError Meta.parse("function end() end")
  390 @test_throws ParseError Meta.parse("function finally() end")
  391 
  392 # PR #16170
  393 @test Meta.lower(Main, Meta.parse("true(x) = x")) == Expr(:error, "invalid function name \"true\"")
  394 @test Meta.lower(Main, Meta.parse("false(x) = x")) == Expr(:error, "invalid function name \"false\"")
  395 
  396 # issue #16355
  397 @test Meta.lower(Main, :(f(d:Int...) = nothing)) == Expr(:error, "\"d:Int\" is not a valid function argument name")
  398 
  399 # issue #16517
  400 @test (try error(); catch; 0; end) === 0
  401 @test (try error(); catch; false; end) === false  # false and true are Bool literals, not variables
  402 @test (try error(); catch; true; end) === true
  403 f16517() = try error(); catch; 0; end
  404 @test f16517() === 0
  405 
  406 # issue #16671
  407 @test Meta.parse("1.") === 1.0
  408 
  409 isline(x) = isa(x, LineNumberNode)
  410 
  411 # issue #16672
  412 @test count(isline, Meta.parse("begin end").args) == 1
  413 @test count(isline, Meta.parse("begin; end").args) == 1
  414 @test count(isline, Meta.parse("begin; x+2; end").args) == 1
  415 @test count(isline, Meta.parse("begin; x+2; y+1; end").args) == 2
  416 
  417 # issue #16736
  418 let
  419     local lineoffset0 = @__LINE__() + 1
  420     local lineoffset1 = @__LINE__()
  421     local lineoffset2 = @__LINE__() - 1
  422     @test lineoffset0 == lineoffset1 == lineoffset2
  423 end
  424 
  425 # issue #16686
  426 @test Meta.parse("try x
  427              catch; test()
  428                  y
  429              end") == Expr(:try,
  430                            Expr(:block,
  431                                 LineNumberNode(1, :none),
  432                                 :x),
  433                            false,
  434                            Expr(:block,
  435                                 LineNumberNode(2, :none),
  436                                 Expr(:call, :test),
  437                                 LineNumberNode(3, :none),
  438                                 :y))
  439 
  440 # test that pre 0.5 deprecated syntax is a parse error
  441 @test_throws ParseError Meta.parse("Int [1,2,3]")
  442 @test_throws ParseError Meta.parse("Int [x for x in 1:10]")
  443 @test_throws ParseError Meta.parse("foo (x) = x")
  444 @test_throws ParseError Meta.parse("foo {T<:Int}(x::T) = x")
  445 
  446 @test_throws ParseError Meta.parse("Foo .bar")
  447 
  448 @test_throws ParseError Meta.parse("import x .y")
  449 @test_throws ParseError Meta.parse("using x .y")
  450 
  451 @test_throws ParseError Meta.parse("--x")
  452 @test_throws ParseError Meta.parse("stagedfunction foo(x); end")
  453 
  454 @test Meta.parse("A=>B") == Expr(:call, :(=>), :A, :B)
  455 
  456 @test Meta.parse("{1,2,3}") == Expr(:braces, 1, 2, 3)
  457 @test Meta.parse("{1 2 3 4}") == Expr(:bracescat, Expr(:row, 1, 2, 3, 4))
  458 @test Meta.parse("{1 2; 3 4}") == Expr(:bracescat, Expr(:row, 1, 2), Expr(:row, 3, 4))
  459 @test Meta.parse("{x for x in 1:10}") == Expr(:braces, :(x for x in 1:10))
  460 @test Meta.parse("{x=>y for (x,y) in zip([1,2,3],[4,5,6])}") == Expr(:braces, :(x=>y for (x,y) in zip([1,2,3],[4,5,6])))
  461 @test Meta.parse("{:a=>1, :b=>2}") == Expr(:braces, Expr(:call, :(=>), QuoteNode(:a), 1),
  462                                       Expr(:call, :(=>), QuoteNode(:b), 2))
  463 
  464 @test Meta.parse("[a,b;c]")  == Expr(:vect, Expr(:parameters, :c), :a, :b)
  465 @test Meta.parse("[a,;c]")   == Expr(:vect, Expr(:parameters, :c), :a)
  466 @test Meta.parse("a[b,c;d]") == Expr(:ref, :a, Expr(:parameters, :d), :b, :c)
  467 @test Meta.parse("a[b,;d]")  == Expr(:ref, :a, Expr(:parameters, :d), :b)
  468 @test_throws ParseError Meta.parse("[a,;,b]")
  469 @test Meta.parse("{a,b;c}")  == Expr(:braces, Expr(:parameters, :c), :a, :b)
  470 @test Meta.parse("{a,;c}")   == Expr(:braces, Expr(:parameters, :c), :a)
  471 @test Meta.parse("a{b,c;d}") == Expr(:curly, :a, Expr(:parameters, :d), :b, :c)
  472 @test Meta.parse("a{b,;d}")  == Expr(:curly, :a, Expr(:parameters, :d), :b)
  473 
  474 # this now is parsed as getindex(Pair{Any,Any}, ...)
  475 @test_throws MethodError eval(Meta.parse("(Any=>Any)[]"))
  476 @test_throws MethodError eval(Meta.parse("(Any=>Any)[:a=>1,:b=>2]"))
  477 
  478 # issue #16720
  479 let err = try
  480     include_string(@__MODULE__, "module A
  481 
  482         function broken()
  483 
  484             x[1] = some_func(
  485 
  486         end
  487 
  488         end")
  489     catch e
  490         e
  491     end
  492     @test err.line == 7
  493 end
  494 
  495 # PR #17393
  496 for op in (:.==, :.&, :.|, :.≤)
  497     @test Meta.parse("a $op b") == Expr(:call, op, :a, :b)
  498 end
  499 for op in (:.=, :.+=)
  500     @test Meta.parse("a $op b") == Expr(op, :a, :b)
  501 end
  502 
  503 # issue #17489
  504 let m_error, error_out, filename = Base.source_path()
  505     m_error = try @eval method_c6(a::(:A)) = 1; catch e; e; end
  506     error_out = sprint(showerror, m_error)
  507     @test startswith(error_out, "ArgumentError: invalid type for argument a in method definition for method_c6 at $filename:")
  508 
  509     m_error = try @eval method_c6(::(:A)) = 2; catch e; e; end
  510     error_out = sprint(showerror, m_error)
  511     @test startswith(error_out, "ArgumentError: invalid type for argument number 1 in method definition for method_c6 at $filename:")
  512 
  513     # issue #20614
  514     m_error = try @eval foo(types::NTuple{N}, values::Vararg{Any,N}, c) where {N} = nothing; catch e; e; end
  515     error_out = sprint(showerror, m_error)
  516     @test startswith(error_out, "ArgumentError: Vararg on non-final argument")
  517 end
  518 
  519 # issue #7272
  520 @test Meta.lower(Main, Meta.parse("let
  521               global x = 2
  522               local x = 1
  523               end")) == Expr(:error, "variable \"x\" declared both local and global")
  524 #=
  525 @test Meta.lower(Main, Meta.parse("let
  526               local x = 2
  527               local x = 1
  528               end")) == Expr(:error, "local \"x\" declared twice")
  529 
  530 @test Meta.lower(Main, Meta.parse("let x
  531                   local x = 1
  532               end")) == Expr(:error, "local \"x\" declared twice")
  533 
  534 @test Meta.lower(Main, Meta.parse("let x = 2
  535                   local x = 1
  536               end")) == Expr(:error, "local \"x\" declared twice")
  537 =#
  538 # issue #23673
  539 @test :(let $([:(x=1),:(y=2)]...); x+y end) == :(let x = 1, y = 2; x+y end)
  540 
  541 # make sure front end can correctly print values to error messages
  542 let ex = Meta.lower(Main, Meta.parse("\"a\"=1"))
  543     @test ex == Expr(:error, "invalid assignment location \"\"a\"\"")
  544 end
  545 
  546 # make sure that incomplete tags are detected correctly
  547 # (i.e. error messages in src/julia-parser.scm must be matched correctly
  548 # by the code in base/client.jl)
  549 for (str, tag) in Dict("" => :none, "\"" => :string, "#=" => :comment, "'" => :char,
  550                        "`" => :cmd, "begin;" => :block, "quote;" => :block,
  551                        "let;" => :block, "for i=1;" => :block, "function f();" => :block,
  552                        "f() do x;" => :block, "module X;" => :block, "mutable struct X;" => :block,
  553                        "struct X;" => :block, "(" => :other, "[" => :other,
  554                        "begin" => :other, "quote" => :other,
  555                        "let" => :other, "for" => :other, "function" => :other,
  556                        "f() do" => :other, "module" => :other, "mutable struct" => :other,
  557                        "struct" => :other)
  558     @test Base.incomplete_tag(Meta.parse(str, raise=false)) == tag
  559 end
  560 
  561 # meta nodes for optional positional arguments
  562 @test Meta.lower(Main, :(@inline f(p::Int=2) = 3)).args[1].code[end-1].args[3].inlineable
  563 
  564 # issue #16096
  565 module M16096
  566 macro iter()
  567     return quote
  568         @inline function foo16096(sub)
  569             it = 1
  570         end
  571     end
  572 end
  573 end
  574 let ex = Meta.lower(M16096, :(@iter))
  575     @test isa(ex, Expr)
  576 end
  577 let ex = Meta.lower(Main, :($M16096.@iter))
  578     @test isa(ex, Expr)
  579 end
  580 let thismodule = @__MODULE__,
  581     ex = Meta.lower(thismodule, :(@M16096.iter))
  582     @test isa(ex, Expr)
  583     @test !isdefined(M16096, :foo16096)
  584     local_foo16096 = Core.eval(@__MODULE__, ex)
  585     @test local_foo16096(2.0) == 1
  586     @test !@isdefined foo16096
  587     @test !@isdefined it
  588     @test !isdefined(M16096, :foo16096)
  589     @test !isdefined(M16096, :it)
  590     @test typeof(local_foo16096).name.module === thismodule
  591     @test typeof(local_foo16096).name.mt.module === thismodule
  592     @test getfield(thismodule, typeof(local_foo16096).name.mt.name) === local_foo16096
  593     @test getfield(thismodule, typeof(local_foo16096).name.name) === typeof(local_foo16096)
  594     @test !isdefined(M16096, typeof(local_foo16096).name.mt.name)
  595     @test !isdefined(M16096, typeof(local_foo16096).name.name)
  596 end
  597 
  598 macro f16096()
  599     quote
  600         g16096($(esc(:x))) = 2x
  601     end
  602 end
  603 let g = @f16096
  604     @test g(3) == 6
  605 end
  606 macro f16096_2()
  607     quote
  608         g16096_2(; $(esc(:x))=2) = 2x
  609     end
  610 end
  611 let g = @f16096_2
  612     @test g() == 4
  613 end
  614 
  615 # issue #15838
  616 module A15838
  617     macro f() end
  618     const x = :a
  619 end
  620 module B15838
  621     import ..A15838.@f
  622     macro f(x); return :x; end
  623     const x = :b
  624 end
  625 @test A15838.@f() === nothing
  626 @test A15838.@f(1) === :b
  627 let ex = :(A15838.@f(1, 2)), __source__ = LineNumberNode(@__LINE__, Symbol(@__FILE__))
  628     nometh = try
  629         macroexpand(@__MODULE__, ex)
  630         false
  631     catch ex
  632         ex
  633     end::LoadError
  634     @test nometh.file === string(__source__.file)
  635     @test nometh.line === __source__.line
  636     e = nometh.error::MethodError
  637     @test e.f === getfield(A15838, Symbol("@f"))
  638     @test e.args === (__source__, @__MODULE__, 1, 2)
  639 end
  640 
  641 # issue 10046
  642 for op in ["+", "-", "\$", "|", ".+", ".-", "*", ".*"]
  643     @test_throws ParseError Meta.parse("$op in [+, -]")
  644 end
  645 
  646 # issue #17701
  647 @test Meta.lower(Main, :(i==3 && i+=1)) == Expr(:error, "invalid assignment location \"(i == 3) && i\"")
  648 
  649 # issue #18667
  650 @test Meta.lower(Main, :(true = 1)) == Expr(:error, "invalid assignment location \"true\"")
  651 @test Meta.lower(Main, :(false = 1)) == Expr(:error, "invalid assignment location \"false\"")
  652 
  653 # PR #15592
  654 let str = "[1] [2]"
  655     @test_throws ParseError Meta.parse(str)
  656 end
  657 
  658 # issue 15896 and PR 15913
  659 @test_throws ErrorException eval(:(macro test15896(d; y=0) end))
  660 
  661 # Issue #16578 (Lowering) mismatch between push_loc and pop_loc
  662 module TestMeta_16578
  663 using Test
  664 function get_expr_list(ex::Core.CodeInfo)
  665     return ex.code::Array{Any,1}
  666 end
  667 function get_expr_list(ex::Expr)
  668     if ex.head == :thunk
  669         return get_expr_list(ex.args[1])
  670     else
  671         return ex.args
  672     end
  673 end
  674 
  675 function count_meta_loc(exprs)
  676     push_count = 0
  677     pop_count = 0
  678     for expr in exprs
  679         Meta.isexpr(expr, :meta) || continue
  680         expr = expr::Expr
  681         if expr.args[1] === :push_loc
  682             push_count += 1
  683         elseif expr.args[1] === :pop_loc
  684             pop_count += 1
  685         end
  686         @test push_count >= pop_count
  687     end
  688     return push_count
  689 end
  690 
  691 function is_return_ssavalue(ex::Expr)
  692     ex.head === :return && isa(ex.args[1], Core.SSAValue)
  693 end
  694 
  695 function is_pop_loc(ex::Expr)
  696     ex.head === :meta && ex.args[1] === :pop_loc
  697 end
  698 
  699 # Macros
  700 macro m1()
  701     quote
  702         sin(1)
  703     end
  704 end
  705 include_string(@__MODULE__, """
  706 macro m3()
  707     quote
  708         @m1
  709     end
  710 end
  711 """, "another_file.jl")
  712 m1_exprs = get_expr_list(Meta.lower(@__MODULE__, quote @m1 end))
  713 
  714 # Check the expanded expression has expected number of matching push/pop
  715 # and the return is handled correctly
  716 # NOTE: we currently only emit push/pop locations for macros from other files
  717 @test_broken count_meta_loc(m1_exprs) == 1
  718 @test is_return_ssavalue(m1_exprs[end])
  719 
  720 let low3 = Meta.lower(@__MODULE__, quote @m3 end)
  721     m3_exprs = get_expr_list(low3)
  722     ci = low3.args[1]::Core.CodeInfo
  723     @test ci.codelocs == [3, 1]
  724     @test is_return_ssavalue(m3_exprs[end])
  725 end
  726 
  727 function f1(a)
  728     b = a + 100
  729     b
  730 end
  731 
  732 @generated function f2(a)
  733     quote
  734         b = a + 100
  735         b
  736     end
  737 end
  738 
  739 f1_ci = code_typed(f1, (Int,))[1][1]
  740 f2_ci = code_typed(f2, (Int,))[1][1]
  741 
  742 f1_exprs = get_expr_list(f1_ci)
  743 f2_exprs = get_expr_list(f2_ci)
  744 
  745 if Base.JLOptions().can_inline != 0
  746     @test length(f1_ci.linetable) == 3
  747     @test length(f2_ci.linetable) >= 3
  748 else
  749     @test length(f1_ci.linetable) == 2
  750     @test length(f2_ci.linetable) >= 3
  751 end
  752 
  753 # Check that string and command literals are parsed to the appropriate macros
  754 @test :(x"s") == :(@x_str "s")
  755 @test :(x"s"flag) == :(@x_str "s" "flag")
  756 @test :(x"s\"`\x\$\\") == :(@x_str "s\"`\\x\\\$\\")
  757 @test :(x`s`) == :(@x_cmd "s")
  758 @test :(x`s`flag) == :(@x_cmd "s" "flag")
  759 @test :(x`s\`"\x\$\\`) == :(@x_cmd "s`\"\\x\\\$\\")
  760 
  761 # Check multiline command literals
  762 @test Expr(:macrocall, GlobalRef(Core, Symbol("@cmd")), LineNumberNode(@__LINE__, Symbol(@__FILE__)), "multiline\ncommand\n") == :```
  763 multiline
  764 command
  765 ```
  766 
  767 macro julia_cmd(s)
  768     Meta.quot(Meta.parse(s))
  769 end
  770 @test julia```
  771 if test + test == test
  772     println(test)
  773 end
  774 ```.head == :if
  775 
  776 end
  777 
  778 # issue 18756
  779 module Mod18756
  780 mutable struct Type
  781 end
  782 end
  783 @test hasmethod(Mod18756.Type, ())
  784 
  785 # issue 18002
  786 @test Meta.parse("Foo{T} = Bar{T}") == Expr(:(=), Expr(:curly, :Foo, :T), Expr(:curly, :Bar, :T))
  787 
  788 # don't insert push_loc for filename `none` at the top level
  789 let ex = Meta.lower(Main, Meta.parse("""
  790 begin
  791     x = 1
  792 end"""))
  793     @test !any(x->(x == Expr(:meta, :push_loc, :none)), ex.args)
  794 end
  795 
  796 # Check qualified string macros
  797 Base.r"regex" == r"regex"
  798 
  799 module QualifiedStringMacro
  800 module SubModule
  801 macro x_str(x)
  802     1
  803 end
  804 macro y_cmd(x)
  805     2
  806 end
  807 end
  808 end
  809 
  810 @test QualifiedStringMacro.SubModule.x"" === 1
  811 @test QualifiedStringMacro.SubModule.y`` === 2
  812 
  813 let ..(x,y) = x + y
  814     @test 3 .. 4 === 7
  815 end
  816 
  817 # issue #7669
  818 @test Meta.parse("@a(b=1, c=2)") == Expr(:macrocall, Symbol("@a"), LineNumberNode(1, :none), :(b=1), :(c=2))
  819 
  820 # issue #19685
  821 let f = function (x; kw...)
  822             return (x, kw)
  823         end,
  824     g = function (x; a = 2)
  825             return (x, a)
  826         end
  827     @test f(1) == (1, pairs(NamedTuple()))
  828     @test g(1) == (1, 2)
  829 end
  830 
  831 # normalization of Unicode symbols (#19464)
  832 let ε=1, μ=2, x=3, î=4
  833     # issue #5434 (mu vs micro):
  834     @test Meta.parse("\u00b5") === Meta.parse("\u03bc")
  835     @test µ == μ == 2
  836     # NFC normalization of identifiers:
  837     @test Meta.parse("\u0069\u0302") === Meta.parse("\u00ee")
  838     @test î == 4
  839     # latin vs greek ε (#14751)
  840     @test Meta.parse("\u025B") === Meta.parse("\u03B5")
  841     @test ɛ == ε == 1
  842 end
  843 
  844 # issue #8925
  845 let
  846     global const (c8925, d8925) = (3, 4)
  847 end
  848 @test c8925 == 3 && isconst(@__MODULE__, :c8925)
  849 @test d8925 == 4 && isconst(@__MODULE__, :d8925)
  850 
  851 # issue #18754: parse ccall as a regular function
  852 @test Meta.parse("ccall([1], 2)[3]") == Expr(:ref, Expr(:call, :ccall, Expr(:vect, 1), 2), 3)
  853 @test Meta.parse("ccall(a).member") == Expr(:., Expr(:call, :ccall, :a), QuoteNode(:member))
  854 
  855 # Check that the body of a `where`-qualified short form function definition gets
  856 # a :block for its body
  857 short_where_call = :(f(x::T) where T = T)
  858 @test short_where_call.args[2].head == :block
  859 
  860 # `where` with multi-line anonymous functions
  861 let f = function (x::T) where T
  862             T
  863         end
  864     @test f(:x) === Symbol
  865 end
  866 
  867 let f = function (x::T, y::S) where T<:S where S
  868             (T,S)
  869         end
  870     @test f(0,1) === (Int,Int)
  871 end
  872 
  873 # issue #20541
  874 @test Meta.parse("[a .!b]") == Expr(:hcat, :a, Expr(:call, :(.!), :b))
  875 
  876 @test Meta.lower(Main, :(a{1} = b)) == Expr(:error, "invalid type parameter name \"1\"")
  877 @test Meta.lower(Main, :(a{2<:Any} = b)) == Expr(:error, "invalid type parameter name \"2\"")
  878 
  879 # issue #20653
  880 @test_throws UndefVarError Base.call(::Int) = 1
  881 module Test20653
  882 using Test
  883 struct A
  884 end
  885 call(::A) = 1
  886 const a = A()
  887 @test_throws MethodError a()
  888 @test call(a) === 1
  889 end
  890 
  891 # issue #20729
  892 macro m20729()
  893     ex = Expr(:head)
  894     resize!(ex.args, 1)
  895     return ex
  896 end
  897 
  898 @test_throws ErrorException Core.eval(@__MODULE__, :(@m20729))
  899 @test Meta.lower(@__MODULE__, :(@m20729)) == Expr(:error, "undefined reference in AST")
  900 
  901 macro err20000()
  902     return Expr(:error, "oops!")
  903 end
  904 
  905 @test Meta.lower(@__MODULE__, :(@err20000)) == Expr(:error, "oops!")
  906 
  907 # issue #20000
  908 @test Meta.parse("@m(a; b=c)") == Expr(:macrocall, Symbol("@m"), LineNumberNode(1, :none),
  909                                   Expr(:parameters, Expr(:kw, :b, :c)), :a)
  910 
  911 # issue #21054
  912 macro make_f21054(T)
  913     quote
  914         $(esc(:f21054))(X::Type{<:$T}) = 1
  915     end
  916 end
  917 @eval @make_f21054 $Array
  918 @test isa(f21054, Function)
  919 g21054(>:) = >:2
  920 @test g21054(-) == -2
  921 
  922 # issue #21168
  923 @test Meta.lower(Main, :(a.[1])) == Expr(:error, "invalid syntax \"a.[1]\"")
  924 @test Meta.lower(Main, :(a.{1})) == Expr(:error, "invalid syntax \"a.{1}\"")
  925 
  926 # Issue #21225
  927 let abstr = Meta.parse("abstract type X end")
  928     @test Meta.parse("abstract type X; end") == abstr
  929     @test Meta.parse(string("abstract type X", ";"^5, " end")) == abstr
  930     @test Meta.parse("abstract type X\nend") == abstr
  931     @test Meta.parse(string("abstract type X", "\n"^5, "end")) == abstr
  932 end
  933 let prim = Meta.parse("primitive type X 8 end")
  934     @test Meta.parse("primitive type X 8; end") == prim
  935     @test Meta.parse(string("primitive type X 8", ";"^5, " end")) == prim
  936     @test Meta.parse("primitive type X 8\nend") == prim
  937     @test Meta.parse(string("primitive type X 8", "\n"^5, "end")) == prim
  938 end
  939 
  940 # issue #21155
  941 @test filter(!isline,
  942              Meta.parse("module B
  943                         using ..x,
  944                               ..y
  945                     end").args[3].args)[1] ==
  946       Expr(:using,
  947            Expr(:., :., :., :x),
  948            Expr(:., :., :., :y))
  949 
  950 @test filter(!isline,
  951              Meta.parse("module A
  952                         using .B,
  953                               .C
  954                     end").args[3].args)[1] ==
  955       Expr(:using,
  956            Expr(:., :., :B),
  957            Expr(:., :., :C))
  958 
  959 # issue #21440
  960 @test Meta.parse("+(x::T,y::T) where {T} = 0") == Meta.parse("(+)(x::T,y::T) where {T} = 0")
  961 @test Meta.parse("a::b::c") == Expr(:(::), Expr(:(::), :a, :b), :c)
  962 
  963 # issue #21545
  964 f21545(::Type{<: AbstractArray{T,N} where N}) where T = T
  965 @test f21545(Array{Int8}) === Int8
  966 @test Meta.parse("<:{T} where T") == Expr(:where, Expr(:curly, :(<:), :T), :T)
  967 @test Meta.parse("<:(T) where T") == Expr(:where, Expr(:(<:), :T), :T)
  968 @test Meta.parse("<:{T}(T) where T") == Expr(:where, Expr(:call, Expr(:curly, :(<:), :T), :T), :T)
  969 
  970 # issue #21586
  971 macro m21586(x)
  972     Expr(:kw, esc(x), 42)
  973 end
  974 
  975 f21586(; @m21586(a), @m21586(b)) = a + b
  976 @test f21586(a=10) == 52
  977 
  978 # issue #21604
  979 @test_nowarn @eval module Test21604
  980     const Foo = Any
  981     struct X
  982         x::Foo
  983     end
  984 end
  985 @test Test21604.X(1.0) === Test21604.X(1.0)
  986 
  987 # issue #20575
  988 @test_throws ParseError Meta.parse("\"a\"x")
  989 @test_throws ParseError Meta.parse("\"a\"begin end")
  990 @test_throws ParseError Meta.parse("\"a\"begin end\"b\"")
  991 
  992 # issue #16427
  993 @test_throws ParseError Meta.parse("for i=1:1 end(3)")
  994 @test_throws ParseError Meta.parse("begin end(3)")
  995 @test_throws ParseError Meta.parse("while false end(3)")
  996 
  997 # comment 298107224 on pull #21607
  998 module Test21607
  999     using Test
 1000     const Any = Integer
 1001 
 1002     # check that X <: Core.Any, not Integer
 1003     mutable struct X; end
 1004     @test supertype(X) === Core.Any
 1005 
 1006     # check that return type is Integer
 1007     f()::Any = 1.0
 1008     @test f() === 1
 1009 
 1010     # check that constructor accepts Any
 1011     struct Y
 1012         x
 1013     end
 1014     @test Y(1.0) !== Y(1)
 1015 
 1016     # check that function default argument type is Any
 1017     g(x) = x
 1018     @test g(1.0) === 1.0
 1019 
 1020     # check that asserted variable type is Integer
 1021     @test let
 1022         x::Any = 1.0
 1023         x
 1024     end === 1
 1025 
 1026     # check that unasserted variable type is not Integer
 1027     @test let
 1028         x = 1.0
 1029         x
 1030     end === 1.0
 1031 end
 1032 
 1033 # issue #16937
 1034 @test Meta.lower(Main, :(f(2, a=1, w=3, c=3, w=4, b=2))) ==
 1035     Expr(:error, "keyword argument \"w\" repeated in call to \"f\"")
 1036 
 1037 let f(x) =
 1038       g(x) = 1
 1039     @test functionloc(f(1))[2] > functionloc(f)[2]
 1040 end
 1041 
 1042 # let-bound functions with `where` and static parameters
 1043 @test let f()::Int = 2.0
 1044     f()
 1045 end === 2
 1046 @test let (f(x::T)::Tuple{Int,Any}) where {T} = (3.0, T)
 1047     f("")
 1048 end === (3, String)
 1049 
 1050 # operator suffixes
 1051 @test Meta.parse("3 +̂ 4") == Expr(:call, :+̂, 3, 4)
 1052 @test Meta.parse("3 +̂′ 4") == Expr(:call, :+̂′, 3, 4)
 1053 @test Meta.parse("3 +⁽¹⁾ 4") == Expr(:call, :+⁽¹⁾, 3, 4)
 1054 @test Meta.parse("3 +₍₀₎ 4") == Expr(:call, :+₍₀₎, 3, 4)
 1055 for bad in ('=', '$', ':', "||", "&&", "->", "<:")
 1056     @test_throws ParseError Meta.parse("3 $(bad)⁽¹⁾ 4")
 1057 end
 1058 @test Base.operator_precedence(:+̂) == Base.operator_precedence(:+)
 1059 
 1060 @test Meta.parse("(x)ᵀ") == Expr(:call, :*, :x, :ᵀ)
 1061 
 1062 # issue #19351
 1063 # adding return type decl should not affect parse of function body
 1064 @test :(t(abc) = 3).args[2] == :(t(abc)::Int = 3).args[2]
 1065 
 1066 # issue #7314
 1067 @test Meta.parse("local x, y = 1, 2") == Expr(:local, Expr(:(=),
 1068                                                       Expr(:tuple, :x, :y),
 1069                                                       Expr(:tuple, 1, 2)))
 1070 
 1071 @test_throws ParseError Meta.parse("[2for i=1:10]")
 1072 @test_throws ParseError Meta.parse("[1 for i in 1:2for j in 2]")
 1073 @test_throws ParseError Meta.parse("(1 for i in 1:2for j in 2)")
 1074 # issue #20441
 1075 @test_throws ParseError Meta.parse("[x.2]")
 1076 @test_throws ParseError Meta.parse("x.2")
 1077 @test Meta.parse("[x;.2]") == Expr(:vcat, :x, 0.2)
 1078 
 1079 # issue #22840
 1080 @test Meta.parse("[:a :b]") == Expr(:hcat, QuoteNode(:a), QuoteNode(:b))
 1081 
 1082 # issue #22868
 1083 @test_throws ParseError Meta.parse("x@time 2")
 1084 @test_throws ParseError Meta.parse("@ time")
 1085 
 1086 # issue #7479
 1087 @test Meta.lower(Main, Meta.parse("(true &&& false)")) == Expr(:error, "invalid syntax &false")
 1088 
 1089 # if an indexing expression becomes a cat expression, `end` is not special
 1090 @test_throws ParseError Meta.parse("a[end end]")
 1091 @test_throws ParseError Meta.parse("a[end;end]")
 1092 #@test_throws ParseError Meta.parse("a[end;]")  # this is difficult to fix
 1093 let a = rand(8), i = 3
 1094     @test a[[1:i-1; i+1:end]] == a[[1,2,4,5,6,7,8]]
 1095 end
 1096 
 1097 # issue #18935
 1098 @test [begin
 1099           @inbounds for i = 1:10 end
 1100        end for i = 1:5] == fill(nothing, 5)
 1101 
 1102 # issue #18912
 1103 @test_throws ParseError Meta.parse("(::)")
 1104 @test Meta.parse(":(::)") == QuoteNode(Symbol("::"))
 1105 @test_throws ParseError Meta.parse("f(::) = ::")
 1106 @test Meta.parse("(::A)") == Expr(Symbol("::"), :A)
 1107 @test_throws ParseError Meta.parse("(::, 1)")
 1108 @test_throws ParseError Meta.parse("(1, ::)")
 1109 
 1110 # issue #18650
 1111 let ex = Meta.parse("maximum(@elapsed sleep(1) for k = 1:10)")
 1112     @test isa(ex, Expr) && ex.head === :call && ex.args[2].head === :generator &&
 1113         ex.args[2].args[1].head === :macrocall
 1114 end
 1115 
 1116 # issue #23173
 1117 @test_throws ErrorException("invalid module path") eval(:(import $(:.)))
 1118 
 1119 # issue #23234
 1120 let
 1121     f = function (x=0)
 1122         x
 1123     end
 1124     @test f() == 0
 1125     @test f(2) == 2
 1126 end
 1127 
 1128 # issue #18730
 1129 @test Meta.lower(Main, quote
 1130         function f()
 1131             local Int
 1132             x::Int -> 2
 1133         end
 1134     end) == Expr(:error, "local variable Int cannot be used in closure declaration")
 1135 
 1136 # some issues with backquote
 1137 # preserve QuoteNode and LineNumberNode
 1138 @test eval(Expr(:quote, QuoteNode(Expr(:tuple, 1, Expr(:$, :(1+2)))))) == QuoteNode(Expr(:tuple, 1, 3))
 1139 @test eval(Expr(:quote, Expr(:line, Expr(:$, :(1+2))))) === LineNumberNode(3, nothing)
 1140 # splicing at the top level should be an error
 1141 xs23917 = [1,2,3]
 1142 @test_throws ErrorException eval(:(:($(xs23917...))))
 1143 let ex2 = eval(:(:(:($$(xs23917...)))))
 1144     @test ex2 isa Expr
 1145     @test_throws ErrorException eval(ex2)
 1146     @test eval(:($(xs23917...),)) == (1,2,3)  # adding a comma gives a tuple
 1147 end
 1148 # multi-unquote of splice in nested quote
 1149 let xs = [:(1+2), :(3+4), :(5+6)]
 1150     ex = quote quote $$(xs...) end end
 1151     @test ex.args[2].args[1].args[2].args[2] == :(3 + 4)
 1152     ex2 = eval(ex)
 1153     @test ex2.args[2:end] == [3,7,11]
 1154 end
 1155 
 1156 let x = [3,2,1]
 1157     @test :( $(x...,) ) == (3, 2, 1)
 1158     @test :( $(x...), ) == Expr(:tuple, 3, 2, 1)
 1159 end
 1160 
 1161 # issue #23519
 1162 @test Meta.parse("@foo[1]") == Meta.parse("@foo([1])")
 1163 @test Meta.parse("@foo[1 2; 3 4]") == Meta.parse("@foo([1 2; 3 4])")
 1164 @test Meta.parse("@foo[1] + [2]") == Meta.parse("@foo([1]) + [2]")
 1165 @test Meta.parse("@foo [1] + [2]") == Meta.parse("@foo([1] + [2])")
 1166 @test Meta.parse("@Mdl.foo[1] + [2]") == Meta.parse("@Mdl.foo([1]) + [2]")
 1167 @test Meta.parse("@Mdl.foo [1] + [2]") == Meta.parse("@Mdl.foo([1] + [2])")
 1168 
 1169 # issue #24289
 1170 macro m24289()
 1171     :(global $(esc(:x24289)) = 1)
 1172 end
 1173 @test (@macroexpand @m24289) == :(global x24289 = 1)
 1174 
 1175 # parsing numbers with _ and .
 1176 @test Meta.parse("1_2.3_4") == 12.34
 1177 @test_throws ParseError Meta.parse("1._")
 1178 @test_throws ParseError Meta.parse("1._5")
 1179 @test_throws ParseError Meta.parse("1e.3")
 1180 @test_throws ParseError Meta.parse("1e3.")
 1181 @test Meta.parse("2e_1") == Expr(:call, :*, 2, :e_1)
 1182 # issue #17705
 1183 @test Meta.parse("2e3_") == Expr(:call, :*, 2e3, :_)
 1184 @test Meta.parse("2e-3_") == Expr(:call, :*, 2e-3, :_)
 1185 @test Meta.parse("2e3_\"x\"") == Expr(:call, :*, 2e3, Expr(:macrocall, Symbol("@__str"), LineNumberNode(1, :none), "x"))
 1186 
 1187 # misplaced top-level expressions
 1188 @test_throws ErrorException("syntax: \"\$\" expression outside quote") Core.eval(@__MODULE__, Meta.parse("x->\$x"))
 1189 @test Meta.lower(@__MODULE__, Expr(:$, :x)) == Expr(:error, "\"\$\" expression outside quote")
 1190 @test Meta.lower(@__MODULE__, :(x->import Foo)) == Expr(:error, "\"import\" expression not at top level")
 1191 @test Meta.lower(@__MODULE__, :(x->module Foo end)) == Expr(:error, "\"module\" expression not at top level")
 1192 @test Meta.lower(@__MODULE__, :(x->struct Foo end)) == Expr(:error, "\"struct\" expression not at top level")
 1193 @test Meta.lower(@__MODULE__, :(x->abstract type Foo end)) == Expr(:error, "\"abstract type\" expression not at top level")
 1194 
 1195 # caused by #24538. forms that lower to `call` should wrap with `call` before
 1196 # recursively calling expand-forms.
 1197 @test [(0,0)... 1] == [0 0 1]
 1198 @test Float32[(0,0)... 1] == Float32[0 0 1]
 1199 
 1200 @testset "raw_str macro" begin
 1201     @test raw"$" == "\$"
 1202     @test raw"\n" == "\\n"
 1203     @test raw"\t" == "\\t"
 1204 
 1205     s1 = raw"""
 1206          lorem ipsum\n
 1207          $x = 1$
 1208          """
 1209 
 1210     s2 = """
 1211          lorem ipsum\\n
 1212          \$x = 1\$
 1213          """
 1214 
 1215     @test s1 == s2
 1216 
 1217     # issue #22926
 1218     @test raw"\\" == "\\"
 1219     @test raw"\\\\" == "\\\\"
 1220     @test raw"\"" == "\""
 1221     @test raw"\\\"" == "\\\""
 1222     @test raw"\\x\\" == "\\\\x\\"
 1223     @test raw"x \\\" y" == "x \\\" y"
 1224     @test raw"x \\\ y" == "x \\\\\\ y"
 1225 end
 1226 
 1227 @test_throws ParseError("expected \"}\" or separator in arguments to \"{ }\"; got \"V)\"") Meta.parse("f(x::V) where {V) = x")
 1228 @test_throws ParseError("expected \"]\" or separator in arguments to \"[ ]\"; got \"1)\"") Meta.parse("[1)")
 1229 
 1230 # issue #9972
 1231 @test Meta.lower(@__MODULE__, :(f(;3))) == Expr(:error, "invalid keyword argument syntax \"3\"")
 1232 
 1233 # issue #25055, make sure quote makes new Exprs
 1234 function f25055()
 1235     x = quote end
 1236     return x
 1237 end
 1238 @test f25055() !== f25055()
 1239 
 1240 # issue #25391
 1241 @test Meta.parse("0:-1, \"\"=>\"\"") == Meta.parse("(0:-1, \"\"=>\"\")") ==
 1242     Expr(:tuple, Expr(:call, :(:), 0, -1), Expr(:call, :(=>), "", ""))
 1243 @test Meta.parse("a => b = c") == Expr(:(=), Expr(:call, :(=>), :a, :b), Expr(:block, LineNumberNode(1, :none), :c))
 1244 @test Meta.parse("a = b => c") == Expr(:(=), :a, Expr(:call, :(=>), :b, :c))
 1245 
 1246 # issue #16239, hygiene of rest keyword name
 1247 macro foo16239(x)
 1248     :($(esc(:blah))(args...; kwargs...) = $(esc(x)))
 1249 end
 1250 function bar16239()
 1251     kwargs = 0
 1252     f = @foo16239 kwargs
 1253     f()
 1254 end
 1255 @test bar16239() == 0
 1256 
 1257 # lowering of <: and >:
 1258 let args = (Int, Any)
 1259     @test <:(args...)
 1260     @test >:(reverse(args)...)
 1261 end
 1262 
 1263 # issue #25947
 1264 let getindex = 0, setindex! = 1, colon = 2, vcat = 3, hcat = 4, hvcat = 5
 1265     a = [10,9,8]
 1266     @test a[2] == 9
 1267     @test 1:2 isa AbstractRange
 1268     a[1] = 1
 1269     @test a[1] == 1
 1270     @test length([1; 2]) == 2
 1271     @test size([0 0]) == (1, 2)
 1272     @test size([1 2; 3 4]) == (2, 2)
 1273 end
 1274 
 1275 # issue #25020
 1276 @test_throws ParseError Meta.parse("using Colors()")
 1277 
 1278 let ex = Meta.parse("md\"x\"
 1279                      f(x) = x", 1)[1]  # custom string literal is not a docstring
 1280     @test Meta.isexpr(ex, :macrocall)
 1281     @test ex.args[1] === Symbol("@md_str")
 1282     @test length(ex.args) == 3
 1283 end
 1284 
 1285 let ex = Meta.parse("@doc raw\"
 1286                      \"
 1287                      f(x) = x")
 1288     @test Meta.isexpr(ex, :macrocall)
 1289     @test ex.args[1] === Symbol("@doc")
 1290     @test length(ex.args) == 4
 1291     @test Meta.isexpr(ex.args[4], :(=))
 1292 end
 1293 
 1294 let ex = Meta.parse("@doc raw\"
 1295                      \"
 1296 
 1297                      f(x) = x", 1)[1]
 1298     @test Meta.isexpr(ex, :macrocall)
 1299     @test ex.args[1] === Symbol("@doc")
 1300     @test length(ex.args) == 3
 1301 end
 1302 
 1303 @test Meta.parse("\"x\"
 1304                   # extra line, not a doc string
 1305                   f(x) = x", 1)[1] === "x"
 1306 @test Meta.parse("\"x\"
 1307 
 1308                   f(x) = x", 1)[1] === "x"
 1309 
 1310 # issue #26137
 1311 # cases where parens enclose argument lists
 1312 @test Meta.parse("-()^2")      == Expr(:call, :^, Expr(:call, :-), 2)
 1313 @test Meta.parse("-(x,)^2")    == Expr(:call, :^, Expr(:call, :-, :x), 2)
 1314 @test Meta.parse("-(x,;)^2")   == Expr(:call, :^, Expr(:call, :-, Expr(:parameters), :x), 2)
 1315 @test Meta.parse("-(;x)^2")    == Expr(:call, :^, Expr(:call, :-, Expr(:parameters, :x)), 2)
 1316 @test Meta.parse("-(x,y)^2")   == Expr(:call, :^, Expr(:call, :-, :x, :y), 2)
 1317 @test Meta.parse("-(x...)^2")  == Expr(:call, :^, Expr(:call, :-, Expr(:(...), :x)), 2)
 1318 @test Meta.parse("-(x...;)^2") == Expr(:call, :^, Expr(:call, :-, Expr(:parameters), Expr(:(...), :x)), 2)
 1319 @test Meta.parse("-(x...;)")   == Expr(:call, :-, Expr(:parameters), Expr(:(...), :x))
 1320 
 1321 # cases where parens are just grouping
 1322 @test Meta.parse("-(x)^2")     == Expr(:call, :-, Expr(:call, :^, :x, 2))
 1323 @test Meta.parse("-(a=1)^2")   == Expr(:call, :-, Expr(:call, :^, Expr(:(=), :a, 1), 2))
 1324 @test Meta.parse("-(x;y)^2")   == Expr(:call, :-, Expr(:call, :^, Expr(:block, :x, LineNumberNode(1,:none), :y), 2))
 1325 @test Meta.parse("-(;)^2")     == Expr(:call, :-, Expr(:call, :^, Expr(:block), 2))
 1326 @test Meta.parse("-(;;;;)^2")  == Expr(:call, :-, Expr(:call, :^, Expr(:block), 2))
 1327 @test Meta.parse("-(x;;;)^2")  == Expr(:call, :-, Expr(:call, :^, Expr(:block, :x), 2))
 1328 @test Meta.parse("+((1,2))")   == Expr(:call, :+, Expr(:tuple, 1, 2))
 1329 
 1330 @test_throws ParseError("space before \"(\" not allowed in \"+ (\"") Meta.parse("1 -+ (a=1, b=2)")
 1331 # issue #29781
 1332 @test_throws ParseError("space before \"(\" not allowed in \"sin. (\"") Meta.parse("sin. (1)")
 1333 
 1334 @test Meta.parse("1 -+(a=1, b=2)") == Expr(:call, :-, 1,
 1335                                            Expr(:call, :+, Expr(:kw, :a, 1), Expr(:kw, :b, 2)))
 1336 
 1337 @test Meta.parse("-(2)(x)") == Expr(:call, :*, Expr(:call, :-,  2), :x)
 1338 @test Meta.parse("-(x)y")   == Expr(:call, :*, Expr(:call, :-, :x), :y)
 1339 @test Meta.parse("-(x,)y")  == Expr(:call, :*, Expr(:call, :-, :x), :y)
 1340 @test Meta.parse("-(f)(x)") == Expr(:call, :-, Expr(:call, :f, :x))
 1341 @test Meta.parse("-(2)(x)^2") == Expr(:call, :*, Expr(:call, :-, 2), Expr(:call, :^, :x, 2))
 1342 @test Meta.parse("Y <- (x->true)(X)") ==
 1343     Expr(:call, :<, :Y,
 1344          Expr(:call, :-, Expr(:call, Expr(:->, :x, Expr(:block, LineNumberNode(1,:none), true)),
 1345                               :X)))
 1346 
 1347 # issue #27641
 1348 @test Meta.parse("√3x")   == Expr(:call, :*, Expr(:call, :√, 3), :x)
 1349 @test Meta.parse("2^√3x") == Expr(:call, :^, 2, Expr(:call, :*, Expr(:call, :√, 3), :x))
 1350 @test Meta.parse("√2^3")  == Expr(:call, :√, Expr(:call, :^, 2, 3))
 1351 @test Meta.parse("-√2")   == Expr(:call, :-, Expr(:call, :√, 2))
 1352 @test Meta.parse("√3x^2") == Expr(:call, :*, Expr(:call, :√, 3), Expr(:call, :^, :x, 2))
 1353 @test Meta.parse("-3x^2") == Expr(:call, :*, -3, Expr(:call, :^, :x, 2))
 1354 @test_throws ParseError Meta.parse("2!3")
 1355 @test_throws ParseError Meta.parse("2√3")
 1356 
 1357 # issue #27914
 1358 @test Meta.parse("2f(x)")        == Expr(:call, :*, 2, Expr(:call, :f, :x))
 1359 @test Meta.parse("f(x)g(x)")     == Expr(:call, :*, Expr(:call, :f, :x), Expr(:call, :g, :x))
 1360 @test Meta.parse("2f(x)g(x)")    == Expr(:call, :*, 2, Expr(:call, :f, :x), Expr(:call, :g, :x))
 1361 @test Meta.parse("f(x)g(x)h(x)") == Expr(:call, :*, Expr(:call, :f, :x), Expr(:call, :g, :x), Expr(:call, :h, :x))
 1362 @test Meta.parse("2(x)")         == Expr(:call, :*, 2, :x)
 1363 @test Meta.parse("2(x)y")        == Expr(:call, :*, 2, :x, :y)
 1364 
 1365 @test_throws ParseError Meta.parse("a.: b")
 1366 @test Meta.parse("a.:end") == Expr(:., :a, QuoteNode(:end))
 1367 @test Meta.parse("a.:catch") == Expr(:., :a, QuoteNode(:catch))
 1368 @test Meta.parse("a.end") == Expr(:., :a, QuoteNode(:end))
 1369 @test Meta.parse("a.catch") == Expr(:., :a, QuoteNode(:catch))
 1370 @test Meta.parse("a.function") == Expr(:., :a, QuoteNode(:function))
 1371 
 1372 # issue #25994
 1373 @test Meta.parse("[a\nfor a in b]") == Expr(:comprehension, Expr(:generator, :a, Expr(:(=), :a, :b)))
 1374 
 1375 # issue #27529
 1376 let len = 10
 1377     @test [ i for i in 0:len -1 ] == [0:9;]
 1378 end
 1379 
 1380 # Module name cannot be a reserved word.
 1381 @test_throws ParseError Meta.parse("module module end")
 1382 
 1383 @test Meta.lower(@__MODULE__, :(global true)) == Expr(:error, "invalid identifier name \"true\"")
 1384 @test Meta.lower(@__MODULE__, :(let ccall end)) == Expr(:error, "invalid identifier name \"ccall\"")
 1385 @test Meta.lower(@__MODULE__, :(cglobal = 0)) == Expr(:error, "invalid assignment location \"cglobal\"")
 1386 
 1387 # issue #26507
 1388 @test Meta.parse("@try x") == Expr(:macrocall, Symbol("@try"), LineNumberNode(1,:none), :x)
 1389 @test Meta.parse("@catch x") == Expr(:macrocall, Symbol("@catch"), LineNumberNode(1,:none), :x)
 1390 @test Meta.parse("@\$x") == Expr(:macrocall, Symbol("@\$"), LineNumberNode(1,:none), :x)
 1391 
 1392 # issue #26717
 1393 @test Meta.lower(@__MODULE__, :( :(:) = 2 )) == Expr(:error, "invalid assignment location \":(:)\"")
 1394 
 1395 # issue #27690
 1396 # previously, this was allowed since it thought `end` was being used for indexing.
 1397 # however the quote should disable that context.
 1398 @test_throws ParseError Meta.parse("Any[:(end)]")
 1399 
 1400 # issue #17781
 1401 let ex = Meta.lower(@__MODULE__, Meta.parse("
 1402     A = function (s, o...)
 1403         f(a, b) do
 1404         end
 1405     end,
 1406     B = function (s, o...)
 1407         f(a, b) do
 1408         end
 1409     end"))
 1410     @test isa(ex, Expr) && ex.head === :error
 1411     @test ex.args[1] == """
 1412 invalid assignment location "function (s, o...)
 1413     # none, line 3
 1414     f(a, b) do
 1415         # none, line 4
 1416     end
 1417 end\""""
 1418 end
 1419 
 1420 # issue #15229
 1421 @test Meta.lower(@__MODULE__, :(function f(x); local x; 0; end)) ==
 1422     Expr(:error, "local variable name \"x\" conflicts with an argument")
 1423 @test Meta.lower(@__MODULE__, :(function f(x); begin; local x; 0; end; end)) ==
 1424     Expr(:error, "local variable name \"x\" conflicts with an argument")
 1425 
 1426 # issue #27964
 1427 a27964(x) = Any[x for x in []]
 1428 @test a27964(0) == Any[]
 1429 function b27964(x)
 1430     local y
 1431     let
 1432         local x
 1433         x = 2
 1434         y = x
 1435     end
 1436     return (x, y)
 1437 end
 1438 @test b27964(8) == (8, 2)
 1439 function c27964(x)
 1440     local y
 1441     let x = 2
 1442         y = x
 1443     end
 1444     return (x, y)
 1445 end
 1446 @test c27964(8) == (8, 2)
 1447 
 1448 # issue #26739
 1449 @test_throws ErrorException("syntax: invalid syntax \"sin.[1]\"") Core.eval(@__MODULE__, :(sin.[1]))
 1450 
 1451 # issue #26873
 1452 f26873 = 0
 1453 try
 1454     include_string(@__MODULE__, """f26873."a" """)
 1455     @test false
 1456 catch e
 1457     @test e isa LoadError
 1458     @test e.error isa MethodError
 1459 end
 1460 
 1461 @test Meta.lower(@__MODULE__, :(if true; break; end for i = 1:1)) == Expr(:error, "break or continue outside loop")
 1462 @test Meta.lower(@__MODULE__, :([if true; break; end for i = 1:1])) == Expr(:error, "break or continue outside loop")
 1463 @test Meta.lower(@__MODULE__, :(Int[if true; break; end for i = 1:1])) == Expr(:error, "break or continue outside loop")
 1464 @test Meta.lower(@__MODULE__, :([if true; continue; end for i = 1:1])) == Expr(:error, "break or continue outside loop")
 1465 @test Meta.lower(@__MODULE__, :(Int[if true; continue; end for i = 1:1])) == Expr(:error, "break or continue outside loop")
 1466 
 1467 @test Meta.lower(@__MODULE__, :(return 0 for i=1:2)) == Expr(:error, "\"return\" not allowed inside comprehension or generator")
 1468 @test Meta.lower(@__MODULE__, :([ return 0 for i=1:2 ])) == Expr(:error, "\"return\" not allowed inside comprehension or generator")
 1469 @test Meta.lower(@__MODULE__, :(Int[ return 0 for i=1:2 ])) == Expr(:error, "\"return\" not allowed inside comprehension or generator")
 1470 @test [ ()->return 42 for i = 1:1 ][1]() == 42
 1471 @test Function[ identity() do x; return 2x; end for i = 1:1 ][1](21) == 42
 1472 
 1473 # issue #27155
 1474 macro test27155()
 1475     quote
 1476         MyTest27155{Arg} = Tuple{Arg}
 1477         MyTest27155
 1478     end
 1479 end
 1480 @test @test27155() == (Tuple{T} where T)
 1481 
 1482 # issue #27521
 1483 macro test27521(f, x)
 1484     :(($(esc(f)), $x))
 1485 end
 1486 let ex = Meta.parse("@test27521(2) do y; y; end")
 1487     fex = Expr(:(->), Expr(:tuple, :y), Expr(:block, LineNumberNode(1,:none), :y))
 1488     @test ex == Expr(:do, Expr(:macrocall, Symbol("@test27521"), LineNumberNode(1,:none), 2),
 1489                      fex)
 1490     @test macroexpand(@__MODULE__, ex) == Expr(:tuple, fex, 2)
 1491 end
 1492 
 1493 # issue #27129
 1494 f27129(x = 1) = (@Base._inline_meta; x)
 1495 for meth in methods(f27129)
 1496     @test ccall(:jl_uncompress_ast, Any, (Any, Any), meth, meth.source).inlineable
 1497 end
 1498 
 1499 # issue #27710
 1500 struct Foo27710{T} end
 1501 function test27710()
 1502     types(::Foo27710{T}) where T = T
 1503     T = types(Foo27710{Int64}())
 1504 end
 1505 @test test27710() === Int64
 1506 
 1507 # issue #29064
 1508 struct X29064
 1509     X29064::Int
 1510 end
 1511 @test X29064(1) isa X29064
 1512 
 1513 # issue #27268
 1514 function f27268()
 1515     g(col::AbstractArray{<:Real}) = col
 1516 end
 1517 function f27268_2()
 1518     g(col::AbstractArray{T} where T<:Real) = col
 1519 end
 1520 @test f27268()([1]) == [1]
 1521 @test f27268_2()([1]) == [1]
 1522 @test_throws MethodError f27268()([""])
 1523 @test_throws MethodError f27268_2()([""])
 1524 
 1525 @test_throws ErrorException("syntax: local variable x cannot be used in closure declaration") @eval begin
 1526     function g27268()
 1527         x = 1
 1528         h(::Val{x}) = 1
 1529     end
 1530 end
 1531 
 1532 types27268 = (Int64,Int8)
 1533 function h27268()
 1534     function g(::Union{map(t->Array{t,N},types27268)...} where N)
 1535     end
 1536 end
 1537 @test first(methods(h27268())).sig == Tuple{typeof(h27268()), Union{Array{Int64,N}, Array{Int8,N}} where N}
 1538 
 1539 let val(::Type{Val{X}}) where {X} = X, f
 1540     function f()
 1541         function g(::Val{x->2x})
 1542         end
 1543     end
 1544     @test val(first(methods(f())).sig.parameters[2])(21) == 42
 1545 end
 1546 
 1547 # issue #27807
 1548 module A27807
 1549 macro m()
 1550     quote
 1551         function foo(x::T, y::S) where T<:Number where S<:Number
 1552             return one(T), zero(S)
 1553         end
 1554     end
 1555 end
 1556 end
 1557 @test A27807.@m()(1,1.0) === (1, 0.0)
 1558 
 1559 # issue #27896 / #29429
 1560 @test Meta.lower(@__MODULE__, quote
 1561     function foo(a::A, b::B) where {A,B}
 1562         B = eltype(A)
 1563         return convert(B, b)
 1564     end
 1565 end) == Expr(:error, "local variable name \"B\" conflicts with a static parameter")
 1566 
 1567 # issue #28044
 1568 code28044(x) = 10x
 1569 begin
 1570     function f28044(::Val{code28044}) where code28044
 1571         code28044(2)
 1572     end
 1573     # make sure this assignment to `code28044` doesn't add an implicit-global
 1574     Val{code28044} where code28044
 1575 end
 1576 @test f28044(Val(identity)) == 2
 1577 
 1578 # issue #28244
 1579 macro foo28244(sym)
 1580     x = :(bar())
 1581     push!(x.args, Expr(sym))
 1582     x
 1583 end
 1584 @test (@macroexpand @foo28244(kw)) == Expr(:call, GlobalRef(@__MODULE__,:bar), Expr(:kw))
 1585 @test eval(:(@macroexpand @foo28244($(Symbol("let"))))) == Expr(:error, "malformed expression")
 1586 
 1587 # #16356
 1588 @test_throws ParseError Meta.parse("0xapi")
 1589 
 1590 # #22523 #22712
 1591 @test_throws ParseError Meta.parse("a?b:c")
 1592 @test_throws ParseError Meta.parse("a ?b:c")
 1593 @test_throws ParseError Meta.parse("a ? b:c")
 1594 @test_throws ParseError Meta.parse("a ? b :c")
 1595 @test_throws ParseError Meta.parse("?")
 1596 
 1597 # #13079
 1598 @test Meta.parse("1<<2*3") == :((1<<2)*3)
 1599 
 1600 # #19987
 1601 @test_throws ParseError Meta.parse("try ; catch f() ; end")
 1602 
 1603 # #23076
 1604 @test :([1,2;]) == Expr(:vect, Expr(:parameters), 1, 2)
 1605 
 1606 # #24452
 1607 @test Meta.parse("(a...)") == Expr(Symbol("..."), :a)
 1608 
 1609 # #19324
 1610 @test_throws UndefVarError(:x) eval(:(module M19324
 1611                  x=1
 1612                  for i=1:10
 1613                      x += i
 1614                  end
 1615              end))
 1616 
 1617 # #22314
 1618 function f22314()
 1619     i = 0
 1620     for i = 1:10
 1621     end
 1622     i
 1623 end
 1624 @test f22314() == 0
 1625 
 1626 module M22314
 1627 i = 0
 1628 for i = 1:10
 1629 end
 1630 end
 1631 @test M22314.i == 0
 1632 
 1633 # #6080
 1634 @test Meta.lower(@__MODULE__, :(ccall(:a, Cvoid, (Cint,), &x))) == Expr(:error, "invalid syntax &x")
 1635 
 1636 @test_throws ParseError Meta.parse("x.'")
 1637 @test_throws ParseError Meta.parse("0.+1")
 1638 
 1639 # #24221
 1640 @test Meta.isexpr(Meta.lower(@__MODULE__, :(a=_)), :error)
 1641 
 1642 for ex in [:([x=1]), :(T{x=1})]
 1643     @test Meta.lower(@__MODULE__, ex) == Expr(:error, string("misplaced assignment statement in \"", ex, "\""))
 1644 end
 1645 
 1646 # issue #28576
 1647 @test Meta.isexpr(Meta.parse("1 == 2 ?"), :incomplete)
 1648 @test Meta.isexpr(Meta.parse("1 == 2 ? 3 :"), :incomplete)
 1649 
 1650 # issue #28991
 1651 eval(Expr(:toplevel,
 1652           Expr(:module, true, :Mod28991,
 1653                Expr(:block,
 1654                     Expr(:export, :Inner),
 1655                     Expr(:abstract, :Inner)))))
 1656 @test names(Mod28991) == Symbol[:Inner, :Mod28991]
 1657 
 1658 # issue #28593
 1659 macro a28593()
 1660     quote
 1661         abstract type A28593{S<:Real, V<:AbstractVector{S}} end
 1662     end
 1663 end
 1664 
 1665 macro b28593()
 1666     quote
 1667         struct B28593{S<:Real, V<:AbstractVector{S}} end
 1668     end
 1669 end
 1670 
 1671 macro c28593()
 1672     quote
 1673         primitive type C28593{S<:Real, V<:AbstractVector{S}} 32 end
 1674     end
 1675 end
 1676 
 1677 @a28593
 1678 @b28593
 1679 @c28593
 1680 
 1681 @test A28593.var.name === :S
 1682 @test B28593.var.name === :S
 1683 @test C28593.var.name === :S
 1684 
 1685 # issue #25955
 1686 macro noeffect25955(e)
 1687     return e
 1688 end
 1689 
 1690 struct foo25955
 1691 end
 1692 
 1693 @noeffect25955 function (f::foo25955)()
 1694     42
 1695 end
 1696 
 1697 @test foo25955()() == 42
 1698 
 1699 # issue #28833
 1700 macro m28833(expr)
 1701     esc(:(global a28833))
 1702 end
 1703 @m28833 1+1
 1704 
 1705 # issue #28900
 1706 macro foo28900(x)
 1707     quote
 1708         $x
 1709     end
 1710 end
 1711 f28900(; kwarg) = kwarg
 1712 let g = @foo28900 f28900(kwarg = x->2x)
 1713     @test g(10) == 20
 1714 end
 1715 
 1716 # issue #26037
 1717 x26037() = 10
 1718 function test_26037()
 1719     [x26037() for _ in 1:3]
 1720     for x26037 in 1:3
 1721        x26037 += x26037
 1722     end
 1723 end
 1724 @test test_26037() === nothing  # no UndefVarError
 1725 
 1726 # range and interval operators
 1727 @test Meta.parse("1…2") == Expr(:call, :…, 1, 2)
 1728 @test Meta.parse("1⁝2") == Expr(:call, :⁝, 1, 2)
 1729 @test Meta.parse("1..2") == Expr(:call, :.., 1, 2)
 1730 # we don't parse chains of these since the associativity and meaning aren't clear
 1731 @test_throws ParseError Meta.parse("1..2..3")
 1732 
 1733 # issue #30048
 1734 @test Meta.isexpr(Meta.lower(@__MODULE__, :(for a in b
 1735            c = try
 1736                try
 1737                    d() do
 1738                        if  GC.@preserve c begin
 1739                            end
 1740                        end
 1741                    end
 1742                finally
 1743                end
 1744            finally
 1745            end
 1746        end)), :thunk)
 1747 
 1748 # issue #28506
 1749 @test Meta.isexpr(Meta.parse("1,"), :incomplete)
 1750 @test Meta.isexpr(Meta.parse("1, "), :incomplete)
 1751 @test Meta.isexpr(Meta.parse("1,\n"), :incomplete)
 1752 @test Meta.isexpr(Meta.parse("1, \n"), :incomplete)
 1753 @test_throws LoadError include_string(@__MODULE__, "1,")
 1754 @test_throws LoadError include_string(@__MODULE__, "1,\n")
 1755 
 1756 # issue #30062
 1757 let er = Meta.lower(@__MODULE__, quote if false end, b+=2 end)
 1758     @test Meta.isexpr(er, :error)
 1759     @test startswith(er.args[1], "invalid multiple assignment location \"if")
 1760 end
 1761 
 1762 # issue #30030
 1763 let x = 0
 1764     @test (a=1, b=2, c=(x=3)) == (a=1, b=2, c=3)
 1765     @test x == 3
 1766 end