From ca78bfffaefec12accdbf37eb5cf768e9a89719e Mon Sep 17 00:00:00 2001 From: svenbarth Date: Mon, 10 Jul 2017 19:45:15 +0000 Subject: [PATCH] * 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 - --- .gitattributes | 1 + compiler/pstatmnt.pas | 9 ++++--- tests/webtbs/tw32111.pp | 59 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 tests/webtbs/tw32111.pp diff --git a/.gitattributes b/.gitattributes index cd889a1852..2ddcb29bf9 100644 --- a/.gitattributes +++ b/.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 diff --git a/compiler/pstatmnt.pas b/compiler/pstatmnt.pas index 8209fa8a66..dac01bbb57 100644 --- a/compiler/pstatmnt.pas +++ b/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; diff --git a/tests/webtbs/tw32111.pp b/tests/webtbs/tw32111.pp new file mode 100644 index 0000000000..9dc8f044e8 --- /dev/null +++ b/tests/webtbs/tw32111.pp @@ -0,0 +1,59 @@ +{ %NORUN } + +program tw32111; +{$MODE OBJFPC}{$H+}{$B-} +uses + SysUtils; + +type generic + TDynArray = array of T; + +type generic + TSorter = class + protected + var + Tmp: C; + procedure _Sort(constref Index: specialize TDynArray; + constref Values: specialize TDynArray; + StartIndex, EndIndex: Int32); virtual; + public + procedure Sort(constref Index: specialize TDynArray; + constref Values: specialize TDynArray; + StartIndex, EndIndex: Int32); virtual; + end; + + +procedure TSorter.Sort(constref Index: specialize TDynArray; + constref Values: specialize TDynArray; + 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; + constref Values: specialize TDynArray; + StartIndex, EndIndex: Int32); +begin + // some code +end; + +var + s: specialize TSorter; + +begin + + s:= specialize TSorter.Create; + +end.