diff --git a/NEWS.md b/NEWS.md index 682c9674fd12b..c7cf697ff6ad0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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]). diff --git a/base/deprecated.jl b/base/deprecated.jl index f7ef5e84563d4..a4d587cb60f87 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1591,6 +1591,9 @@ end @deprecate readstring(filename::AbstractString) read(filename, String) @deprecate readstring(cmd::AbstractCmd) read(cmd, String) +# issue #11310 +# remove "parametric method syntax" deprecation in julia-syntax.scm + @deprecate momenttype(::Type{T}) where {T} typeof((zero(T)*zero(T) + zero(T)*zero(T))/2) false # END 0.7 deprecations diff --git a/src/ast.scm b/src/ast.scm index 0023531f04337..638c323f29cc5 100644 --- a/src/ast.scm +++ b/src/ast.scm @@ -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)))))) diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 09fff6029571a..8ba5551c8cca3 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -802,14 +802,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) @@ -1054,6 +1056,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