From f20d36d18fe1394c2426f199b59074f80d7186bb Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Thu, 5 Jun 2014 01:15:38 -0400 Subject: [PATCH] generate a specific default inner constructor using the field types, in addition to the Any-typed constructor we currently generate. fixes #7071 --- NEWS.md | 6 ++++-- src/julia-syntax.scm | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/NEWS.md b/NEWS.md index 5f36cd9cd042a..6886906426596 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,8 +9,9 @@ New language features * `Tuple`s (of `Integer`s, `Symbol`s, or `Bool`s) can now be used as type parameters ([#5164]). - * Default "inner" constructors now accept any arguments. Constructors that - look like `MyType(a, b) = new(a, b)` can and should be removed ([#4026]). + * An additional default "inner" constructor accepting any arguments is now + generated. Constructors that look like `MyType(a, b) = new(a, b)` do not + need to be added manually ([#4026], [#7071]). * Expanded array type hierarchy to include an abstract ``DenseArray`` for in-memory arrays with standard strided storage ([#987], [#2345], @@ -360,6 +361,7 @@ Deprecated or removed [#4042]: https://github.com/JuliaLang/julia/issues/4042 [#5164]: https://github.com/JuliaLang/julia/issues/5164 [#4026]: https://github.com/JuliaLang/julia/issues/4026 +[#7071]: https://github.com/JuliaLang/julia/issues/7071 [#4799]: https://github.com/JuliaLang/julia/issues/4799 [#4862]: https://github.com/JuliaLang/julia/issues/4862 [#4048]: https://github.com/JuliaLang/julia/issues/4048 diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 47efcb66cfa7e..35a5ecb5c42a7 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -715,11 +715,18 @@ (map (lambda (x) (gensy)) field-names) field-names)) -(define (default-inner-ctor name field-names field-types) +(define (default-inner-ctors name field-names field-types) (let ((field-names (safe-field-names field-names field-types))) - `(function (call ,name ,@field-names) - (block - (call new ,@field-names))))) + (list + ;; definition with field types for all arguments + `(function (call ,name + ,@(map make-decl field-names field-types)) + (block + (call new ,@field-names))) + ;; definition with Any for all arguments + `(function (call ,name ,@field-names) + (block + (call new ,@field-names)))))) (define (default-outer-ctor name field-names field-types params bounds) (let ((field-names (safe-field-names field-names field-types))) @@ -810,7 +817,7 @@ (field-names (map decl-var fields)) (field-types (map decl-type fields)) (defs2 (if (null? defs) - (list (default-inner-ctor name field-names field-types)) + (default-inner-ctors name field-names field-types) defs))) (for-each (lambda (v) (if (not (symbol? v))