6.5. Overloading

There are two aspects to the use of overloading in a parametrized class - one aspect is the behavior of the interface of the parametrized class itself, and the other aspect is calls within the parametrized class where one or more arguments have the type of one of the type parameters, or is related to the type parameters through static type inference (see .

6.5.1. Overloading In the Parametrized Class Interface

Argument with the type of a class parameter cannot be used to resolve overloading (such an argument is similar to an 'out' argument or a return type in this respect).
class FOO{T1<$STR ,T2<$ELT} is
   bar(a:T1);  -- (1)
   bar(a:T2);  -- (2)

Even though the type bounds for T1 and T2 are distinct and one is more specific than the other, this is not a sufficient constraint on the actual instantiation of the parameter. In a class such as


for instance, the two versions of 'bar' will essentially be identical.

6.5.2. Overloading Resolution within the Parametrized Class

Note: The current ICSI compiler does not yet have this behaviour implemented. In the current compiler, overloading resolution is based on the actual instantiated class.

For all calls within the parametrized class, the resolution of overloading is done with respect to the type bounds of the parameters. Consider a class that makes use of output streams
abstract class $OSTREAM is

A parametrized class can then write to any output stream
class FOO{S < $OSTREAM} is
   attr x,y:INT;

   describe(s:S) is
      s + "Self is:";
      s + x;
      s + ",";
      s + y;

Now, suppose we instantiate the class FOO with a FILE
class FILE < $OSTREAM is
   plus(s:$STR) is ... -- (1)
   plus(s:INT) is ...  -- (2)

a:FOO{FILE} := ..
f:FILE := FILE::open_for_read("myfile");

Only '(1) plus($STR)' will be called in FOO{FILE}, even though the more specific '(2) plus(INT)' is available in FILE.

The reason for this behavior is to preseve the ability to analyze a stand alone class, which is needed for separate compilation of parametrized classes - this requires that the behavior of the parametrized class be completely determined by the typebounds and not based on the existance of specialized overloaded routines in particular instantiations.