Discussion:
[fpc-pascal] Generics question
Bart
2018-12-02 22:28:00 UTC
Permalink
Hi,

{ TFoo }

generic TFoo<T> = class
procedure Bar;
end;

{ TFoo }

procedure TFoo.Bar;
procedure localproc;
begin end;
begin
end;

This will not compile (fpc 3.0.4):
gentest.lpr(35,4) Error: Generic methods cannot have nested procedures

While the message is clear, the reason for this is not (to me at last).

Does anybody know why?

Bart
--
Bart
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman
Sven Barth via fpc-pascal
2018-12-03 07:00:51 UTC
Permalink
Post by Bart
Hi,
{ TFoo }
generic TFoo<T> = class
procedure Bar;
end;
{ TFoo }
procedure TFoo.Bar;
procedure localproc;
begin end;
begin
end;
gentest.lpr(35,4) Error: Generic methods cannot have nested procedures
While the message is clear, the reason for this is not (to me at last).
Does anybody know why?
Because Delphi does not allow that either. We relaxed that however in 3.1.1
and it should be part of 3.2.0. You can test the corresponding branch of
you want.

Regards,
Sven
Martok
2018-12-03 09:53:20 UTC
Permalink
Because Delphi does not allow that either. We relaxed that however in 3.1.1 and
it should be part of 3.2.0. You can test the corresponding branch of you want.
Is this related to <https://bugs.freepascal.org/view.php?id=33013> ?
The example I provided then doesn't crash anymore, but it sounds like that is
the sort of code that would not be accepted at all in Delphi?

I'll have to check the real-world code again, might be able to close this bug as
"fixed in the mean time".
--
Regards,
Martok

Ceterum censeo b32079 esse sanandam.

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/m
Sven Barth via fpc-pascal
2018-12-03 10:27:16 UTC
Permalink
Post by Sven Barth via fpc-pascal
Because Delphi does not allow that either. We relaxed that however in
3.1.1 and
Post by Sven Barth via fpc-pascal
it should be part of 3.2.0. You can test the corresponding branch of you
want.
Is this related to <https://bugs.freepascal.org/view.php?id=33013> ?
The example I provided then doesn't crash anymore, but it sounds like that is
the sort of code that would not be accepted at all in Delphi?
I'll have to check the real-world code again, might be able to close this bug as
"fixed in the mean time".
Yes, I fixed something related to nested procs some weeks ago and yes,
Delphi does not support that (and some other things we support, but they
don't :D ).

Regards,
Sven
Martok
2018-12-03 11:34:24 UTC
Permalink
Post by Martok
I'll have to check the real-world code again, might be able to close this bug as
"fixed in the mean time".
Checked, works also in real code.

I have added a note saying so on the bug.
--
Regards,
Martok

Ceterum censeo b32079 esse sanandam.

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://l
Loading...