Browse Source

fcl-passrc: resolver: fixed for s in arrayofstring

git-svn-id: trunk@38701 -
Mattias Gaertner 7 years ago
parent
commit
b64b45e26c
2 changed files with 31 additions and 6 deletions
  1. 9 6
      packages/fcl-passrc/src/pasresolver.pp
  2. 22 0
      packages/fcl-passrc/tests/tcresolver.pas

+ 9 - 6
packages/fcl-passrc/src/pasresolver.pp

@@ -6572,11 +6572,7 @@ begin
 
     if not EnumeratorFound then
       begin
-      VarRange:=EvalTypeRange(VarResolved.TypeEl,[]);
-      if VarRange=nil then
-        RaiseXExpectedButYFound(20171109191528,'range',
-                     GetResolverResultDescription(VarResolved),Loop.VariableName);
-      //writeln('TPasResolver.ResolveImplForLoop ForIn VarRange=',VarRange.AsDebugString);
+      VarRange:=nil;
       InRange:=nil;
       try
         OrigStartResolved:=StartResolved;
@@ -6638,6 +6634,11 @@ begin
           begin
           // for v in <constant> do
           // -> check if same type
+          VarRange:=EvalTypeRange(VarResolved.TypeEl,[]);
+          if VarRange=nil then
+            RaiseXExpectedButYFound(20171109191528,'range',
+                         GetResolverResultDescription(VarResolved),Loop.VariableName);
+          //writeln('TPasResolver.ResolveImplForLoop ForIn VarRange=',VarRange.AsDebugString);
           //writeln('TPasResolver.ResolveImplForLoop ForIn InRange=',InRange.AsDebugString,' ElType=',GetResolverResultDbg(StartResolved));
           case InRange.Kind of
           revkRangeInt,revkSetOfInt:
@@ -6710,7 +6711,9 @@ begin
         if not EnumeratorFound then
           begin
           {$IFDEF VerbosePasResolver}
-          writeln('TPasResolver.ResolveImplForLoop VarRange=',VarRange.AsDebugString,' StartResolved=',GetResolverResultDbg(StartResolved));
+          writeln('TPasResolver.ResolveImplForLoop StartResolved=',GetResolverResultDbg(StartResolved));
+          if VarRange<>nil then
+            writeln('TPasResolver.ResolveImplForLoop VarRange=',VarRange.AsDebugString);
           {$ENDIF}
           RaiseMsg(20171108223818,nCannotFindEnumeratorForType,sCannotFindEnumeratorForType,
             [GetBaseDescription(OrigStartResolved)],Loop.StartExpr);

+ 22 - 0
packages/fcl-passrc/tests/tcresolver.pas

@@ -519,6 +519,7 @@ type
     Procedure TestClass_ClassConstFail;
     Procedure TestClass_Enumerator;
     Procedure TestClass_EnumeratorFunc;
+    Procedure TestClass_ForInPropertyStaticArray;
     // Todo: Fail to use class.method in constant or type, e.g. const p = @o.doit;
 
     // published
@@ -8766,6 +8767,27 @@ begin
   ParseProgram;
 end;
 
+procedure TTestResolver.TestClass_ForInPropertyStaticArray;
+begin
+  StartProgram(false);
+  Add([
+  'type',
+  '  TMonthNameArray = array [1..12] of string;',
+  '  TMonthNames = TMonthNameArray;',
+  '  TObject = class',
+  '  private',
+  '    function GetLongMonthNames: TMonthNames; virtual; abstract;',
+  '  public',
+  '    Property LongMonthNames : TMonthNames Read GetLongMonthNames;',
+  '  end;',
+  'var f: TObject;',
+  '  Month: string;',
+  'begin',
+  '  for Month in f.LongMonthNames do ;',
+  '']);
+  ParseProgram;
+end;
+
 procedure TTestResolver.TestClass_PublishedClassVarFail;
 begin
   StartProgram(false);