Skip to content

Commit e1f26ae

Browse files
committed
deprecate using _ as an rvalue
1 parent 45c1641 commit e1f26ae

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ Language changes
4141
* `isa` is now parsed as an infix operator with the same precedence as `in`
4242
([#19677]).
4343

44+
* The identifier `_` can be assigned, but accessing its value is deprecated,
45+
allowing this syntax to be used in the future for discarding values ([#9343], [#18251]).
46+
4447
Breaking changes
4548
----------------
4649

src/jlfrontend.scm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@
9999
(or (memq (car e) '(toplevel line module import importall using export
100100
error incomplete))
101101
(and (eq? (car e) 'global) (every symbol? (cdr e))))))
102+
(if (eq? e '_)
103+
(syntax-deprecation #f "_ as an rvalue" ""))
102104
e)
103105
(else
104106
(let ((last *in-expand*))

src/julia-syntax.scm

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3293,15 +3293,20 @@ f(x) = yt(x)
32933293
(define (compile e break-labels value tail)
32943294
(if (or (not (pair? e)) (memq (car e) '(null ssavalue quote inert top core copyast the_exception $
32953295
globalref outerref cdecl stdcall fastcall thiscall llvmcall)))
3296-
(let ((e (if (and arg-map (symbol? e))
3297-
(get arg-map e e)
3298-
e)))
3299-
(cond (tail (emit-return e))
3300-
(value e)
3301-
((or (eq? e 'true) (eq? e 'false)) #f)
3302-
((symbol? e) (emit e) #f) ;; keep symbols for undefined-var checking
3303-
((and (pair? e) (eq? (car e) 'outerref)) (emit e) #f) ;; keep globals for undefined-var checking
3304-
((and (pair? e) (eq? (car e) 'globalref)) (emit e) #f) ;; keep globals for undefined-var checking
3296+
(let ((e1 (if (and arg-map (symbol? e))
3297+
(get arg-map e e)
3298+
e)))
3299+
(if (and value (or (eq? e '_)
3300+
(and (pair? e) (or (eq? (car e) 'outerref)
3301+
(eq? (car e) 'globalref))
3302+
(eq? (cadr e) '_))))
3303+
(syntax-deprecation #f "_ as an rvalue" ""))
3304+
(cond (tail (emit-return e1))
3305+
(value e1)
3306+
((or (eq? e1 'true) (eq? e1 'false)) #f)
3307+
((symbol? e1) (emit e1) #f) ;; keep symbols for undefined-var checking
3308+
((and (pair? e1) (eq? (car e1) 'outerref)) (emit e1) #f) ;; keep globals for undefined-var checking
3309+
((and (pair? e1) (eq? (car e1) 'globalref)) (emit e1) #f) ;; keep globals for undefined-var checking
33053310
(else #f)))
33063311
(case (car e)
33073312
((call new foreigncall)

0 commit comments

Comments
 (0)