Ver Fonte

Merged revisions 508 via svnmerge from
/trunk

git-svn-id: branches/fixes_2_0@523 -

peter há 20 anos atrás
pai
commit
74afd0284a
2 ficheiros alterados com 27 adições e 7 exclusões
  1. 22 5
      compiler/symsym.pas
  2. 5 2
      compiler/symtable.pas

+ 22 - 5
compiler/symsym.pas

@@ -118,7 +118,7 @@ interface
           function search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
           function search_procdef_bypara(para:tlist;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
           function search_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
-          function search_procdef_assignment_operator(fromdef,todef:tdef):Tprocdef;
+          function search_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
           function  write_references(ppufile:tcompilerppufile;locals:boolean):boolean;override;
           function is_visible_for_object(currobjdef:tdef):boolean;override;
 {$ifdef GDB}
@@ -993,13 +993,12 @@ implementation
       end;
 
 
-    function Tprocsym.search_procdef_assignment_operator(fromdef,todef:tdef):Tprocdef;
+    function Tprocsym.search_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
       var
         convtyp : tconverttype;
         pd      : pprocdeflist;
         bestpd  : tprocdef;
-        eq,
-        besteq  : tequaltype;
+        eq      : tequaltype;
         hpd     : tprocdef;
         i       : byte;
       begin
@@ -1009,7 +1008,15 @@ implementation
         pd:=pdlistfirst;
         while assigned(pd) do
           begin
-            if equal_defs(todef,pd^.def.rettype.def) then
+            if equal_defs(todef,pd^.def.rettype.def) and
+              { the result type must be always really equal and not an alias,
+                if you mess with this code, check tw4093 }
+              ((todef=pd^.def.rettype.def) or
+               (
+                 not(df_unique in todef.defoptions) and
+                 not(df_unique in pd^.def.rettype.def.defoptions)
+               )
+              ) then
              begin
                i:=0;
                { ignore vs_hidden parameters }
@@ -1019,8 +1026,18 @@ implementation
                if assigned(pd^.def.paras[i]) then
                 begin
                   eq:=compare_defs_ext(fromdef,tparavarsym(pd^.def.paras[i]).vartype.def,nothingn,convtyp,hpd,[]);
+
+                  { alias? if yes, only l1 choice,
+                    if you mess with this code, check tw4093 }
+                  if (eq=te_exact) and
+                    (fromdef<>tparavarsym(pd^.def.paras[i]).vartype.def) and
+                    ((df_unique in fromdef.defoptions) or
+                    (df_unique in tparavarsym(pd^.def.paras[i]).vartype.def.defoptions)) then
+                    eq:=te_convert_l1;
+
                   if eq=te_exact then
                    begin
+                     besteq:=eq;
                      result:=pd^.def;
                      exit;
                    end;

+ 5 - 2
compiler/symtable.pas

@@ -2051,6 +2051,7 @@ implementation
     var st:Tsymtable;
         sym:Tprocsym;
         sv:cardinal;
+        besteq:tequaltype;
 
     begin
       st:=symtablestack;
@@ -2062,8 +2063,10 @@ implementation
             begin
               if sym.typ<>procsym then
                 internalerror(200402031);
-              search_assignment_operator:=sym.search_procdef_assignment_operator(from_def,to_def);
-              if search_assignment_operator<>nil then
+              { if the source type is an alias then this is only the second choice,
+                if you mess with this code, check tw4093 }
+              search_assignment_operator:=sym.search_procdef_assignment_operator(from_def,to_def,besteq);
+              if (search_assignment_operator<>nil) and (besteq=te_exact) then
                 break;
             end;
           st:=st.next;