Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread Wrong casting not rejected by the compiler
Thu, Jul 27 2017 5:26 AMPermanent Link

Michael Dreher

I've declared some classes in different units

type
 TCell = class public
   actor  : TObject;
   map : TObject;
 end;
 TActor = class public
   cell  : TCell;
 end;
 TMap = class end;

and made a bug

procedure Move(actor : TActor);
var map : TMap;
begin
 map := Map(actor.cell.map); // <<<---- here

 // shound be...
 map := TMap(actor.cell.map);
and;

It compiles but of course the output isn't something usefull.

  // function main_move(actor)
  // {
     // var map;
     // map = map; // <<<---- here
     // map = actor.cell.map;
  // };

It would be nice if the compiler report an error. Example code in the attachment.
Is there something special about the name "map"? It's syntax highlighted like a keyword.

Michael Dreher



Attachments: Example.zip
Thu, Jul 27 2017 10:44 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Michael,

<< It would be nice if the compiler report an error. Example code in the attachment.  >>

Thanks, I'll check it out.  I've got everything disassembled right now, but I'm doing a new build early next week.

<< Is there something special about the name "map"? It's syntax highlighted like a keyword. >>

Yeah, it was originally supposed to be used for "property expressions" and I never got around to implementing them.  Property expressions are just a shortcut to avoid having to add property getters/setters that simply reference a property in a class instance that is a member variable of the current class.  They basically save the overhead of a function call and allow the compiler to in-line such references.

Tim Young
Elevate Software
www.elevatesoft.com
Image