[fpc-devel] Implicit function specialization precedence

Sven Barth pascaldragon at googlemail.com
Wed Apr 14 22:33:25 CEST 2021


Am 11.04.2021 um 23:38 schrieb Ryan Joseph via fpc-devel:
>
>> On Apr 11, 2021, at 3:33 PM, Sven Barth <pascaldragon at googlemail.com> wrote:
>>
>> Looking at it, it could be that there is a bug in tarrayconstructornode.pass_typecheck that hasn't really surfaced yet... I'll have to look at that first, but I don't know when I'll have the time for that.
> sure I'll just leave it as is for now then. By the time the overloading happens it must know the array constructor is array of const but it should ideally be known by the time tarrayconstructornode.pass_typecheck is executed.

Had a bit of time to look at this. You can try the attached patch. You 
can then check for both ado_IsConstructor and ado_IsArrayOfConst to 
detect such a mixed array.

Regards,
Sven
-------------- next part --------------
diff --git a/compiler/defutil.pas b/compiler/defutil.pas
index 852d2cfa5a..b9c50dfa87 100644
--- a/compiler/defutil.pas
+++ b/compiler/defutil.pas
@@ -821,7 +821,10 @@ implementation
     function is_array_of_const(p : tdef) : boolean;
       begin
          result:=(p.typ=arraydef) and
-                 (ado_IsArrayOfConst in tarraydef(p).arrayoptions);
+                 (ado_IsArrayOfConst in tarraydef(p).arrayoptions) and
+                 { consider it an array-of-const in the strict sense only if it
+                   isn't an array constructor }
+                 not (ado_IsConstructor in tarraydef(p).arrayoptions);
       end;
 
     function is_conststring_array(p: tdef): boolean;
diff --git a/compiler/nld.pas b/compiler/nld.pas
index 7be26db2bc..bdea9cfb0f 100644
--- a/compiler/nld.pas
+++ b/compiler/nld.pas
@@ -1113,6 +1113,7 @@ implementation
         hdef  : tdef;
         hp    : tarrayconstructornode;
         len   : longint;
+        diff,
         varia : boolean;
         eq    : tequaltype;
         hnodetype : tnodetype;
@@ -1136,6 +1137,7 @@ implementation
         hnodetype:=errorn;
         len:=0;
         varia:=false;
+        diff:=false;
         if assigned(left) then
          begin
            hp:=self;
@@ -1164,6 +1166,8 @@ implementation
                    end
                  else
                    eq:=compare_defs(hdef,hp.left.resultdef,hp.left.nodetype);
+                 if eq<te_equal then
+                   diff:=true;
                  if (not varia) and (eq<te_equal) then
                    begin
                      { If both are integers we need to take the type that can hold both
@@ -1194,6 +1198,8 @@ implementation
          include(tarraydef(resultdef).arrayoptions,ado_IsConstructor);
          if varia then
            include(tarraydef(resultdef).arrayoptions,ado_IsVariant);
+         if diff then
+           include(tarraydef(resultdef).arrayoptions,ado_IsArrayOfConst);
          tarraydef(resultdef).elementdef:=hdef;
       end;
 


More information about the fpc-devel mailing list