#5212 Method chain order not correctly documented

current: 8.6.0
open
5
2013-03-05
2013-03-05
Twylite
No

The method chain order is documented in the 'next' man page as:

---
When constructing the method chain, method implementations are searched for in the following order:
In the object.
In the classes mixed into the object, in class traversal order. The list of mixins is checked in natural order.
In the classes mixed into the classes of the object, with sources of mixing in being searched in class traversal order. Within each class, the list of mixins is processed in natural order.
In the object's class.
In the superclasses of the class, following each superclass in a depth-first fashion in the natural order of the superclass list.
Any particular method implementation always comes as late in the resulting list of implementations as possible.
---

The following code appears to contradict the documentation:

---
oo::define oo::class method m {} { puts [self class]; next }
oo::define oo::object method m {} { puts [self class]; next }
oo::class create SuperObjMix { method m {} { puts [self class]; next } }
oo::class create ObjMix { superclass SuperObjMix ; method m {} { puts [self class]; next } }
oo::class create ClsMix { method m {} { puts [self class]; next } }
oo::class create SuperMix { method m {} { puts [self class]; next } }
oo::class create Mix { superclass SuperMix ; method m {} { puts [self class]; next } }
oo::class create Super { method m {} { puts [self class]; next } }
oo::class create OtherSuper { mixin Mix ; method m {} { puts [self class]; next } }
oo::class create MyClass { mixin ClsMix ; superclass Super OtherSuper; method m {} { puts [self class]; next } }
MyClass create myclass
oo::objdefine myclass mixin ObjMix
oo::objdefine myclass method m {} { puts [self]; next }
myclass m
---

Output:
---
::ObjMix
::SuperObjMix
::myclass
::ClsMix
::MyClass
::Super
::Mix
::SuperMix
::OtherSuper
::oo::object
no next method implementation
---

I haven't checked the Tcl code, but the method chain appears to be better described as follows:

---
# - In the classes mixed into the object. The list of mixins is checked
# in natural order; each mixin (and its mixins and superclasses) is
# checked in class traversal order.
# - In the object itself.
# - In the object's class and superclasses - and their mixins - in class
# traversal order.
#
# Class traversal order: for each class:
# - The list of mixins to the class is checked in natural order; each
# mixin (and its mixins and superclasses) is checked in class
# traversal order (depth-first).
# - The class itself.
# - The list of superclasses to the class is checked in natural order;
# each superclass (and its mixins and superclasses) is checked in
# class traversal order (depth-first).
# Each class/object is places as late in the resulting list as possible.
---

Discussion