bloks@eba.eb.ele.tue.nl (rudi_bloks) (01/09/91)
Hi, Last week i have discovered a bug in the THINK Pascal 3.01 compiler. It is illustrated by the following program, which is the simplest piece of code i could make that actually forces the bug to show itself. The bug only appears when classes are used with methods that return Point Types. (I haven't checked with any other 'complex' types). program test; type oPt = object pt1, pt2: Point; { a class maintaining two Points } procedure Init; function GetPoint1: Point; function GetPoint2: Point; function GetDiff: Point; end; var { some global variables } x: oPt; tp: Point; procedure oPt.Init; { initialize instance variables } begin SetPt(pt1, 5, 7); SetPt(pt2, 4, 8); end; function oPt.GetPoint1: Point; { return one of the instance variables } begin GetPoint1 := pt1; end; function oPt.GetPoint2: Point; { return the other instance variable } begin GetPoint2 := pt2; end; function oPt.GetDiff: Point; { return the difference as a Point } var q: Point; begin SetPt(q, pt2.h - GetPoint1.h, pt2.v - GetPoint1.v); { *** BUG HERE *** } GetDiff := q; end; begin ShowText; new(x); { make an object and initialize it } x.Init; tp := x.GetPoint1; { show first point for verification } writeln(tp.h, tp.v); tp := x.GetPoint2; { show second point for verification } writeln(tp.h, tp.v); { show difference between points by computing it here } writeln(x.GetPoint2.h - x.GetPoint1.h, x.GetPoint2.v - x.GetPoint1.v); { show difference between points by having object compute it } writeln(x.GetDiff.h, x.GetDiff.v); dispose(x); end. The above program will give the following results: 5 7 *correct* 4 8 *correct* -1 1 *correct* -1 3 *NOT CORRECT* It seems that the GetPoint1.v call in the method GetDiff is actually compiled into GetPoint1.h I have encountered this bug in several places in a program i am writing. Has anybody else experienced similar bugs? -- or am i just missing some undocumented feature? -- Rudi email bloks@eb.ele.tue.nl