From: Mark Wooding Date: Tue, 17 Nov 2015 17:23:18 +0000 (+0000) Subject: src/method-aggregate.lisp: New protocol for method return types. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/sod/commitdiff_plain/64a6094b97647f25abc49a792451ed54c83741ed?ds=inline src/method-aggregate.lisp: New protocol for method return types. Rather than assume that primary methods should always return the same type as the message, introduce protocol for the method combination to decide which return type it wants. --- diff --git a/src/method-aggregate.lisp b/src/method-aggregate.lisp index 155ccb7..37454f8 100644 --- a/src/method-aggregate.lisp +++ b/src/method-aggregate.lisp @@ -96,6 +96,12 @@ (defgeneric check-aggregating-message-type (message combination type) (:method (message combination type) t)) +(defgeneric aggregating-message-method-return-type (message combination) + (:documentation + "Return the primary method return type for this MESSAGE and COMBINATION.") + (:method ((message aggregating-message) (combination t)) + (c-type-subtype (sod-message-type message)))) + (export 'aggregating-effective-method) (defclass aggregating-effective-method (simple-effective-method) () (:documentation "Effective method counterpart to `aggregating-message'.")) @@ -173,6 +179,19 @@ (defmethod shared-initialize :before arg-names plist))))))) +(defmethod check-method-type + ((method sod-method) (message aggregating-message) + (type c-function-type)) + (let ((wanted (aggregating-message-method-return-type + message (sod-message-combination message))) + (msgtype (sod-message-type message))) + (unless (c-type-equal-p (c-type-subtype type) wanted) + (error "Method return type ~A doesn't match message ~A" + (c-type-subtype msgtype) (c-type-subtype type))) + (unless (argument-lists-compatible-p (c-function-arguments msgtype) + (c-function-arguments type)) + (error "Method arguments ~A don't match message ~A" type msgtype)))) + ;;;-------------------------------------------------------------------------- ;;; Utilities.