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: unswitch Union of same UnionAll results #50483

Merged
merged 1 commit into from
Jul 11, 2023

Conversation

aviatesk
Copy link
Member

@aviatesk aviatesk commented Jul 9, 2023

With this commit the inference-based REPL completion algorithm converts Union result of same UnionAll instances to UnionAll of Unions so that it can use the field information of the UnionAll.

This allows us to get completions for cases like:

julia> union_somes() = rand() < 0.5 ? Some(1) : Some(2.);

julia> union_somes().| # completes to `value`

With this commit the inference-base REPL completion algorithm converts
`Union` result of same `UnionAll` instances to `UnionAll` of `Union`s
so that it can use the field information of the `UnionAll`.

This allows us to get completions for cases like:
```julia
julia> union_somes() = rand() < 0.5 ? Some(1) : Some(2.);

julia> union_somes().| # completes to `value`
```
@aviatesk aviatesk requested a review from vtjnash July 9, 2023 15:53
@aviatesk aviatesk merged commit 680e3b3 into master Jul 11, 2023
@aviatesk aviatesk deleted the avi/union-completion branch July 11, 2023 04:57
aviatesk added a commit that referenced this pull request Jul 11, 2023
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`.
Comment on lines +344 to +346
Head = (typename::Core.TypeName).wrapper
unionparams = Any[ Union{Any[(t::DataType).parameters[i] for t in ts]...} for i in 1:n ]
return Head{unionparams...}
Copy link
Member

Choose a reason for hiding this comment

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

This is very much illegal from a type variance perspective. Are you sure we shouldn't be using something like typejoin instead that preserves subtyping correctness on the answer?

Copy link
Member Author

Choose a reason for hiding this comment

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

The discussion is ongoing in #50511.

aviatesk added a commit that referenced this pull request Jul 12, 2023
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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants