Skip to content

Commit

Permalink
fieldnames() can throw for types such as typeof(+) (#32840)
Browse files Browse the repository at this point in the history
Fixes #32558
  • Loading branch information
staticfloat authored and JeffBezanson committed Jan 21, 2020
1 parent b28bb24 commit 0549bf1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
17 changes: 12 additions & 5 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,18 @@ function complete_symbol(sym, ffunc, context_module=Main)::Vector{Completion}
else
# Looking for a member of a type
if t isa DataType && t != Any
fields = fieldnames(t)
for field in fields
s = string(field)
if startswith(s, name)
push!(suggestions, FieldCompletion(t, field))
# Check for cases like Type{typeof(+)}
if t isa DataType && t.name === Base._TYPE_NAME
t = typeof(t.parameters[1])
end
# Only look for fields if this is a concrete type
if isconcretetype(t)
fields = fieldnames(t)
for field in fields
s = string(field)
if startswith(s, name)
push!(suggestions, FieldCompletion(t, field))
end
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions stdlib/REPL/test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1049,3 +1049,9 @@ let s = "prevind(\"θ\",1,"
@test r == 1:7
@test s[r] == "prevind"
end

# Issue #32840
let s = "typeof(+)."
c, r = test_complete_context(s)
@test length(c) == length(fieldnames(DataType))
end

0 comments on commit 0549bf1

Please sign in to comment.