Explorar el Código

fcl-passrc: resolver: fixed with-do-inherited

git-svn-id: trunk@37406 -
Mattias Gaertner hace 7 años
padre
commit
5534acd097

+ 20 - 4
packages/fcl-passrc/src/pasresolver.pp

@@ -1253,6 +1253,7 @@ type
     function PushEnumDotScope(CurEnumType: TPasEnumType): TPasDotEnumTypeScope;
     procedure ResetSubScopes(out Depth: integer);
     procedure RestoreSubScopes(Depth: integer);
+    function GetInheritedExprScope(ErrorEl: TPasElement): TPasProcedureScope;
     // log and messages
     class procedure UnmangleSourceLineNumber(LineNumber: integer;
       out Line, Column: integer);
@@ -5306,8 +5307,7 @@ begin
     end;
 
   // 'inherited;' without expression
-  CheckTopScope(FScopeClass_Proc);
-  ProcScope:=TPasProcedureScope(TopScope);
+  ProcScope:=GetInheritedExprScope(El);
   SelfScope:=ProcScope.GetSelfScope;
   if SelfScope=nil then
     RaiseMsg(20170216152141,nInheritedOnlyWorksInMethods,sInheritedOnlyWorksInMethods,[],El);
@@ -5353,8 +5353,7 @@ begin
   writeln('TPasResolver.ResolveInheritedCall El=',GetTreeDbg(El));
   {$ENDIF}
 
-  CheckTopScope(FScopeClass_Proc);
-  ProcScope:=TPasProcedureScope(TopScope);
+  ProcScope:=GetInheritedExprScope(El);
   SelfScope:=ProcScope.GetSelfScope;
   if SelfScope=nil then
     RaiseMsg(20170216152148,nInheritedOnlyWorksInMethods,sInheritedOnlyWorksInMethods,[],El);
@@ -10473,6 +10472,23 @@ begin
     end;
 end;
 
+function TPasResolver.GetInheritedExprScope(ErrorEl: TPasElement
+  ): TPasProcedureScope;
+var
+  Scope: TPasScope;
+  i: Integer;
+begin
+  i:=ScopeCount;
+  repeat
+    dec(i);
+    if i<0 then
+      RaiseMsg(20171006001229,nIllegalExpression,sIllegalExpression,[],ErrorEl);
+    Scope:=Scopes[i];
+    if Scope is TPasProcedureScope then
+      exit(TPasProcedureScope(Scope));
+  until false;
+end;
+
 procedure TPasResolver.SetLastMsg(const id: int64; MsgType: TMessageType;
   MsgNumber: integer; const Fmt: String; Args: array of const;
   PosEl: TPasElement);

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

@@ -6193,6 +6193,8 @@ begin
   '  inherited;',
   '  inherited DoIt;',
   '  if inherited DoIt=14 then ;',
+  '  with Self do inherited;',
+  '  with Self do inherited DoIt;',
   'end;',
   'begin',
    '']);