slavapestov/factor — Issue #394: buggy behavior on order of dispatch
Author: kenanb
Created: 2011-11-13 01:19:54+00:00
State: open

In this example, the generic word dispatches on p1 instead of t3:

TUPLE: t1 s1 ;
TUPLE: t2 < t1 ;
TUPLE: t3 < t2 ;
PREDICATE: p1 < t1 s1>> ;
GENERIC: foo ( class -- print )
M: t1 foo drop "t1" ;
M: t2 foo drop "t2" ;
M: t3 foo drop "t3" ;
M: p1 foo drop "p1" ;
t3 new t >>s1 foo

! --- Data stack:
! "p1"

\ foo order

! --- Data stack:
! { t1 t2 t3 p1 }
! which probably should have been { t1 p1 t2 t3 } according to precedence rule and metaclass ranking rule combined.

! with a little scruffier structure

TUPLE: t1 s1 ;
TUPLE: t2 < t1 ;
TUPLE: t3 < t2 ;
PREDICATE: p1 < t1 s1>> ;
PREDICATE: p2 < t2 s1>> ;
PREDICATE: p3 < p2 s1>> ;
t1 class-usages sort-classes

! --- Data stack:
! { t1 t2 t3 p2 p3 p1 }
! i expected something like { t1 p1 t2 p2 p3 t3 } or { t1 p1 t2 p2 t3 p3 } I'm not sure.

! with mixins

TUPLE: t1 s1 ;
TUPLE: t2 < t1 ;
TUPLE: t3 < t2 ;
MIXIN: m1
INSTANCE: t2 m1
MIXIN: m2
INSTANCE: t3 m2
t1 class-usages sort-classes

! --- Data stack:
! { t1 m2 m1 t2 t3 }
! i am not sure what was the expected behavior of this, i just wanted to test further. though i think there is a problem with this one, too.

i am not experienced in OOP, but IMHO dispatch order on mixins should be handled specially, probably mixin should be placed in the order dynamically, i.e mixins placed in dispatch order every time according to which instance is of the mixin is making the dispatch predicate on the mixin true. I haven't tested for combinations with other metaclasses. but i can do some if needed.