Skip to content

Commit

Permalink
deprecate assignment inside square bracket expressions
Browse files Browse the repository at this point in the history
for #25631
  • Loading branch information
JeffBezanson committed May 31, 2018
1 parent 8b3849e commit c3ec8db
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ Language changes

* `` (`\dots`) and `` (`\tricolon`) are now parsed as binary operators ([#26262]).

* Assignment syntax inside square bracket expressions (e.g. `A[...]`, `[x, y]`) is
deprecated. It will likely be reclaimed in a later version for passing keyword
arguments ([#25631]).

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

Expand Down
22 changes: 20 additions & 2 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2003,6 +2003,8 @@
(let ((a (cadr lhs))
(idxs (cddr lhs))
(rhs (caddr e)))
(if (any assignment? idxs)
(syntax-deprecation "assignment inside indexing" "" #f))
(let* ((reuse (and (pair? a)
(contains (lambda (x) (eq? x 'end))
idxs)))
Expand Down Expand Up @@ -2061,6 +2063,8 @@
'ref
(lambda (e)
(let ((args (cddr e)))
(if (any assignment? args)
(syntax-deprecation "assignment inside indexing" "" #f))
(if (has-parameters? args)
(error "unexpected semicolon in array expression")
(expand-forms (partially-expand-ref e)))))
Expand All @@ -2069,6 +2073,8 @@
(lambda (e)
(if (has-parameters? (cddr e))
(error (string "unexpected semicolon in \"" (deparse e) "\"")))
(if (any assignment? (cddr e))
(syntax-deprecation "assignment inside T{ }" "" #f))
(let* ((p (extract-implicit-whereparams e))
(curlyparams (car p))
(whereparams (cdr p)))
Expand Down Expand Up @@ -2241,14 +2247,21 @@
(lambda (e)
(if (has-parameters? (cdr e))
(error "unexpected semicolon in array expression"))
(if (any assignment? (cdr e))
(syntax-deprecation "assignment inside [ ]" "" #f))
(expand-forms `(call (top vect) ,@(cdr e))))

'hcat
(lambda (e) (expand-forms `(call (top hcat) ,@(cdr e))))
(lambda (e)
(if (any assignment? (cdr e))
(syntax-deprecation "assignment inside [ ]" "" #f))
(expand-forms `(call (top hcat) ,@(cdr e))))

'vcat
(lambda (e)
(let ((a (cdr e)))
(if (any assignment? a)
(syntax-deprecation "assignment inside [ ]" "" #f))
(if (has-parameters? a)
(error "unexpected semicolon in array expression")
(expand-forms
Expand All @@ -2267,12 +2280,17 @@
`(call (top vcat) ,@a))))))

'typed_hcat
(lambda (e) (expand-forms `(call (top typed_hcat) ,@(cdr e))))
(lambda (e)
(if (any assignment? (cddr e))
(syntax-deprecation "assignment inside T[ ]" "" #f))
(expand-forms `(call (top typed_hcat) ,@(cdr e))))

'typed_vcat
(lambda (e)
(let ((t (cadr e))
(a (cddr e)))
(if (any assignment? (cddr e))
(syntax-deprecation "assignment inside T[ ]" "" #f))
(expand-forms
(if (any (lambda (x)
(and (pair? x) (eq? (car x) 'row)))
Expand Down

0 comments on commit c3ec8db

Please sign in to comment.