Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deprecate using _ as an rvalue
Browse files Browse the repository at this point in the history
JeffBezanson committed Jan 30, 2017
1 parent 45c1641 commit e1f26ae
Showing 3 changed files with 19 additions and 9 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -41,6 +41,9 @@ Language changes
* `isa` is now parsed as an infix operator with the same precedence as `in`
([#19677]).

* The identifier `_` can be assigned, but accessing its value is deprecated,
allowing this syntax to be used in the future for discarding values ([#9343], [#18251]).

Breaking changes
----------------

2 changes: 2 additions & 0 deletions src/jlfrontend.scm
Original file line number Diff line number Diff line change
@@ -99,6 +99,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" ""))
e)
(else
(let ((last *in-expand*))
23 changes: 14 additions & 9 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
@@ -3293,15 +3293,20 @@ f(x) = yt(x)
(define (compile e break-labels value tail)
(if (or (not (pair? e)) (memq (car e) '(null ssavalue quote inert top core copyast the_exception $
globalref outerref cdecl stdcall fastcall thiscall llvmcall)))
(let ((e (if (and arg-map (symbol? e))
(get arg-map e e)
e)))
(cond (tail (emit-return e))
(value e)
((or (eq? e 'true) (eq? e 'false)) #f)
((symbol? e) (emit e) #f) ;; keep symbols for undefined-var checking
((and (pair? e) (eq? (car e) 'outerref)) (emit e) #f) ;; keep globals for undefined-var checking
((and (pair? e) (eq? (car e) 'globalref)) (emit e) #f) ;; keep globals for undefined-var checking
(let ((e1 (if (and arg-map (symbol? e))
(get arg-map e e)
e)))
(if (and value (or (eq? e '_)
(and (pair? e) (or (eq? (car e) 'outerref)
(eq? (car e) 'globalref))
(eq? (cadr e) '_))))
(syntax-deprecation #f "_ as an rvalue" ""))
(cond (tail (emit-return e1))
(value e1)
((or (eq? e1 'true) (eq? e1 'false)) #f)
((symbol? e1) (emit e1) #f) ;; keep symbols for undefined-var checking
((and (pair? e1) (eq? (car e1) 'outerref)) (emit e1) #f) ;; keep globals for undefined-var checking
((and (pair? e1) (eq? (car e1) 'globalref)) (emit e1) #f) ;; keep globals for undefined-var checking
(else #f)))
(case (car e)
((call new foreigncall)

0 comments on commit e1f26ae

Please sign in to comment.