[chuck-users] bug on virtuality
eduard aylon
eduard.aylon at gmail.com
Sat Oct 18 17:48:32 EDT 2008
Dear list,
today I came across some (I believe) inconsistency related to virtual
parent classes. The following code exemplifies such bug.
There are three types of classes:
Point -> in principle purely virtual
Point2D and Point3D -> inherit from Point
Point2D and Point3D need to be of the same parental type, so valid
functions for both of them can be written in a single definition. See
coordinates(Point p) and coordinates(Point p[]). The chuck interpreter
complains when passing an array of Point2D or Point3D to the second
function, claiming there is a type mismatch. In my opinion this should
not happen. What do you think?
eudard
public class Point
{
// virtual class
fun void set(int x, int y){}
fun void print(){}
}
class Point2D extends Point
{
int _x;
int _y;
fun void set(int x, int y)
{
x => _x;
y => _y;
}
fun void print() { <<< _x, _y >>>; }
}
class Point3D extends Point
{
int _x;
int _y;
int _z;
fun void set(int x, int y, int z)
{
x => _x;
y => _y;
z => _z;
}
fun void print() { <<< _x, _y, _z >>>; }
}
fun void coordinates(Point p)
{
p.print();
}
fun void coordinates(Point p[])
{
for (int i; i < p.size(); i++) p[i].print();
}
Point2D p2d;
Point3D p3d;
Point2D p2d_array[2];
Point3D p3d_array[2];
// this works:
coordinates(p2d);
coordinates(p3d);
// this doesn't work
// reason might be due to passing arrays
coordinates(p2d_array);
coordinates(p3d_array);
More information about the chuck-users
mailing list