Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-11

Generics and Scopes

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

African Wild Dog

Hello,

I have tried to compile some delphi projects using the latest FPC (3.0.0) release, and i got several errors related to Ggenerics feature. Reading the FPC documentation (section 8.8 - A Word About Scope) i have found that FPC requires that all external types and procedures used in the the Generic type implementation must be visible when the Generic type is specialized.

It is intended to change such compiler behavior in the future? It is incompatible with Delphi and moreover it force us to break the encapsulation of the Generic types.

Best regards

Michael Van Canneyt
to African Wild Dog
African Wild Dog wrote 11 lines
Hello, I have tried to compile some delphi projects using the latest FPC (3.0.0) release, and i got several errors related to Ggenerics feature. Reading the FPC documentation (section 8.8 - A Word About Scope) i have found that FPC requires that all external types and procedures used in the the Generic type implementation must be visible when the Generic type is specialized. It is intended to change such compiler behavior in the future? It is incompatible with Delphi and moreover it force us to break the encapsulation of the Generic types.

It may well be that this part of the text is no longer valid. Sven Barth would need to look at it to see if it is still so.

Michael.

African Wild Dog
to Sven Barth

2016-11-07 14:15 GMT-02:00 Sven Barth :

Show quoted text 7 lines
Am 07.11.2016 15:58 schrieb "African Wild Dog" : > It is intended to change such compiler behavior in the future? It is incompatible with Delphi and moreover it force us to break the encapsulation of the Generic types. I can't answer this without you providing an example that fails.

Sorry for the noise. Some of my classes were bad designed. They look like this sample (Delphi XE 6 compiles):

==== CODE BEGIN ====

unit sample;
{$MODE delphi}
interface
type
  TGenericRecord<T> = record
  strict private
    Interf: IInterface;
    type
      TMockIntfObject<T> = record // Nested generic declaration
      end;
  public
    FValue: T;
    procedure SetValue(Value: T);
  end;
implementation

{ TGenericRecord<T> }

procedure TGenericRecord<T>.SetValue(Value: T);
begin
  Interf := TMockIntfObject.Create;
end;
end.

==== END ====

With fpc i got the error "Fatal: Declation of generic class inside another generic class is not allowed".

Best regards

African Wild Dog
to African Wild Dog

2016-11-10 1:30 GMT-02:00 African Wild Dog :

Show quoted text 55 lines
2016-11-07 14:15 GMT-02:00 Sven Barth : > Am 07.11.2016 15:58 schrieb "African Wild Dog" : > > It is intended to change such compiler behavior in the future? It is > incompatible with Delphi and moreover it force us to break the > encapsulation of the Generic types. > > I can't answer this without you providing an example that fails. > Sorry for the noise. Some of my classes were bad designed. They look like this sample (Delphi XE 6 compiles): ==== CODE BEGIN ==== unit sample; {$MODE delphi} interface type TGenericRecord<T> = record strict private Interf: IInterface; type TMockIntfObject<T> = record // Nested generic declaration end; public FValue: T; procedure SetValue(Value: T); end; implementation { TGenericRecord<T> } procedure TGenericRecord<T>.SetValue(Value: T); begin Interf := TMockIntfObject.Create; end; end. ==== END ==== With fpc i got the error "Fatal: Declation of generic class inside another generic class is not allowed". Best regards

This is the correct sample:

=== CODE BEGIN ===

unit sample;
{$MODE delphi}
interface
type
  TGenericRecord<T> = record
  strict private
    type
      TMockRecord<T> = record // Nested generic declaration
      end;
  public
    FValue: T;
    procedure SetValue(Value: T);
  end;
implementation

{ TGenericRecord<T> }

procedure TGenericRecord<T>.SetValue(Value: T);
begin
end;
end.

=== END ===

Regards

Sven Barth
to African Wild Dog: 2016-11-07 14:15 GMT-02:00 Sven Barth : Sorry for the noise. Some of my classes were bad…
"African Wild Dog" wrote 5 lines
2016-11-07 14:15 GMT-02:00 Sven Barth : > > Am 07.11.2016 15:58 schrieb "African Wild Dog" : > > It is intended to change such compiler behavior in the future? It is

incompatible with Delphi and moreover it force us to break the encapsulation of the Generic types.

Show quoted text 5 lines
> > I can't answer this without you providing an example that fails. Sorry for the noise. Some of my classes were bad designed. They look like

this sample (Delphi XE 6 compiles):

Show quoted text 38 lines
==== CODE BEGIN ==== unit sample; {$MODE delphi} interface type TGenericRecord<T> = record strict private Interf: IInterface; type TMockIntfObject<T> = record // Nested generic declaration end; public FValue: T; procedure SetValue(Value: T); end; implementation { TGenericRecord<T> } procedure TGenericRecord<T>.SetValue(Value: T); begin Interf := TMockIntfObject.Create; end; end. ==== END ==== With fpc i got the error "Fatal: Declation of generic class inside

another generic class is not allowed".

Nested generics are currently indeed not supported. They are on my ToDo list however.

Regards,
Sven