|
751 | 751 |
|
752 | 752 | (define (default-inner-ctors name field-names field-types params bounds locs) |
753 | 753 | (let* ((field-names (safe-field-names field-names field-types)) |
754 | | - (any-ctor |
| 754 | + (all-ctor (if (null? params) |
| 755 | + ;; definition with exact types for all arguments |
| 756 | + `(function (call ,name |
| 757 | + ,@(map make-decl field-names field-types)) |
| 758 | + (block |
| 759 | + ,@locs |
| 760 | + (new (outerref ,name) ,@field-names))) |
| 761 | + #f)) |
| 762 | + (any-ctor (if (or (not all-ctor) (any (lambda (t) (not (equal? t '(core Any)))) |
| 763 | + field-types)) |
755 | 764 | ;; definition with Any for all arguments |
| 765 | + ;; only if any field type is not Any, checked at runtime |
756 | 766 | `(function (call (|::| |#ctor-self#| |
757 | 767 | ,(with-wheres |
758 | 768 | `(curly (core Type) ,(if (pair? params) |
|
762 | 772 | ,@field-names) |
763 | 773 | (block |
764 | 774 | ,@locs |
765 | | - (call new ,@field-names))))) |
766 | | - (if (and (null? params) (any (lambda (t) (not (equal? t '(core Any)))) |
767 | | - field-types)) |
768 | | - (list |
769 | | - ;; definition with field types for all arguments |
770 | | - ;; only if any field type is not Any, checked at runtime |
771 | | - `(if ,(foldl (lambda (t u) |
772 | | - `(&& ,u (call (core ===) (core Any) ,t))) |
773 | | - `(call (core ===) (core Any) ,(car field-types)) |
774 | | - (cdr field-types)) |
775 | | - (block) |
776 | | - (function (call ,name |
777 | | - ,@(map make-decl field-names field-types)) |
778 | | - (block |
779 | | - ,@locs |
780 | | - (new (outerref ,name) ,@field-names)))) |
781 | | - any-ctor) |
| 775 | + (call new ,@field-names))) ; this will add convert calls later |
| 776 | + #f))) |
| 777 | + (if all-ctor |
| 778 | + (if any-ctor |
| 779 | + (list all-ctor |
| 780 | + `(if ,(foldl (lambda (t u) |
| 781 | + `(&& ,u (call (core ===) (core Any) ,t))) |
| 782 | + `(call (core ===) (core Any) ,(car field-types)) |
| 783 | + (cdr field-types)) |
| 784 | + '(block) |
| 785 | + ,any-ctor)) |
| 786 | + (list all-ctor)) |
782 | 787 | (list any-ctor)))) |
783 | 788 |
|
784 | 789 | (define (default-outer-ctor name field-names field-types params bounds locs) |
|
0 commit comments