Skip to content

Commit 0549bf1

Browse files
staticfloatJeffBezanson
authored andcommitted
fieldnames() can throw for types such as typeof(+) (#32840)
Fixes #32558
1 parent b28bb24 commit 0549bf1

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

stdlib/REPL/src/REPLCompletions.jl

+12-5
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,18 @@ function complete_symbol(sym, ffunc, context_module=Main)::Vector{Completion}
153153
else
154154
# Looking for a member of a type
155155
if t isa DataType && t != Any
156-
fields = fieldnames(t)
157-
for field in fields
158-
s = string(field)
159-
if startswith(s, name)
160-
push!(suggestions, FieldCompletion(t, field))
156+
# Check for cases like Type{typeof(+)}
157+
if t isa DataType && t.name === Base._TYPE_NAME
158+
t = typeof(t.parameters[1])
159+
end
160+
# Only look for fields if this is a concrete type
161+
if isconcretetype(t)
162+
fields = fieldnames(t)
163+
for field in fields
164+
s = string(field)
165+
if startswith(s, name)
166+
push!(suggestions, FieldCompletion(t, field))
167+
end
161168
end
162169
end
163170
end

stdlib/REPL/test/replcompletions.jl

+6
Original file line numberDiff line numberDiff line change
@@ -1049,3 +1049,9 @@ let s = "prevind(\"θ\",1,"
10491049
@test r == 1:7
10501050
@test s[r] == "prevind"
10511051
end
1052+
1053+
# Issue #32840
1054+
let s = "typeof(+)."
1055+
c, r = test_complete_context(s)
1056+
@test length(c) == length(fieldnames(DataType))
1057+
end

0 commit comments

Comments
 (0)