Skip to content

Commit

Permalink
deprecation warning for old parametric method syntax. fixes #11310
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jul 17, 2017
1 parent ecab331 commit 2316249
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ New language features
Language changes
----------------

* The syntax for parametric methods, `function f{T}(x::T)`, has been
changed to `function f(x::T) where {T}` ([#11310]).

* The syntax `1.+2` is deprecated, since it is ambiguous: it could mean either
`1 .+ 2` (the current meaning) or `1. + 2` ([#19089]).

Expand Down
3 changes: 3 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,9 @@ end

@deprecate String(io::GenericIOBuffer) String(take!(copy(io)))

# issue #11310
# remove "parametric method syntax" deprecation in julia-syntax.scm

# END 0.7 deprecations

# BEGIN 1.0 deprecations
Expand Down
1 change: 1 addition & 0 deletions src/ast.scm
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
(deparse-block (string (car e) " " (deparse (cadr e)))
(block-stmts (caddr e))))
((copyast) (deparse (cadr e)))
((kw) (string (deparse (cadr e)) " = " (deparse (caddr e))))
(else
(string e))))))

Expand Down
19 changes: 13 additions & 6 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -810,14 +810,16 @@
(sig (car temp))
(params (cdr temp)))
(if (pair? params)
(let* ((lnos (filter (lambda (e) (and (pair? e) (eq? (car e) 'line)))
body))
(lno (if (null? lnos) '() (car lnos))))
(syntax-deprecation #f
(string "inner constructor " name "(...)" (linenode-string lno))
(deparse `(where (call (curly ,name ,@params) ...) ,@params)))))
(syntax-deprecation #f
(string "inner constructor " name "(...)" (linenode-string (function-body-lineno body)))
(deparse `(where (call (curly ,name ,@params) ...) ,@params))))
`(,keyword ,sig ,(ctor-body body params)))))))

(define (function-body-lineno body)
(let ((lnos (filter (lambda (e) (and (pair? e) (eq? (car e) 'line)))
body)))
(if (null? lnos) '() (car lnos))))

;; rewrite calls to `new( ... )` to `new` expressions on the appropriate
;; type, determined by the containing constructor definition.
(define (rewrite-ctor ctor Tname params bounds field-names field-types)
Expand Down Expand Up @@ -1062,6 +1064,11 @@
(eq? (caar argl) 'parameters))))))
(name (if (or (decl? name) (and (pair? name) (eq? (car name) 'curly)))
#f name)))
(if has-sp
(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)))))
(expand-forms
(method-def-expr name sparams argl body isstaged rett))))
(else
Expand Down

0 comments on commit 2316249

Please sign in to comment.