2
0
Эх сурвалжийг харах

* fix for Mantis #32111: allow undefined defs as a for loop's counter; the specialization will decide whether it will compile or not
+ added test

git-svn-id: trunk@36722 -

svenbarth 8 жил өмнө
parent
commit
ca78bfffae

+ 1 - 0
.gitattributes

@@ -15628,6 +15628,7 @@ tests/webtbs/tw31945.pp svneol=native#text/pascal
 tests/webtbs/tw3197.pp svneol=native#text/plain
 tests/webtbs/tw3207.pp svneol=native#text/plain
 tests/webtbs/tw3210.pp svneol=native#text/plain
+tests/webtbs/tw32111.pp svneol=native#text/pascal
 tests/webtbs/tw3212.pp svneol=native#text/plain
 tests/webtbs/tw3214.pp svneol=native#text/plain
 tests/webtbs/tw3216.pp svneol=native#text/plain

+ 6 - 3
compiler/pstatmnt.pas

@@ -375,11 +375,14 @@ implementation
              loopvarsym:=nil;
 
              { variable must be an ordinal, int64 is not allowed for 32bit targets }
-             if not(is_ordinal(hloopvar.resultdef))
+             if (
+                 not(is_ordinal(hloopvar.resultdef))
     {$ifndef cpu64bitaddr}
-                or is_64bitint(hloopvar.resultdef)
+                 or is_64bitint(hloopvar.resultdef)
     {$endif not cpu64bitaddr}
-                then
+               ) and
+               (hloopvar.resultdef.typ<>undefineddef)
+               then
                MessagePos(hloopvar.fileinfo,type_e_ordinal_expr_expected);
 
              hp:=hloopvar;

+ 59 - 0
tests/webtbs/tw32111.pp

@@ -0,0 +1,59 @@
+{ %NORUN }
+
+program tw32111;
+{$MODE OBJFPC}{$H+}{$B-}
+uses
+  SysUtils;
+
+type generic
+  TDynArray<T> = array of T;
+
+type generic
+  TSorter<T, C> = class
+  protected
+  var
+    Tmp: C;
+    procedure _Sort(constref Index: specialize TDynArray<C>;
+                     constref Values: specialize TDynArray<T>;
+                     StartIndex, EndIndex: Int32); virtual;
+  public
+    procedure Sort(constref Index: specialize TDynArray<C>;
+                     constref Values: specialize TDynArray<T>;
+                     StartIndex, EndIndex: Int32); virtual;
+  end;
+
+
+procedure TSorter.Sort(constref Index: specialize TDynArray<C>;
+                       constref Values: specialize TDynArray<T>;
+                       StartIndex, EndIndex: Int32);
+var
+  Len: Int32;
+  I : C;
+
+begin
+  // some code
+  Len:= System.Length(Values);
+  if (Len = 0) or ( Assigned(Index) and (Len <> System.Length(Index)) ) then Exit;
+  if Assigned(Index)
+  then begin
+    for I:= C(Startindex) to C(EndIndex) do Index[I]:= I;
+    I:= 1;
+  end;
+  Self._Sort(Index, Values, StartIndex, EndIndex);
+end;
+
+procedure TSorter._Sort(constref Index: specialize TDynArray<C>;
+                        constref Values: specialize TDynArray<T>;
+                        StartIndex, EndIndex: Int32);
+begin
+  // some code
+end;
+
+var
+  s: specialize TSorter<Unicodestring, Int32>;
+
+begin
+
+  s:= specialize TSorter<Unicodestring, Int32>.Create;
+
+end.