View Issue Details

IDProjectCategoryView StatusLast Update
0033961FPCCompilerpublic2018-07-14 23:04
ReporterThaddy de KoningAssigned ToFlorian 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformallOSallOS Versionall
Product Version3.1.1Product Build39423 
Target VersionFixed in Version3.1.1 
Summary0033961: generics accept a comparison of an unspecialized T to (pointer) nil.
Descriptiongenerics (both modes) accept a comparison of T to nil.
T need not be of a pointer type.
Delphi does not accept such syntax.
Steps To Reproduce{$ifdef fpc}{$mode objfpc}{$modeswitch advancedrecords}{$H+}{$endif}
type
   generic Ttestme<T> = record
   private
     bar:T;
   public
     procedure foo;
   end;
   procedure Ttestme.foo;
   begin
      if bar <> nil then writeln('How do you know T is a ponter type?');
   end;

begin
end.
// the above compiles without warning but:

// now, use it:
var a:specialize TTest<integer>;
begin
  a.foo;
end.
Additional InformationThe comparison to pointer should never been accepted.
Delphi mode also accepts it. Delphi itself does not accept it. Delphi is right.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Relationships

related to 0033960 resolvedMichael Van Canneyt generics chapter 8.8 "A word about scope" needs maybe a remark about accessing members of T that are not yet specialized. 

Activities

Thaddy de Koning

2018-07-10 11:35

reporter   ~0109337

Seems it is all a bit too relaxed a.t.m.

Florian

2018-07-10 20:32

administrator   ~0109351

By design.

Thaddy de Koning

2018-07-12 16:48

reporter   ~0109413

Then the previous 0033960 is - by proxy - also not a valid fix.
T should be undetermined. Can you re-consider this?
I know you made a fix to relax (which kind of works), but is it the proper fix?
Due respect, Thaddy

p.s. I can live with it.

Florian

2018-07-14 15:55

administrator   ~0109451

The example in 0033960 compiles now as well. It is supposed to compile.

Thaddy de Koning

2018-07-14 19:02

reporter   ~0109457

Oh well. I still do not agree about resolving a T to a T with members. Type safety. You just made FPC generics *not* type safe.. Rethink.. I hope you reverse that fix. But if you will keep it in you can close. It is imo the wrong fix not the proper fix.

Florian

2018-07-14 23:04

administrator   ~0109465

It is the proper fix. This is how FPC generics work. The compiler makes during parsing no assumptions about the type.

Issue History

Date Modified Username Field Change
2018-07-10 11:33 Thaddy de Koning New Issue
2018-07-10 11:35 Thaddy de Koning Note Added: 0109337
2018-07-10 20:32 Florian Note Added: 0109351
2018-07-10 20:32 Florian Status new => resolved
2018-07-10 20:32 Florian Resolution open => won't fix
2018-07-10 20:32 Florian Assigned To => Florian
2018-07-12 16:48 Thaddy de Koning Note Added: 0109413
2018-07-12 16:48 Thaddy de Koning Status resolved => feedback
2018-07-12 16:48 Thaddy de Koning Resolution won't fix => reopened
2018-07-14 15:54 Florian Relationship added related to 0033960
2018-07-14 15:55 Florian Note Added: 0109451
2018-07-14 15:55 Florian Status feedback => resolved
2018-07-14 15:55 Florian Fixed in Version => 3.1.1
2018-07-14 15:55 Florian Resolution reopened => fixed
2018-07-14 19:02 Thaddy de Koning Note Added: 0109457
2018-07-14 19:02 Thaddy de Koning Status resolved => feedback
2018-07-14 19:02 Thaddy de Koning Resolution fixed => reopened
2018-07-14 23:04 Florian Note Added: 0109465
2018-07-14 23:04 Florian Status feedback => resolved
2018-07-14 23:04 Florian Resolution reopened => fixed