Opened 9 years ago

Closed 9 years ago

#853 closed defect (worksforme)

coops: redefining things breaks methods

Reported by: megane Owned by: felix winkelmann
Priority: minor Milestone:
Component: extensions Version: 4.7.x
Keywords: Cc:
Estimated difficulty:

Description

Tested with Version 4.7.5 (rev 5fe91ae)

;;; This works as supposed:

(require-extension coops)
(define-class <a>)
 (define-method (foo (i <a>))
   (print "foo v1"))

(define obj (make <a>))
(foo obj)

(define-class <a>)
 (define-method (foo (i <a>))
   (print "foo v2"))

(foo obj)

;; Output:
;; foo v1
;; foo v1 <- this is OK

;; Now, same with modules:

(module a
 *
 (import chicken scheme)
 (use coops)
 (define-class <a>)
 (define-method (foo (i <a>))
   (print "foo v1"))
 )

(import a)

(define obj (make <a>))
(foo obj)

(module a
 *
 (import chicken scheme)
 (use coops)
 (define-class <a>)
 (define-method (foo (i <a>))
   (print "foo v2"))
 )

(import a) ;; <- commenting this doesn't matter
;; Also, using different name altogether for the second module doesn't matter

(foo obj)

;; Output:
;; foo v1
;; Error: (foo) no method defined for given argument classes: (#<coops standard-class `<a>'>)

Change History (4)

comment:1 Changed 9 years ago by felix winkelmann

Milestone: 4.8.0

comment:2 Changed 9 years ago by felix winkelmann

Owner: set to felix winkelmann
Status: newassigned

comment:3 Changed 9 years ago by sjamaan

We discussed this on IRC, and I think we came to the conclusion that this is expected (if somewhat unfortunate) behavior. The classes might have the same name and be from the same module, but the class objects are entirely unrelated and don't know about eachother's existence.

If you rename the second module to b, and don't import it, it works. If you rename but DO import, the class is redefined and the obj is of the old class. The new foo procedure you defined in the second module overwrites the foo procedure defined in the first module instead of extending the earlier generic procedure. If module a is imported in b, it will extend properly.

If y'all agree this is not a bug, please close the ticket.

comment:4 Changed 9 years ago by felix winkelmann

Resolution: worksforme
Status: assignedclosed
Note: See TracTickets for help on using tickets.