[Lazarus] Bug in MY code. fpc 3.0.0 did NOT detect - leads to strange error.

Donald Ziesig donald at ziesig.org
Fri Feb 12 15:45:26 CET 2016


Hi All!

After a multi-day debugging binge, I found the problem described in my 
previous email.

Quick summary:

Common Library has a unit which defines a generic class that itself is 
derived from a class from another unit of the same library.

Application Library has many units which specialize the generic class.

Compiling the Application LIbrary causes a "File not found" error giving 
the name of a valid file (the one declaring the generic) but in an 
incorrect directory,  There is no indication of where the failure 
(file:line no) occurs.  There is no sign of the file where the error 
message says it is (that part is correct, but why it happens is not).

A long series of tests determined that the error occurs in all files 
that specialize the generic class.  I had not touched the file declaring 
the generic class in years.

The bug in my code was in the Common Library unit that declared the 
class from which the generic class was derived.  FPC 3.0.0 did not 
detect the following error in the class declaration:

     class function Load( TextIO : TTextIO; aParent : TPersists = nil ) 
: TPersists; virtual; overload; // Calls read afterwards

     procedure Load( TextIO : TTextIO ); overload; // Loads without 
creating *<<< this was newly added and caused the p**roblem. fpc did not 
object!

*This module is many years old. I know now that the class function could 
have been replaced by a constructor, but that would require refactoring 
many working programs.

I added the procedure recently to simplify a lot of application code 
(which it did).  It had been working without the error for a few days.  
I don't know what I did to trigger the failure, but once I did it would 
not go away (that in itself is problematic, I would have expected the 
failure right after I introduced the bug).

The first instance of the error occurred using Lazarus 1.7/fpc 3.0.0 on 
Raspbian.  During the bug hunt, I copied the code to my laptop where it 
occurred using Lazarus 1.6RC2/fpc 3.0.0 on Linux Mint 17.3.

When I changed the code to:

     class function Load( TextIO : TTextIO; aParent : TPersists = nil ) 
: TPersists; virtual; // Calls read afterwards

     procedure LoadExisting( TextIO : TTextIO );  // Loads without creating

and refactored, the errors disappeared and the recursion tests worked.

I believe this is a Compiler bug so I will post a bug report for fpc 
over the weekend.

Comments will be appreciated.

Don Ziesig


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160212/aba766ac/attachment-0002.html>


More information about the Lazarus mailing list