-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Restrict REPL method completion to ignore strictly less specific ones #43572
Conversation
3080053
to
27f8d56
Compare
Actually there is a better reason to TAB-complete potentially ambiguous method calls: the REPL may simply not have access to the tightest argument types. For example: julia> foo(a::Integer, b) = x;
julia> foo(u, v::Integer) = v;
julia> foo(x::Int, y::Int) = x + y;
julia> foo(Ref{Integer}(4)[], Ref{Integer}(3)[], #TAB
foo(x::Int64, y::Int64) in Main at REPL[3]:1
foo(a::Integer, b) in Main at REPL[1]:1
foo(u, v::Integer) in Main at REPL[2]:1
julia> foo(Ref{Integer}(4)[], Ref{Integer}(3)[])
7
julia> foo(Ref{Integer}(4)[], Ref{Integer}(0x0000ab)[], #TAB
foo(x::Int64, y::Int64) in Main at REPL[3]:1
foo(a::Integer, b) in Main at REPL[1]:1
foo(u, v::Integer) in Main at REPL[2]:1
julia> foo(Ref{Integer}(4)[], Ref{Integer}(0x0000ab)[])
ERROR: MethodError: foo(::Int64, ::UInt32) is ambiguous. Candidates:
foo(a::Integer, b) in Main at REPL[1]:1
foo(u, v::Integer) in Main at REPL[2]:1
Possible fix, define
foo(::Integer, ::Integer)
Stacktrace:
[1] top-level scope
@ REPL[6]:1 I amended the comment and added tests for this in the latest commit. |
27f8d56
to
8920038
Compare
Now rebased on top of #43577. CI failure on linux32 is unrelated |
- Restrict method completion to ignore strictly less specific ones - Fix various lookup bugs - Improve slurping of final expression Inspired by #43572 Co-authored-by: Lionel Zoubritzky <lionel.zoubritzky@gmail.com>
- Restrict method completion to ignore strictly less specific ones - Fix various lookup bugs - Improve slurping of final expression Inspired by #43572 Co-authored-by: Lionel Zoubritzky <lionel.zoubritzky@gmail.com>
- Restrict method completion to ignore strictly less specific ones - Fix various lookup bugs - Improve slurping of final expression Inspired by #43572 Co-authored-by: Lionel Zoubritzky <lionel.zoubritzky@gmail.com>
- Restrict method completion to ignore strictly less specific ones - Fix various lookup bugs - Improve slurping of final expression Inspired by #43572 Co-authored-by: Lionel Zoubritzky <lionel.zoubritzky@gmail.com>
- Restrict method completion to ignore strictly less specific ones - Fix various lookup bugs - Improve slurping of final expression Inspired by #43572 Co-authored-by: Lionel Zoubritzky <lionel.zoubritzky@gmail.com>
- Restrict method completion to ignore strictly less specific ones - Fix various lookup bugs - Improve slurping of final expression Inspired by #43572 Co-authored-by: Lionel Zoubritzky <lionel.zoubritzky@gmail.com>
- Restrict method completion to ignore strictly less specific ones - Fix various lookup bugs - Improve slurping of final expression Inspired by #43572 Co-authored-by: Lionel Zoubritzky <lionel.zoubritzky@gmail.com>
For reference, the issue that appeared in #43536 was: julia> boo(a::Int; kw1) = a - kw1;
julia> boo(a::Integer; kw2) = a + kw2;
julia> boo(3; kw#TAB
kw1= kw2= kwsorter3 kwtest3 kwtest4 The |
Closing now since #43865 is a strict superset of this PR. |
- Restrict method completion to ignore strictly less specific ones - Fix various lookup bugs - Improve slurping of final expression Inspired by JuliaLang#43572 Co-authored-by: Lionel Zoubritzky <lionel.zoubritzky@gmail.com>
- Restrict method completion to ignore strictly less specific ones - Fix various lookup bugs - Improve slurping of final expression Inspired by JuliaLang#43572 Co-authored-by: Lionel Zoubritzky <lionel.zoubritzky@gmail.com>
Spurred by (and solves) "the inevitable edge-case" of #43536.
To copy-paste the issue I described there, we currently have:
Both methods are suggested, while only the first one is any relevant since the type of
x
is known to beInt
, which means that in this context,foo(3, a)
will always call the first method, independently of the type ofa
.This PR fixes that by removing suggestions of methods that are strictly less specific than other ones:
It also happens when using the
?(x,y)TAB
syntax of #38791 since I believe that's desired as well there.A note on method ambiguities: I chose to keep ambiguous method calls, even though they can only result in error, since I think it can help debug those ambiguity errors. To continue with the same example, in this PR: