Browse Source

* when searching for an assignment operator to a typed pointer type then also search for an assignment operator to an untyped pointer if nothing suitable was found
+ added test

Sven/Sarah Barth 4 days ago
parent
commit
b64c6c4c5e
2 changed files with 32 additions and 0 deletions
  1. 10 0
      compiler/symtable.pas
  2. 22 0
      tests/test/toperator97.pp

+ 10 - 0
compiler/symtable.pas

@@ -4275,6 +4275,16 @@ implementation
         if result=nil then
         if result=nil then
           result:=search_specific_assignment_operator(_ASSIGNMENT,from_def,to_def);
           result:=search_specific_assignment_operator(_ASSIGNMENT,from_def,to_def);
 
 
+        { if we're assigning to a typed pointer, but we did not find a suitable assignement
+          operator then we also check for a untyped pointer assignment operator }
+        if not assigned(result) and is_pointer(to_def) and not is_voidpointer(to_def) then
+          begin
+            if explicit then
+              result:=search_specific_assignment_operator(_OP_EXPLICIT,from_def,voidpointertype);
+            if not assigned(result) then
+              result:=search_specific_assignment_operator(_ASSIGNMENT,from_def,voidpointertype);
+          end;
+
         { restore symtable stack }
         { restore symtable stack }
         if to_def.typ in [recorddef,objectdef] then
         if to_def.typ in [recorddef,objectdef] then
           symtablestack.pop(tabstractrecorddef(to_def).symtable);
           symtablestack.pop(tabstractrecorddef(to_def).symtable);

+ 22 - 0
tests/test/toperator97.pp

@@ -0,0 +1,22 @@
+{ %NORUN }
+
+program toperator97;
+
+{$mode objfpc}
+{$modeswitch advancedrecords}
+
+type
+  TTest = record
+    class operator :=(aArg: TTest): Pointer;
+  end;
+
+class operator TTest.:=(aArg: TTest): Pointer;
+begin
+end;
+
+var
+  b: PByte;
+  t: TTest;
+begin
+  b := t;
+end.