Am 11.04.2021 um 23:38 schrieb Ryan Joseph via fpc-devel:

On Apr 11, 2021, at 3:33 PM, Sven Barth <pascaldra...@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
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;
 
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to