Skip to content

Commit 9e99af6

Browse files
authored
improve minor inferrabilities (#42141)
1 parent 3a4198e commit 9e99af6

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

base/shell.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,24 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
4949
empty!(innerlist)
5050
end
5151

52+
C = eltype(str)
53+
P = Pair{Int,C}
5254
for (j, c) in st
53-
j, c = j::Int, c::eltype(str)
55+
j, c = j::Int, c::C
5456
if !in_single_quotes && !in_double_quotes && isspace(c)
5557
i = consume_upto!(arg, s, i, j)
5658
append_2to1!(args, arg)
5759
while !isempty(st)
5860
# We've made sure above that we don't end in whitespace,
5961
# so updating `i` here is ok
60-
(i, c) = peek(st)::Pair{Int,eltype(str)}
62+
(i, c) = peek(st)::P
6163
isspace(c) || break
6264
popfirst!(st)
6365
end
6466
elseif interpolate && !in_single_quotes && c == '$'
6567
i = consume_upto!(arg, s, i, j)
6668
isempty(st) && error("\$ right before end of command")
67-
stpos, c = popfirst!(st)::Pair{Int,eltype(str)}
69+
stpos, c = popfirst!(st)::P
6870
isspace(c) && error("space not allowed right after \$")
6971
if startswith(SubString(s, stpos), "var\"")
7072
# Disallow var"#" syntax in cmd interpolations.
@@ -88,19 +90,19 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
8890
in_double_quotes = !in_double_quotes
8991
i = consume_upto!(arg, s, i, j)
9092
elseif !in_single_quotes && c == '\\'
91-
if !isempty(st) && peek(st)[2] in ('\n', '\r')
93+
if !isempty(st) && (peek(st)::P)[2] in ('\n', '\r')
9294
i = consume_upto!(arg, s, i, j) + 1
93-
if popfirst!(st)[2] == '\r' && peek(st)[2] == '\n'
95+
if popfirst!(st)[2] == '\r' && (peek(st)::P)[2] == '\n'
9496
i += 1
9597
popfirst!(st)
9698
end
97-
while !isempty(st) && peek(st)[2] in (' ', '\t')
99+
while !isempty(st) && (peek(st)::P)[2] in (' ', '\t')
98100
i = nextind(str, i)
99101
_ = popfirst!(st)
100102
end
101103
elseif in_double_quotes
102104
isempty(st) && error("unterminated double quote")
103-
k, c′ = peek(st)
105+
k, c′ = peek(st)::P
104106
if c′ == '"' || c′ == '$' || c′ == '\\'
105107
i = consume_upto!(arg, s, i, j)
106108
_ = popfirst!(st)

base/strings/unicode.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ function iterate(g::GraphemeIterator, i_=(Int32(0),firstindex(g.s)))
681681
y === nothing && return nothing
682682
c0, k = y
683683
while k <= ncodeunits(s) # loop until next grapheme is s[i:j]
684-
c, ℓ = iterate(s, k)
684+
c, ℓ = iterate(s, k)::NTuple{2,Any}
685685
isgraphemebreak!(state, c0, c) && break
686686
j = k
687687
k =

0 commit comments

Comments
 (0)