Skip to content

Commit

Permalink
fix JuliaLang#23010, method parameter deprecation warning fixes
Browse files Browse the repository at this point in the history
also some general improvements to the scheme `deparse` function
  • Loading branch information
JeffBezanson committed Jul 28, 2017
1 parent fc10c8b commit f600cdc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
35 changes: 29 additions & 6 deletions src/ast.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

;; deparser

(define (deparse-arglist l (sep ",")) (string.join (map deparse l) sep))
(define (deparse-arglist l (sep ", "))
(if (has-parameters? l)
(string (string.join (map deparse (cdr l)) sep)
"; "
(string.join (map deparse (cdar l)) ", "))
(string.join (map deparse l) sep)))

(define (deparse e)
(define (block-stmts e)
Expand Down Expand Up @@ -60,11 +65,25 @@
(string ":" (deparse (cadr e)))
(string ":(" (deparse (cadr e)) ")")))
((vect) (string #\[ (deparse-arglist (cdr e)) #\]))
((vcat) (string #\[ (deparse-arglist (cdr e) ";") #\]))
((hcat) (string #\[ (deparse-arglist (cdr e) " ") #\]))
((row) (deparse-arglist (cdr e) " "))
((vcat)
(string #\[
;; note: this is a parser quasi-bug; arguably `[a,b;c]` should
;; be a `vect` expression with parameters, not `vcat`
(deparse-arglist (cdr e) (if (has-parameters? (cdr e))
", " "; "))
#\]))
((typed_vcat) (string (deparse (cadr e))
(deparse (cons 'vcat (cddr e)))))
((hcat) (string #\[ (deparse-arglist (cdr e) " ") #\]))
((typed_hcat) (string (deparse (cadr e))
(deparse (cons 'hcat (cddr e)))))
((row) (deparse-arglist (cdr e) " "))
((braces) (string #\{ (deparse-arglist (cdr e)) #\}))
((bracescat) (string #\{ (deparse-arglist (cdr e) ";") #\}))
((bracescat)
(string #\{
(deparse-arglist (cdr e) (if (has-parameters? (cdr e))
", " "; "))
#\}))
((const) (string "const " (deparse (cadr e))))
((global local)
(string (car e) " " (string.join (map deparse (cdr e)) ", ")))
Expand All @@ -86,7 +105,11 @@
((block)
(deparse-block "begin" (cdr e)))
((comprehension)
(string "[ " (deparse (cadr e)) " for " (deparse-arglist (cddr e) ", ") " ]"))
(let ((e (cadr e)))
(string "[ " (deparse (cadr e)) " for " (deparse-arglist (cddr e) ", ") " ]")))
((typed_comprehension)
(string (deparse (cadr e))
(deparse (cons 'comprehension (cddr e)))))
((generator)
(string "(" (deparse (cadr e)) " for " (deparse-arglist (cddr e) ", ") ")"))
((where)
Expand Down
12 changes: 8 additions & 4 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1038,9 +1038,10 @@
(if (nospecialize-meta? a) (caddr a) a))
argl))
(argl (if op (cons `(|::| (call (core Typeof) ,op)) argl) argl))
(sparams (map analyze-typevar (cond (has-sp (cddr head))
(where where)
(else '()))))
(raw-typevars (cond (has-sp (cddr head))
(where where)
(else '())))
(sparams (map analyze-typevar raw-typevars))
(isstaged (eq? (car e) 'stagedfunction))
(adj-decl (lambda (n) (if (and (decl? n) (length= n 2))
`(|::| |#self#| ,(cadr n))
Expand All @@ -1060,7 +1061,10 @@
(syntax-deprecation #f
(string "parametric method syntax " (deparse (cadr e))
(linenode-string (function-body-lineno body)))
(deparse `(where (call ,name ,@(cdr argl)) ,@(map car sparams)))))
(deparse `(where (call ,name ,@(if (has-parameters? argl)
(cons (car argl) (cddr argl))
(cdr argl)))
,@raw-typevars))))
(expand-forms
(method-def-expr name sparams argl body isstaged rett))))
(else
Expand Down
2 changes: 1 addition & 1 deletion test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ for op in ["+", "-", "\$", "|", ".+", ".-", "*", ".*"]
end

# issue #17701
@test expand(Main, :(i==3 && i+=1)) == Expr(:error, "invalid assignment location \"==(i,3) && i\"")
@test expand(Main, :(i==3 && i+=1)) == Expr(:error, "invalid assignment location \"==(i, 3) && i\"")

# issue #18667
@test expand(Main, :(true = 1)) == Expr(:error, "invalid assignment location \"true\"")
Expand Down

0 comments on commit f600cdc

Please sign in to comment.