View Issue Details

IDProjectCategoryView StatusLast Update
0035866FPCCompilerpublic2019-07-20 21:49
ReporterThaddy de KoningAssigned ToSven Barth 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformarmhfOSRaspbianOS VersionStretch
Product Version3.3.1Product Build42454 
Target VersionFixed in Version3.3.1 
Summary0035866: Attributes: Internal error 2019070601
DescriptionWhile testing the new attributes feature I ran into Internal error 2019070601
There maybe something wrong with my assumptions (see code below) since I am not yet experienced enough with this feature, but it should not throw an internal error.
Steps To Reproduceprogram testattributes;
{$mode delphi}{$warn 5079 off} // turn warning experimental off
uses
  sysutils, dateutils, typinfo, rtti, classes;
  
type
{$M+}
   TDateTimeAttribute = class(TCustomAttribute)
   private
     FArg:TDateTime;
   public
     constructor Create(aArg: String);overload;
     constructor Create(aArg: TDateTime);overload;
     constructor Create(aArg: int64);overload;
     property DateTime:TDateTime read Farg;
   end;
  
   [TDateTimeAttribute]
   TMyDateTimeClass = class
   private
     FDateTime:TDateTime;
   published
     [TDateTimeAttribute(Now)]
     property DateTime:TDateTime;
   end;

   constructor TDateTimeAttribute.Create(aArg: String);
   begin
     inherited create;
     FArg := StrToDateTime(aArg);
   end;
   
   constructor TDateTimeAttribute.Create(aArg: TDateTime);
   begin
     FArg := aArg;
   end;
   
   constructor TDateTimeAttribute.Create(aArg: int64);
   begin
     FArg := UnixToDateTime(aArg);
   end;
   
   
var
  Test:TMyDateTimeClass;
begin
  Test := TMyDateTimeClass.Create;
  try
    writeln(DateTimeToStr(Test.DateTime));
  finally
    test.free;
  end;
end.
Additional InformationI was trying to unify datetime initialization.
TagsNo tags attached.
Fixed in Revision42469
FPCOldBugId
FPCTarget-
Attached Files

Activities

Sven Barth

2019-07-20 21:49

manager   ~0117331

Multiple points:
- main problem: the arguments for an attribute *must* be constant expressions (though I thought the compiler would check this already the way I implemented it, but seems that I was wrong; this is fixed now)
- something I noticed only now when checking with Delphi: if you want to use an attribute without any arguments then you *must* declare a parameterless constructor yourself (I have yet to fix this)
- you missed a "read FDateTime" in the declaration of TMyDateTimeClass.DateTime

Issue History

Date Modified Username Field Change
2019-07-20 19:55 Thaddy de Koning New Issue
2019-07-20 21:49 Sven Barth Assigned To => Sven Barth
2019-07-20 21:49 Sven Barth Status new => resolved
2019-07-20 21:49 Sven Barth Resolution open => fixed
2019-07-20 21:49 Sven Barth Fixed in Version => 3.3.1
2019-07-20 21:49 Sven Barth Fixed in Revision => 42469
2019-07-20 21:49 Sven Barth FPCTarget => -
2019-07-20 21:49 Sven Barth Note Added: 0117331