@@ -965,7 +965,7 @@ function operator_associativity(s::Symbol)
965
965
end
966
966
967
967
is_expr (@nospecialize (ex), head:: Symbol ) = isa (ex, Expr) && (ex. head === head)
968
- is_expr (@nospecialize (ex), head:: Symbol , n:: Int ) = is_expr (ex, head) && length (ex . args) == n
968
+ is_expr (@nospecialize (ex), head:: Symbol , n:: Int ) = is_expr (ex, head) && length ((ex :: Expr ) . args) == n
969
969
970
970
is_quoted (ex) = false
971
971
is_quoted (ex:: QuoteNode ) = true
@@ -1031,13 +1031,15 @@ function show_list(io::IO, items, sep, indent::Int, prec::Int=0, quote_level::In
1031
1031
! first && print (io, sep)
1032
1032
parens = ! is_quoted (item) &&
1033
1033
(first && prec >= prec_power &&
1034
- ((item isa Expr && item. head === :call && item. args[1 ] in uni_ops) ||
1034
+ ((item isa Expr && item. head === :call && (callee = item. args[1 ]; isa (callee, Symbol) && callee in uni_ops) ) ||
1035
1035
(item isa Real && item < 0 ))) ||
1036
1036
(enclose_operators && item isa Symbol && isoperator (item))
1037
1037
parens && print (io, ' (' )
1038
1038
if kw && is_expr (item, :kw , 2 )
1039
+ item = item:: Expr
1039
1040
show_unquoted (io, Expr (:(= ), item. args[1 ], item. args[2 ]), indent, parens ? 0 : prec, quote_level)
1040
1041
elseif kw && is_expr (item, :(= ), 2 )
1042
+ item = item:: Expr
1041
1043
show_unquoted_expr_fallback (io, item, indent, quote_level)
1042
1044
else
1043
1045
show_unquoted (io, item, indent, parens ? 0 : prec, quote_level)
@@ -1261,7 +1263,7 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
1261
1263
# .
1262
1264
print (io, ' .' )
1263
1265
# item
1264
- parens = ! (field isa Symbol) || (field in quoted_syms)
1266
+ parens = ! (field isa Symbol) || (field:: Symbol in quoted_syms)
1265
1267
quoted = parens || isoperator (field)
1266
1268
quoted && print (io, ' :' )
1267
1269
parens && print (io, ' (' )
@@ -1284,13 +1286,14 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
1284
1286
elseif head === :tuple
1285
1287
print (io, " (" )
1286
1288
if nargs > 0 && is_expr (args[1 ], :parameters )
1289
+ arg1 = args[1 ]:: Expr
1287
1290
show_list (io, args[2 : end ], " , " , indent, 0 , quote_level)
1288
1291
nargs == 2 && print (io, ' ,' )
1289
1292
print (io, " ;" )
1290
- if ! isempty (args[ 1 ] . args)
1293
+ if ! isempty (arg1 . args)
1291
1294
print (io, " " )
1292
1295
end
1293
- show_list (io, args[ 1 ] . args, " , " , indent, 0 , quote_level, false , true )
1296
+ show_list (io, arg1 . args, " , " , indent, 0 , quote_level, false , true )
1294
1297
else
1295
1298
show_list (io, args, " , " , indent, 0 , quote_level)
1296
1299
nargs == 1 && print (io, ' ,' )
@@ -1331,7 +1334,7 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
1331
1334
func = args[1 ]
1332
1335
fname = isa (func, GlobalRef) ? func. name : func
1333
1336
func_prec = operator_precedence (fname)
1334
- if func_prec > 0 || fname in uni_ops
1337
+ if func_prec > 0 || ( isa ( fname, Symbol) && fname in uni_ops)
1335
1338
func = fname
1336
1339
end
1337
1340
func_args = args[2 : end ]
@@ -1343,7 +1346,7 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
1343
1346
# scalar multiplication (i.e. "100x")
1344
1347
elseif (func === :* &&
1345
1348
length (func_args) == 2 && isa (func_args[1 ], Union{Int, Int64, Float32, Float64}) &&
1346
- isa (func_args[2 ], Symbol) && ! in (string (func_args[2 ])[1 ], (' e' , ' E' , ' f' )))
1349
+ isa (func_args[2 ], Symbol) && ! in (string (func_args[2 ]:: Symbol )[1 ], (' e' , ' E' , ' f' )))
1347
1350
if func_prec <= prec
1348
1351
show_enclosed_list (io, ' (' , func_args, " " , ' )' , indent, func_prec, quote_level)
1349
1352
else
@@ -1363,7 +1366,7 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
1363
1366
# binary operator (i.e. "x + y")
1364
1367
elseif func_prec > 0 # is a binary operator
1365
1368
na = length (func_args)
1366
- if (na == 2 || (na > 2 && func in (:+ , :++ , :* )) || (na == 3 && func === :(:))) &&
1369
+ if (na == 2 || (na > 2 && isa (func, Symbol) && func in (:+ , :++ , :* )) || (na == 3 && func === :(:))) &&
1367
1370
all (! isa (a, Expr) || a. head != = :... for a in func_args)
1368
1371
sep = func === :(:) ? " $func " : " $func "
1369
1372
@@ -1431,7 +1434,7 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
1431
1434
# function calls need to transform the function from :call to :calldecl
1432
1435
# so that operators are printed correctly
1433
1436
elseif head === :function && nargs== 2 && is_expr (args[1 ], :call )
1434
- show_block (IOContext (io, beginsym=> false ), head, Expr (:calldecl , args[1 ]. args... ), args[2 ], indent, quote_level)
1437
+ show_block (IOContext (io, beginsym=> false ), head, Expr (:calldecl , ( args[1 ]:: Expr ) . args... ), args[2 ], indent, quote_level)
1435
1438
print (io, " end" )
1436
1439
1437
1440
elseif (head === :function || head === :macro ) && nargs == 1
@@ -1443,8 +1446,8 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
1443
1446
iob = IOContext (io, beginsym=> false )
1444
1447
show_unquoted (iob, args[1 ], indent, - 1 , quote_level)
1445
1448
print (io, " do " )
1446
- show_list (iob, args[2 ]. args[1 ]. args, " , " , 0 , 0 , quote_level)
1447
- for stmt in args[2 ]. args[2 ]. args
1449
+ show_list (iob, ((( args[2 ]:: Expr ) . args[1 ]) :: Expr ) . args, " , " , 0 , 0 , quote_level)
1450
+ for stmt in ((( args[2 ]:: Expr ) . args[2 ]) :: Expr ) . args
1448
1451
print (io, ' \n ' , " " ^ (indent + indent_width))
1449
1452
show_unquoted (iob, stmt, indent + indent_width, - 1 , quote_level)
1450
1453
end
@@ -1463,10 +1466,11 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
1463
1466
elseif (head === :if || head === :elseif ) && nargs == 3
1464
1467
iob = IOContext (io, beginsym=> false )
1465
1468
show_block (iob, head, args[1 ], args[2 ], indent, quote_level)
1466
- if isa (args[3 ],Expr) && args[3 ]. head === :elseif
1467
- show_unquoted (iob, args[3 ], indent, prec, quote_level)
1469
+ arg3 = args[3 ]
1470
+ if isa (arg3, Expr) && arg3. head === :elseif
1471
+ show_unquoted (iob, arg3:: Expr , indent, prec, quote_level)
1468
1472
else
1469
- show_block (iob, " else" , args[ 3 ] , indent, quote_level)
1473
+ show_block (iob, " else" , arg3 , indent, quote_level)
1470
1474
print (io, " end" )
1471
1475
end
1472
1476
@@ -1562,7 +1566,8 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
1562
1566
show_sym (io, arg1, allow_macroname= true )
1563
1567
elseif arg1 isa GlobalRef
1564
1568
show_globalref (io, arg1, allow_macroname= true )
1565
- elseif is_expr (arg1, :(.)) && length (arg1. args) == 2
1569
+ elseif is_expr (arg1, :(.)) && length ((arg1:: Expr ). args) == 2
1570
+ arg1 = arg1:: Expr
1566
1571
m = arg1. args[1 ]
1567
1572
if m isa Symbol || m isa GlobalRef || is_expr (m, :(.), 2 )
1568
1573
show_unquoted (io, m)
@@ -1573,9 +1578,9 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
1573
1578
end
1574
1579
print (io, ' .' )
1575
1580
if is_expr (arg1. args[2 ], :quote )
1576
- mname = arg1. args[2 ]. args[1 ]
1581
+ mname = ( arg1. args[2 ]:: Expr ) . args[1 ]
1577
1582
else
1578
- mname = arg1. args[2 ]. value
1583
+ mname = ( arg1. args[2 ]:: QuoteNode ) . value
1579
1584
end
1580
1585
if mname isa Symbol
1581
1586
show_sym (io, mname, allow_macroname= true )
@@ -1593,10 +1598,10 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
1593
1598
iob = IOContext (io, beginsym=> false )
1594
1599
show_block (iob, " try" , args[1 ], indent, quote_level)
1595
1600
if is_expr (args[3 ], :block )
1596
- show_block (iob, " catch" , args[2 ] === false ? Any[] : args[2 ], args[3 ], indent, quote_level)
1601
+ show_block (iob, " catch" , args[2 ] === false ? Any[] : args[2 ], args[3 ]:: Expr , indent, quote_level)
1597
1602
end
1598
1603
if nargs >= 4 && is_expr (args[4 ], :block )
1599
- show_block (iob, " finally" , Any[], args[4 ], indent, quote_level)
1604
+ show_block (iob, " finally" , Any[], args[4 ]:: Expr , indent, quote_level)
1600
1605
end
1601
1606
print (io, " end" )
1602
1607
@@ -1627,9 +1632,9 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
1627
1632
1628
1633
elseif head === :quote && nargs == 1 && isa (args[1 ], Symbol)
1629
1634
show_unquoted_quote_expr (IOContext (io, beginsym=> false ), args[1 ]:: Symbol , indent, 0 , quote_level+ 1 )
1630
- elseif head === :quote && ! get (io, :unquote_fallback , true )
1635
+ elseif head === :quote && ! ( get (io, :unquote_fallback , true ) :: Bool )
1631
1636
if nargs == 1 && is_expr (args[1 ], :block )
1632
- show_block (IOContext (io, beginsym=> false ), " quote" , Expr (:quote , args[1 ]. args... ), indent,
1637
+ show_block (IOContext (io, beginsym=> false ), " quote" , Expr (:quote , ( args[1 ]:: Expr ) . args... ), indent,
1633
1638
quote_level+ 1 )
1634
1639
print (io, " end" )
1635
1640
elseif nargs == 1
0 commit comments