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);
eduard; What do you think?
I tried a few things but I'm a bit stuck here as well. Right now, unless I'm very mistaken, this looks to me like it's indeed wrong and another expression of something being wrong in the type-system where arrays are concerned. Here in particular array types don't seem respect extending of classes, type-wise. I Hacked up your class structure for a bit, having Point1D extend Point and Point2D extend Point1D, etc but that didn't help. I ended up writing a small trivial test case. I feel this should work, it should print a series of 3 zeros.... yet it doesn't; //==================-8<======================- class bar { int value; } class baz extends bar { } baz foo[3]; fun void print( bar p[]) { for(0 => int n; n
participants (2)
-
eduard aylon
-
Kassen