Skip to content

Commit 9ce01d8

Browse files
committed
remove fallback eltype that returns Any for all types
1 parent 4c15c6b commit 9ce01d8

File tree

7 files changed

+9
-10
lines changed

7 files changed

+9
-10
lines changed

base/array.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ julia> eltype(fill(0x1, (2,2)))
8484
UInt8
8585
```
8686
"""
87-
eltype(::Type) = Any
87+
eltype(t::Type) = throw(MethodError(eltype, (t,)))
8888
eltype(::Type{Bottom}) = throw(ArgumentError("Union{} does not have elements"))
8989
eltype(x) = eltype(typeof(x))
9090

base/compiler/abstractinterpretation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ function precise_container_type(@nospecialize(arg), @nospecialize(typ), vtypes::
350350
else
351351
return Any[ p for p in tti0.parameters ]
352352
end
353-
elseif tti0 <: Array
353+
elseif tti0 isa Type{<:Array{T}} where T
354354
return Any[Vararg{eltype(tti0)}]
355355
else
356356
return Any[abstract_iteration(typ, vtypes, sv)]

base/dict.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Dict(ps::Pair...) = Dict(ps)
134134

135135
function Dict(kv)
136136
try
137-
dict_with_eltype((K, V) -> Dict{K, V}, kv, eltype(kv))
137+
dict_with_eltype((K, V) -> Dict{K, V}, kv, IteratorEltype(typeof(kv)) isa HasEltype ? eltype(kv) : Any)
138138
catch e
139139
if !applicable(start, kv) || !all(x->isa(x,Union{Tuple,Pair}),kv)
140140
throw(ArgumentError("Dict(kv): kv needs to be an iterator of tuples or pairs"))

base/weakkeydict.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ WeakKeyDict(ps::Pair...) = WeakKeyDict{Any,Any}(ps)
5858

5959
function WeakKeyDict(kv)
6060
try
61-
Base.dict_with_eltype((K, V) -> WeakKeyDict{K, V}, kv, eltype(kv))
61+
Base.dict_with_eltype((K, V) -> WeakKeyDict{K, V}, kv, IteratorEltype(typeof(kv)) isa HasEltype ? eltype(kv) : Any)
6262
catch e
6363
if !applicable(start, kv) || !all(x->isa(x,Union{Tuple,Pair}),kv)
6464
throw(ArgumentError("WeakKeyDict(kv): kv needs to be an iterator of tuples or pairs"))

stdlib/Distributed/src/cluster.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ mutable struct WorkerConfig
4242

4343
function WorkerConfig()
4444
wc = new()
45-
for n in 1:length(WorkerConfig.types)
46-
T = eltype(fieldtype(WorkerConfig, n))
45+
for n in 1:fieldcount(WorkerConfig)
4746
setfield!(wc, n, nothing)
4847
end
4948
wc

stdlib/Random/src/Random.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ struct SamplerTrivial{T,E} <: Sampler{E}
132132
self::T
133133
end
134134

135-
SamplerTrivial(x::T) where {T} = SamplerTrivial{T,eltype(T)}(x)
135+
SamplerTrivial(x::T) where {T} = SamplerTrivial{T,Any}(x)
136136

137137
Sampler(::AbstractRNG, x, ::Repetition) = SamplerTrivial(x)
138138

@@ -144,14 +144,14 @@ struct SamplerSimple{T,S,E} <: Sampler{E}
144144
data::S
145145
end
146146

147-
SamplerSimple(x::T, data::S) where {T,S} = SamplerSimple{T,S,eltype(T)}(x, data)
147+
SamplerSimple(x::T, data::S) where {T,S} = SamplerSimple{T,S,Any}(x, data)
148148

149149
Base.getindex(sp::SamplerSimple) = sp.self
150150

151151
# simple sampler carrying a (type) tag T and data
152152
struct SamplerTag{T,S,E} <: Sampler{E}
153153
data::S
154-
SamplerTag{T}(s::S) where {T,S} = new{T,S,eltype(T)}(s)
154+
SamplerTag{T}(s::S) where {T,S} = new{T,S,Any}(s)
155155
end
156156

157157

test/missing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ end
358358
@test collect(x) isa Vector{Int}
359359

360360
x = skipmissing(v for v in [missing, 1, missing, 2, 4])
361-
@test eltype(x) === Any
361+
@test_throws MethodError eltype(x)
362362
@test collect(x) == [1, 2, 4]
363363
@test collect(x) isa Vector{Int}
364364
end

0 commit comments

Comments
 (0)