View Issue Details

IDProjectCategoryView StatusLast Update
0034691FPCCompilerpublic2018-12-26 12:26
ReporterPavol SAssigned ToSven Barth 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product VersionProduct Build 
Target VersionFixed in Version3.3.1 
Summary0034691: Internal error 200402171 when publishing property from object
Description  TObjA = class
    Icon: String;
  end;

  TObjB = class
    FObjA: TObjA;

  published
    property Icon: String read FObjA.Icon;
  end;

Code work's only when property is placed under "public" section.
TagsNo tags attached.
Fixed in Revision40646
FPCOldBugId
FPCTarget
Attached Files

Activities

Thaddy de Koning

2018-12-15 17:16

reporter   ~0112587

The internal error is a bug indeed, but your code also contains a bug:

Published properties need a class derived from Tpersistent, not from TObject.

So your code should look like this:
 TObjA = class(Tpersistent)
    Icon: String;
  end;

  TObjB = class(Tpersistent)
    FObjA: TObjA;

  published
    property Icon: String read FObjA.Icon;
  end;

Alternatively you can compile your classes explicitly in the {$M+} state.
{$push}{$M+}
 TObjA = class
    Icon: String;
  end;

  TObjB = class
    FObjA: TObjA;

  published
    property Icon: String read FObjA.Icon;
  end;
{$pop}

Martok

2018-12-15 17:35

reporter   ~0112588

Last edited: 2018-12-15 17:35

View 2 revisions

The code should be perfectly fine in mode Delphi.

If FPC needs explicit $M+, it's an incompatibility. In Delphi, having a published section implies RTTI for that class.
See http://docwiki.embarcadero.com/RADStudio/en/W1055_Published_caused_RTTI_($M%2B)_to_be_added_to_type_'%25s'_(Delphi)

Thaddy de Koning

2018-12-15 17:35

reporter   ~0112589

Ah I see: even that does not work. Confirmed, also in trunk from today.

With some fixes I got it working. It seems related to the missing constructor:
This works.
{$mode delphi}{$H+}
uses classes;
type
{$M+}
 TObjA = class
 public
    Icon: String;
 end;

  TObjB = class(Tpersistent)
  private
    FObjA: TObjA;
  protected
    function GetIcon:String;
  public
    constructor Create;
  published
    property Icon: String read GetIcon;
  end;
  
  function TObjB.GetIcon:String;
  begin
    Result := FObjA.Icon;
  end;
  
  constructor TObjB.Create;
  begin
    inherited;
    FObjA := TObjA.Create;
  end;

begin
end.

Thaddy de Koning

2018-12-15 17:38

reporter   ~0112590

Last edited: 2018-12-15 17:40

View 2 revisions

Martok, yes the code is fine, but it throws the internal error in any mode.
BTW if Tobject published doesn't require Tpersistent anymore that is from a later than XE2 version.

Martok

2018-12-15 17:45

reporter   ~0112591

Last edited: 2018-12-15 17:50

View 2 revisions

You wrote "[...], but your code also contains a bug:". That is not true.
And in fact FPC handles it correctly, it just prints no message.

"BTW if Tobject published doesn't require Tpersistent anymore that is from a later than XE2 version."
It never did. The earliest I have installed is 7, but I remember 4 also having no problem with that.

Also, the constructor has absolutely nothing to do with anything. You replaced a field reference with a getter method. This is different code.

Sven Barth

2018-12-25 21:42

manager   ~0112876

@Pavol S: If you want to use a nested field accessor (the "FObjA.Icon") then "FObjA" *must* be a record or TP style object (same is true in Delphi) - of course the compiler should complain here instead of triggering an internal error.

@Martok: Newer Delphi versions added the ability to implicitely enable $M if "published" is encountered. FPC does not (yet).

@Thaddy: TPersistent is no special class as far as the compiler is concerned. It simply checks for $M (and yes, that's also true for older Delphi versions).

Sven Barth

2018-12-26 12:26

manager   ~0112886

The compiler now fails gracefully in that situation.

Please test and close if okay.

Issue History

Date Modified Username Field Change
2018-12-12 09:45 Pavol S New Issue
2018-12-12 11:20 Juha Manninen Project Lazarus => FPC
2018-12-15 17:16 Thaddy de Koning Note Added: 0112587
2018-12-15 17:35 Martok Note Added: 0112588
2018-12-15 17:35 Thaddy de Koning Note Added: 0112589
2018-12-15 17:35 Martok Note Edited: 0112588 View Revisions
2018-12-15 17:38 Thaddy de Koning Note Added: 0112590
2018-12-15 17:40 Thaddy de Koning Note Edited: 0112590 View Revisions
2018-12-15 17:45 Martok Note Added: 0112591
2018-12-15 17:50 Martok Note Edited: 0112591 View Revisions
2018-12-25 21:42 Sven Barth Note Added: 0112876
2018-12-25 21:43 Sven Barth Status new => confirmed
2018-12-26 12:26 Sven Barth Fixed in Revision => 40646
2018-12-26 12:26 Sven Barth Note Added: 0112886
2018-12-26 12:26 Sven Barth Status confirmed => resolved
2018-12-26 12:26 Sven Barth Fixed in Version => 3.3.1
2018-12-26 12:26 Sven Barth Resolution open => fixed
2018-12-26 12:26 Sven Barth Assigned To => Sven Barth