Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPLCompletions: allow field completions for Union results #50503

Merged
merged 2 commits into from
Jul 12, 2023

Conversation

aviatesk
Copy link
Member

This generalizes the idea of #50483 and enables field completions when the result type is inferred to be Union{A,B} where A is not necessarily the same type as B.

aviatesk and others added 2 commits July 11, 2023 16:56
This generalizes the idea of #50483 and enables field completions when
the result type is inferred to be `Union{A,B}` where `A` is not
necessarily the same type as `B`.
end

function add_field_completions!(suggestions::Vector{Completion}, name::String, @nospecialize(t))
if isa(t, Union)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if isa(t, Union)
t = Base.unwrap_unionall(t)
if isa(t, Union)

Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Though note that some types (e.g. NamedTuple) may throw an exception when you try to call fieldnames on them.

ERROR: ArgumentError: type does not have definite field names

@aviatesk
Copy link
Member Author

The check performed just above (if isconcretetype(t) ) makes sure that fieldnames(t) does not throw an exception? Otherwise we probably need to wrap the fieldnames(t) call within try/catch clause.

@aviatesk aviatesk merged commit 4995d3f into master Jul 12, 2023
@aviatesk aviatesk deleted the avi/repl-completion-union branch July 12, 2023 06:09
@brenhinkeller brenhinkeller added the REPL Julia's REPL (Read Eval Print Loop) label Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants