-
-
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
deprecate using _
as an rvalue
#20328
Conversation
For now this seems sufficient to me. I'm curious what the thumbs downs are about. |
I don't really like having this special cased as a variable name you can't use. |
If most of the goal here is for unused lvalues, I have an idea that's more verbose (and a bit of a pun) but doesn't require any modified syntax: julia> import Base: setindex!, DevNullStream
julia> setindex!(::DevNullStream, x) = nothing
setindex! (generic function with 94 methods)
julia> a, DevNull[], DevNull[] = (1, 2, 3)
(1,2,3)
julia> a
1 |
Several chaining packages currently use _ extensively. Edit: we've got magic to do, just for you. Join us! |
There is a precedent for this in Erlang - http://stackoverflow.com/questions/13707361/anonymous-variables-in-erlang |
@amitmurthy I'd actually argue that your link shows that "magical" things like this introduce potentially confusing special cases. |
It ceases to be magical once documented and widely used. And then it gets known as a feature of the language. I found it quite useful when writing code in Erlang. |
I don't believe this will affect uses in macros. If the macro renames One problem with the |
There's less need for syntax magic there though, right? In most languages that have this as special syntax, isn't it playing a role in pattern matching of some kind? |
I believe the use in pattern matching is basically compatible; it matches anything and discards it. |
Do you mean:
|
What I mean is that writing |
In fact, this effectively clears the use of |
Looking at existing uses of this in packages, there are fair number of uses of the form |
Can you quantify "fair number"? |
These are some messy greps, kinda need to manually look through with some meaningful and some (most) not. I'm even seeing also a few places where it's used for a type parameter |
It's weird, but using it as a field name could still be allowed maybe. |
e1f26ae
to
418631a
Compare
418631a
to
d3d6090
Compare
I'm still thinking we should do this. The idea is not a global ban on the symbol |
I already don't like it, it's an odd special case that this is a valid identifier name that you aren't allowed to use. And that we're disallowing rvalue usage in order to later have an lvalue-ignore feature. |
It's a relatively innocuous kind of special case, since it gives an early error. As opposed to, say, |
Merging this affords us the option to use |
Would be great to have this as a first step towards #9343. |
The simplest case doesn't actually get caught by this deprecation:
Probably a special case where we skip eval when the input is just a symbol. |
Good catch @StefanKarpinski. It's doing |
Probably |
Good hunting – I did not manage to track that down. |
I think this is giving a spurious warning in ImageFiltering. shell> touch ImageFiltering.jl
julia> using ImageFiltering
INFO: Recompiling stale cache file /home/tim/.julia/lib/v0.6/ImageFiltering.ji for module ImageFiltering.
WARNING: deprecated syntax "_ as an rvalue".
WARNING: deprecated syntax "_ as an rvalue". I've checked the results of Requires JuliaImages/ImageFiltering.jl#25 if you don't want a sea of other warnings. And the build is broken current due to #20658, but you can work around that by commenting out the second |
Could it be in some macro defined by another package that ImageFiltering is using? |
Could be. Since this is a parser depwarn, is it possible to produce a more useful message localizing the problem? One already has to do a certain amount of work even to localize which package(s) are producing the warning. Usually I solve such problems by grepping my whole package directory for the offending string, but in this case that's not really practical: tim@diva:~/.julia/v0.5$ fls=$(find . -name "*.jl")
tim@diva:~/.julia/v0.5$ grep "=.*_" $fls | wc
35049 215863 3267100 For small packages it's usually pretty easy to find, but for big ones I think the only option is to copy-paste each file at the REPL and scan the output. That's pretty painful. I had the impression that parser depwarns are "easy," so I'm hopeful that the lack of useful file/line info is just an oversight. But since it's only for |
@timholy in the meantime, you could refine that regex like this |
This is a minimal change to get a warning for accessing the value of
_
. We need to decide whether this extends toeval(:_)
andMod._
. I'm also not sure we want/need to allow multiple_
as argument names in this release; that will take more work.