ソースを参照

* also store and restore the optoken when specializing to avoid potential issues when checking for compatible operator overloads
+ added test

Sven/Sarah Barth 4 日 前
コミット
1c9d59510c
3 ファイル変更33 行追加0 行削除
  1. 2 0
      compiler/pgentype.pas
  2. 3 0
      compiler/pgenutil.pas
  3. 28 0
      tests/test/tgeneric128.pp

+ 2 - 0
compiler/pgentype.pas

@@ -27,6 +27,7 @@ interface
 
 uses
   cclasses,
+  tokens,
   globtype,
   symtype,symbase;
 
@@ -41,6 +42,7 @@ type
     oldgenericdummysyms   : tfphashobjectlist;
     oldspecializestate    : pspecializationstate;
     oldcurrent_genericdef : tdef;
+    oldoptoken            : ttoken;
   end;
 
   tspecializationcontext=class

+ 3 - 0
compiler/pgenutil.pas

@@ -2784,6 +2784,8 @@ uses
       state.oldgenericdummysyms:=current_module.genericdummysyms;
       state.oldcurrent_genericdef:=current_genericdef;
       state.oldspecializestate:=pspecializationstate(current_module.specializestate);
+      state.oldoptoken:=optoken;
+      optoken:=NOTOKEN;
       current_module.specializestate:=@state;
       current_module.extendeddefs:=TFPHashObjectList.create(true);
       current_module.genericdummysyms:=tfphashobjectlist.create(true);
@@ -2865,6 +2867,7 @@ uses
       current_module.genericdummysyms.free;
       current_module.genericdummysyms:=state.oldgenericdummysyms;
       current_module.specializestate:=state.oldspecializestate;
+      optoken:=state.oldoptoken;
       symtablestack.free;
       symtablestack:=state.oldsymtablestack;
       { clear the state record to be on the safe side }

+ 28 - 0
tests/test/tgeneric128.pp

@@ -0,0 +1,28 @@
+{ %NORUN }
+
+program tgeneric128;
+
+{$mode delphi}
+
+type
+  Foo<T> = record
+  public
+    class operator Equal(const left: Foo<T>; const right: T): Boolean;
+  end;
+
+  Bar<T> = record
+  public
+    class operator Implicit(const value: Bar<T>): Foo<T>;
+  end;
+
+class operator Foo<T>.Equal(const left: Foo<T>; const right: T): Boolean;
+begin
+end;
+
+class operator Bar<T>.Implicit(const value: Bar<T>): Foo<T>;
+begin
+end;
+
+begin
+
+end.