diff --git a/NEWS.md b/NEWS.md index 11a56e3b90408..f21dc28f6a62b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -118,6 +118,9 @@ Language changes * `reduce(+, [...])` and `reduce(*, [...])` no longer widen the iterated over arguments to system word size. `sum` and `prod` still preserve this behavior. ([#22825]) + * Like `_`, variable names consisting only of underscores can be assigned, + but accessing their values is deprecated ([#24221]). + Breaking changes ---------------- diff --git a/base/client.jl b/base/client.jl index 29abb482966a8..f38e655724840 100644 --- a/base/client.jl +++ b/base/client.jl @@ -208,8 +208,8 @@ function parse_input_line(s::String; filename::String="none") # expr ex = ccall(:jl_parse_input_line, Any, (Ptr{UInt8}, Csize_t, Ptr{UInt8}, Csize_t), s, sizeof(s), filename, sizeof(filename)) - if ex === :_ - # remove with 0.6 deprecation + if ex isa Symbol && all(equalto('_'), string(ex)) + # remove with 0.7 deprecation expand(Main, ex) # to get possible warning about using _ as an rvalue end return ex diff --git a/src/flisp/julia_extensions.c b/src/flisp/julia_extensions.c index b54c6889ab982..598defd763794 100644 --- a/src/flisp/julia_extensions.c +++ b/src/flisp/julia_extensions.c @@ -210,6 +210,16 @@ value_t fl_julia_strip_op_suffix(fl_context_t *fl_ctx, value_t *args, uint32_t n return opnew_symbol; } +/* check whether arg is a symbol that consists solely of underscores. */ +value_t fl_julia_underscore_symbolp(fl_context_t *fl_ctx, value_t *args, uint32_t nargs) +{ + argcount(fl_ctx, "underscore-symbol?", nargs, 1); + if (!issymbol(args[0])) return fl_ctx->F; + char *op = symbol_name(fl_ctx, args[0]); + while (*op == '_') ++op; + return *op ? fl_ctx->F : fl_ctx->T; +} + #include "julia_charmap.h" utf8proc_int32_t jl_charmap_map(utf8proc_int32_t c, void *ctx) @@ -298,6 +308,7 @@ static const builtinspec_t julia_flisp_func_info[] = { { "identifier-start-char?", fl_julia_identifier_start_char }, { "op-suffix-char?", fl_julia_op_suffix_char }, { "strip-op-suffix", fl_julia_strip_op_suffix }, + { "underscore-symbol?", fl_julia_underscore_symbolp }, { NULL, NULL } }; diff --git a/src/jlfrontend.scm b/src/jlfrontend.scm index e704f540b1500..6942c9fb375d2 100644 --- a/src/jlfrontend.scm +++ b/src/jlfrontend.scm @@ -100,8 +100,8 @@ (or (memq (car e) '(toplevel line module import importall using export error incomplete)) (and (eq? (car e) 'global) (every symbol? (cdr e)))))) - (if (eq? e '_) - (syntax-deprecation #f "_ as an rvalue" "")) + (if (underscore-symbol? e) + (syntax-deprecation #f "underscores as an rvalue" "")) e) (else (let ((last *in-expand*)) diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 4d668dc861222..9afa174c4b19f 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -3515,11 +3515,11 @@ f(x) = yt(x) (let ((e1 (if (and arg-map (symbol? e)) (get arg-map e e) e))) - (if (and value (or (eq? e '_) + (if (and value (or (underscore-symbol? e) (and (pair? e) (or (eq? (car e) 'outerref) (eq? (car e) 'globalref)) - (eq? (cadr e) '_)))) - (syntax-deprecation #f (string "_ as an rvalue" (linenode-string current-loc)) + (underscore-symbol? (cadr e))))) + (syntax-deprecation #f (string "underscores as an rvalue" (linenode-string current-loc)) "")) (if (and (not *warn-all-loop-vars*) (has? deprecated-loop-vars e)) (begin (deprecation-message