SRL Archive - Lape

pointer bug


riwu

2014-08-25 07:16:03


Procedure Pointer.Inc(Size: Int64);
Begin
writeln('Pointer.Inc() called');
Self := Self + Size;
End;


procedure TMufasaBitmap.DrawTPA(tpa: TPointArray; Colour: Integer); override;
var
c: Integer;
begin
Inc(c);
writeln(c);
end;

var
tm: TMufasaBitmap;
tpa: TPointArray;
d: Integer;

begin
tm.DrawTPA(tpa, 0);
Inc(d);
writeln(d);
end.

rj

2014-08-25 10:10:32

what is the bug you never called Pointer.Inc unless you mean where it does not increase the variable c by 1

riwu

2014-08-25 10:13:48

From: Robert
what is the bug you never called Pointer.Inc

Yeah if you run the script you would realize that it's actually being called in TMufasaBitmap.DrawTPA() when it's not supposed to.

rj

2014-08-25 10:19:06

From: riwu
Yeah if you run the script you would realize that it's actually being called in TMufasaBitmap.DrawTPA() when it's not supposed to.


Hmm yes and the bug is still there even when you declare a type of Pointer

slacky

2014-08-25 10:39:57

It's not a bug, it's pretty much the expected behavior.

TMufasaBitmap is defined as a Pointer in lape (it seems). And since there is a local function: Pointer.Inc() it will be automatically called, instead of the global Inc().

In this case, the simple workaround is to use the System-unit as a prefix so lape knows to call the correct method, so..

Procedure Pointer.Inc(Size: Int64);
Begin
writeln('Pointer.Inc() called');
Self := Self + Size;
End;


procedure TMufasaBitmap.DrawTPA(tpa: TPointArray; Colour: Integer); override;
var
c: Integer;
begin
System.Inc(c);
writeln(c);
end;

var
tm: TMufasaBitmap;
tpa: TPointArray;
d: Integer;
begin
tm.DrawTPA(tpa, 0);
Inc(d);
writeln(d);
end.

riwu

2014-08-25 10:53:04

From: slacky
It's not directly a bug, it's pretty much the expected behavior.

TMufasaBitmap is defined as a Pointer in lape (it seems). And since there is a there is a a local function: Pointer.Inc() it will be automatically called, instead of the global Inc().

i see…didn't know that TMufasaBitmap is a pointer…
thx +rep

Brandon

2014-08-25 12:21:33

I don't get how it's not a bug. I thought TMufasaBitmap was a record or class(TObject)

If that's the case then implicit conversion to a "pointer" would indeed be a bug. So it shouldn't be calling Pointer.Inc/Self.Inc inside the TM function.

I don't know.. It just seems a bit weird. The self.Inc shouldn't take priority here (implicitly) because it isn't being used directly (explicitly / Self.Inc if TM really is a pointer).

Type-Safety comes to mind. I'd say this is a bug.

slacky

2014-08-25 12:45:13

From: Brandon
I don't get how it's not a bug. I thought TMufasaBitmap was a record or class(TObject)

If that's the case then implicit conversion to a "pointer" would indeed be a bug. So it shouldn't be calling Pointer.Inc/Self.Inc inside the TM function.

I don't know.. It just seems a bit weird. The self.Inc shouldn't take priority here (implicitly) because it isn't being used directly (explicitly / Self.Inc if TM really is a pointer).

Type-Safety comes to mind. I'd say this is a bug.

Yeah, you might indeed be right about it being a bug.
Edit:I just checked it right now, and `TMufasaBitmap` seems to be defined as `type TObject`, (and TObject is defined as `type Pointer`).

Brandon

2014-08-25 12:59:41

From: slacky
Yeah, you might indeed be right about it being a bug.
Edit:I just checked it right now, and `TMufasaBitmap` seems to be defined as `type TObject`, (and TObject is defined as `type Pointer`).



Yeah. You are right. Not myself. I checked the net and tried it using:


var
F: TObject;
P: Pointer;
I: Integer;
PtrI: ^Integer;
begin
P := F; //implicit conversion, but fine.
PtrI := F; //also fine..
//P := I; //compile time error.
writeln(F); //prints nil.
end.


Still.. it does suck. Sort of a type-safety issue rather than a bug then I guess. It's not really right that all classes should/would/could be implicitly converted to pointers.

I guess this is actually a Pascal issue rather than a Lape one. So yeah you are right. It's "technically" not a bug. Well.. at least there is a work around.

nielsie95

2014-08-25 13:39:05

Yes, this is as designed. Every type inherits the type functions of its parent. It can be turned off on the Simba side for certain imports, though.