The Delphi Bug List

Entry No.
582
Compiler - Can't compile
'Left side cannot be assigned to' with int64 type casted variables.
1.02 2.01 3.0 3.01 3.02 4.0 4.01 4.02 4.03 5.0 5.01 6.0 6.01 6.02 Kylix 1.0
N/AN/AN/AN/AN/AAbsentAbsentAbsentAbsentExistsExistsExistsExistsExistsExists
Description
Reported by Primoz Gabrijelcic
(reposted from borland.public.delphi.objectpascal)
Miha Remec and I stumbled across some int64 incompatibility when trying to compile old code to Delphi 5. This is a minimized version of the problem.
Try to compile that:
{$A+,B-,C+,D+,E-,F-,G+,H+,I+,J+,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}
program int64bug;
{$APPTYPE CONSOLE}
uses sysutils;

type
  Tbug = class
    field: int64;
    constructor Create;
  end;

{ Tbug }

constructor Tbug.Create;
begin
  inherited;
  Int64Rec(field).Lo := 0; // !!!
end;

begin
end.
Delphi reports 'Left side cannot be assigned to' on the marked line. This code works perfectly well in D4. As far as I'm concerned it is perfectly valid, too. Can somebody enlighten me with an explanation?

Even more interesting: if I have a simple global (or local) variable of type int64, compiler does its job good. This compiles correctly, for example:

{$A+,B-,C+,D+,E-,F-,G+,H+,I+,J+,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}

program int64bug;
{$APPTYPE CONSOLE}
uses sysutils;

var
  global: int64;

begin
  Int64Rec(global).Lo := 0;
end.
*BUT* if you complicate the casting enough, compiler eventually dies. This, for example does not work (same error - left side...):
{$A+,B-,C+,D+,E-,F-,G+,H+,I+,J+,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}

program int64bug;
{$APPTYPE CONSOLE}
uses sysutils;

var
  global: int64;

begin
  Int64Rec(int64((@global)^)).Lo := 0;
end.
(additional comment by Robert Lee) ell figured out what I had been seeing before. It's not exactly the same, but I has the same workaround. Also, I poked around in the problem and it does seem quite strange that for instance you can cast a double, which is also 8 bytes, into any like sized structure, but not int64. I think you'll find this amusing as well
TSomeClass=class
  Data:int64;
  ...
end;

...
  int64(Data):=3;
'Left side cannot be signed to' !!! You can't even cast it to itself. OK, it's a bug.
Latest update of this entry: 2002-04-05

Post a comment on this bug


Index page
Delphi Bug List home page
The Delphi Bug Lists are presently maintained by Jordan Russell, who has taken over this task from Reinier Sterkenburg since August 2000.
All feedback is appreciated. See also the feedback section of the Delphi Bug List home page.