-
-
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
Allow ...
outside call
#48750
Allow ...
outside call
#48750
Conversation
This seems to cause problems with these tests for REPL completions: https://github.com/JuliaLang/julia/blob/master/stdlib/REPL/test/replcompletions.jl#L734-L749 Does anyone know how to diagnose what's going on here that would cause that? |
This may be a good idea anyway, but I think the macro precedence issue is not fixable. The problem is |
@@ -2766,7 +2767,8 @@ | |||
'.>>>= lower-update-op | |||
|
|||
'|...| | |||
(lambda (e) (error "\"...\" expression outside call")) | |||
(lambda (e) | |||
(expand-tuple (cadr e))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(expand-tuple (cadr e))) | |
(expand-tuple (cons 'tuple (cdr e)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I tied at first, but when I do that I get
julia> (1,2)...
((1, 2),)
instead of the desired (1, 2)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe (list 'tuple e)
?
Yeah, I also came upon that unfortunate realization earlier today. Chris may have a way out here though: #36547 (comment) |
I don't read femtolisp unfortunately, but REPL completions diagnostic is right up my alley! Unfortunately, that code is quite brittle when handling varargs... What happens in general is that, at some point, the type of something like julia/stdlib/REPL/src/REPLCompletions.jl Lines 507 to 511 in 78ec99b
(x...) , but fails since it's a splat outside a call. So the catch part is executed and the whole get_type procedure returns a cautious Any as the expected type of the expression. In summary, a splat is interpreted as a value of type Any .But your PR makes it not break! So it happily returns a definite Tuple{DataType} (in the case of the failing test where x is Integer[] ).
The root issue is that both answers are wrong: what should be returned is A definite fix is included in #44434, but that PR is complicated and it's larger than your issue. Some fix specific to varargs completion could be extracted from 6a1bfbf I believe. Anyway, as a quick-fix for this PR, I suggest adding the following, which simply forces any vararg expression to be interpreted as a value of type diff --git a/stdlib/REPL/src/REPLCompletions.jl b/stdlib/REPL/src/REPLCompletions.jl
index 34ce7ad992..ec95723550 100644
--- a/stdlib/REPL/src/REPLCompletions.jl
+++ b/stdlib/REPL/src/REPLCompletions.jl
@@ -481,6 +481,8 @@ function try_get_type(sym::Expr, fn::Module)
return try_get_type(sym.args[end], fn)
elseif sym.head === :escape || sym.head === :var"hygienic-scope"
return try_get_type(sym.args[1], fn)
+ elseif sym.head === :...
+ return (Any, true)
end
return (Any, false)
end |
Closes #48738
What
Why?
I want this because SimpleUnderscores.jl provides a macro
@->
which is meant to act like an anonymous function, but macros have different precedence than->
so we get this:This means that if
@->
wants to mimic the behaviour of->
, it needs to splat out multiple arguments but that currently causes an error if done outside of a:call
expression.