+2
Planned

Request Warning: class field hides a class field of parent class

Martin Wienold 10 years ago updated by Vincent Parrett 10 years ago 2
I don't know if it possible for FixInsight to detect his, but here is my use case.
I have two classes, TParent and TChild, and a class field in TChild hides a class field defined in TParent.

unit FixInsightTest;

interface

uses
  SysUtils,
  Classes;

type
  TParent = class(TPersistent)
  private
    fPrivate: string;
  protected
    fProtected: string;
  public
    fPublic: string;
  end;

  TChild = class(TParent)
  private
    fPrivate: string;   // this is fine, since it's private for this class
  protected
    fProtected: string; // class field hides class field of parent class
  public
    fPublic: string;    // class field hides class field of parent class
  end;

//
//  Tested with FixInsight 2015.04
//
//  This is somehow related to the warning W517, but this is a special case
//  because the current class' field hides a field of the parent class
//
//    "W517 Variable '%s' hides a class field, method or property"
//

implementation

end.
Would like to see this extended to properties as well.. just had a case where a property and it's backing field was redeclared in a descendant class, both inside a package.. no compiler warnings issues and fix insight didn't find it. Caused a serialization issue (rtti for reading found he base class field, writing the descendant! Doh!).