Typecasting fails
Bugzilla Link | 1124 |
Created on | Jul 10, 2014 17:57 |
Version | svn |
OS | Linux |
Architecture | PC |
Attachments | , rgb.sac, program.sac |
Extended Description
Here is an experiment: We define a type called rgb in the module called rgb.sac like this: $ cat -n rgb.sac 1 module rgb; 2 3 export all; 4 typedef int[3] rgb; 5 6 int[.] shape (rgb[.,.] a) 7 { 8 return Array::drop ([Array::- 1], Array::shape ((int[.,.,.])a)); 9 } We also define the shape function. Now the main progam looks like this: $ cat -n program.sac 1 use String: {string}; 2 use BMP: all; 3 use rgb: all; 4 5 rgb[.,.] my_readBMP( string name) 6 { 7 img = BMP::readBMP( name); 8 StdIO::print (Color8::shape (img)); 9 b = (int[.,.,.])img; 10 StdIO::print (Array::shape (b)); 11 a = (rgb[.,.])b; 12 StdIO::print (shape (a)); 13 return a; 14 } 15 16 int main() 17 { 18 img = my_readBMP("feedsmall.bmp"); 19 StdIO::print (shape (img)); 20 return 0; 21 } and the output of the program is this: $ ./a.out Dimension: 1 Shape : < 2> <10 10 > Dimension: 1 Shape : < 3> <10 10 3 > Dimension: 1 Shape : < 0> <> Dimension: 1 Shape : < 3> <10 10 22851456 > So, as you can see, the shape information after the typecast to rgb[.,.] type is wrong. If we inline the shape in rgb, the problem goes away. If we introduce object references inside the shape, the problem goes away: int[.] shape (rgb[.,.] a) { sh= Array::drop ([Array::- 1], Array::shape ((int[.,.,.])a)); StdIO::print (sh); return sh; } O_o