Skip to content

Commit

Permalink
generate a specific default inner constructor using the field types, in
Browse files Browse the repository at this point in the history
addition to the Any-typed constructor we currently generate.

fixes #7071
  • Loading branch information
JeffBezanson committed Jun 5, 2014
1 parent 20cd5bc commit f20d36d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit f20d36d

Please sign in to comment.