Browse Source

* allow generic parameters to be used as array limits, resolves #41358

florian 3 weeks ago
parent
commit
285ba1cc6f
3 changed files with 16 additions and 2 deletions
  1. 3 1
      compiler/ncon.pas
  2. 2 1
      compiler/nset.pas
  3. 11 0
      tests/webtbs/tw41358.pp

+ 3 - 1
compiler/ncon.pas

@@ -233,7 +233,7 @@ implementation
       defcmp,defutil,procinfo,
       aasmdata,aasmtai,
       cgbase,
-      nld;
+      nld,nbas;
 
     function genintconstnode(const v : TConstExprInt) : tordconstnode;
       var
@@ -394,6 +394,8 @@ implementation
               else
                 p1:=cguidconstnode.create(pguid(p.value.valueptr)^);
             end;
+          constnone :
+            p1:=cnothingnode.create
           else
             internalerror(200205103);
         end;

+ 2 - 1
compiler/nset.pas

@@ -458,7 +458,8 @@ implementation
          if codegenerror then
            exit;
          { both types must be compatible }
-         if compare_defs(left.resultdef,right.resultdef,left.nodetype)=te_incompatible then
+         if not (nf_generic_para in left.flags) and not (nf_generic_para in right.flags) and
+           (compare_defs(left.resultdef,right.resultdef,left.nodetype)=te_incompatible) then
            IncompatibleTypes(left.resultdef,right.resultdef);
          { check if only when its a constant set and
            ignore range nodes which are generic parameter derived }

+ 11 - 0
tests/webtbs/tw41358.pp

@@ -0,0 +1,11 @@
+program Project1;
+{$Mode objfpc}
+type
+  //generic x<const K> = class  // error semicolon expected, but > found
+  generic x<const K; T> = class // so we give it the semicolon...
+  public type
+    Foo = array[0..K] of byte; // internal error
+  end;
+
+begin
+end.