SRL Archive - Lape

Argument diff record type as param


riwu

2014-11-07 08:30:27

I'm not sure if it's supposed to be a feature or a bug.

procedure Mouse(box: TBox);
begin
writeln(box);
end;

type glModel = record
ID: Cardinal;
TID: Integer;
X, Y: Integer;
end;

var
modelRecord: glModel;
begin
Mouse(modelRecord);
end.
Their fields are similar but they are actually 2 completely different records…should throw an error in case ppl (like me) make a mistake in passing the wrong argument.

Brandon

2014-11-08 09:56:56

Are you absolutely sure there are no other overloads? Anyone able to reproduce this?

riwu

2014-11-08 09:59:39

From: Brandon
Are you absolutely sure there are no other overloads? Anyone able to reproduce this?

No i didnt include anything.
Ur test resulted in a compiling error?

Frement

2014-11-08 10:25:36

Is slackys record comparisons in the newest simba? Anyway, the two records fit within each other. Except the types of the fields in the two records are not the same so yes it should throw an error.

NKN

2014-11-08 10:26:02

Verified, works for me.


Dunno why though.

Brandon

2014-11-08 10:54:58

From: NKN
Verified, works for me.
Dunno why though.


What about:


type s = record
a: Cardinal;
b: Integer;
c: Integer;
d: Integer;
end;

procedure Mouse(box: TBox);
begin
writeln('foo..');
end;

procedure Mouse(l: s); overload;
begin
writeln('meh..');
end;

var
m: s;
begin
Mouse(m);
end.

Ambiguous overload? or does it call the right one? Willing to be it calls the right one.. If it does, perhaps you need to declare the structure first before the functions? OP has it after..

NKN

2014-11-08 11:28:28

From: Brandon
What about:


type s = record
a: Cardinal;
b: Integer;
c: Integer;
d: Integer;
end;

procedure Mouse(box: TBox);
begin
writeln('foo..');
end;

procedure Mouse(l: s); overload;
begin
writeln('meh..');
end;

var
m: s;
begin
Mouse(m);
end.

Ambiguous overload? or does it call the right one? Willing to be it calls the right one.. If it does, perhaps you need to declare the structure first before the functions? OP has it after..

That one calls the correct procedure.

seems to only call the TBox method when there is no other method with s as the parameter. I moved it around, switched overloads, etc.

slacky

2014-11-08 18:32:13

From: Frement
Is slackys record comparisons in the newest simba? Anyway, the two records fit within each other. Except the types of the fields in the two records are not the same so yes it should throw an error.

Nope it was never re-added after we updated Lape (from original repo).

Edit: As a sidenote: This bug has apparently been around for a long time.

riwu

2014-11-08 19:00:59

From: Brandon
What about:


type s = record
a: Cardinal;
b: Integer;
c: Integer;
d: Integer;
end;

procedure Mouse(box: TBox);
begin
writeln('foo..');
end;

procedure Mouse(l: s); overload;
begin
writeln('meh..');
end;

var
m: s;
begin
Mouse(m);
end.

Ambiguous overload? or does it call the right one? Willing to be it calls the right one.. If it does, perhaps you need to declare the structure first before the functions? OP has it after..



Declaring it first produced the same result:

type glModel = record
ID: Cardinal;
TID: Integer;
X, Y: Integer;
end;

var
modelRecord: glModel;

procedure Mouse(box: TBox);
begin
writeln(box);
end;

begin
Mouse(modelRecord);
end.


The fact that u need to overload, and not override the second method with the s param means that the compiler actually recognize that 's' and 'tbox' are 2 different records? Does it simply distinguish them by namespace of the records? Could the same check be used for the above scenario? Would there be any side effect/performance issues for doing so?

slacky

2014-11-08 20:04:23

From: riwu

The fact that u need to overload, and not override the second method with the s param means that the compiler actually recognize that 's' and 'tbox' are 2 different records? Does it simply distinguish them by namespace of the records? Could the same check be used for the above scenario? Would there be any side effect/performance issues for doing so?

..
I can look in to getting a fix added soon. It's just a matter of a lacking check, like I think I got something working already, but I'm gonna sit on it for a lil' while, just to make sure I am not doing anything stupid.

nielsie95

2014-11-21 14:31:44

You're right, seems like a peculiar bug. Thanks for reporting!

slacky

2014-12-01 07:52:14

I've added a (small) fix to lape which hopefully works as it's supposed to. Time will tell.