Browse Source

compiler: don't output an error twice in 'on Exception do' block if Exception is not a valid type

git-svn-id: trunk@25419 -
paul 12 years ago
parent
commit
d25ae84113
1 changed files with 14 additions and 10 deletions
  1. 14 10
      compiler/pstatmnt.pas

+ 14 - 10
compiler/pstatmnt.pas

@@ -825,6 +825,18 @@ implementation
 
 
 
 
     function try_statement : tnode;
     function try_statement : tnode;
+
+      procedure check_type_valid(var def: tdef);
+        begin
+           if not (is_class(def) or is_javaclass(def) or
+              { skip showing error message the second time }
+              (def.typ=errordef)) then
+             begin
+               Message1(type_e_class_type_expected,def.typename);
+               def:=generrordef;
+             end;
+        end;
+
       var
       var
          p_try_block,p_finally_block,first,last,
          p_try_block,p_finally_block,first,last,
          p_default,p_specific,hp : tnode;
          p_default,p_specific,hp : tnode;
@@ -901,11 +913,7 @@ implementation
                           if try_to_consume(_COLON) then
                           if try_to_consume(_COLON) then
                             begin
                             begin
                               single_type(ot,[]);
                               single_type(ot,[]);
-                              if not (is_class(ot) or is_javaclass(ot)) then
-                                begin
-                                  Message1(type_e_class_type_expected,ot.typename);
-                                  ot:=generrordef;
-                                end;
+                              check_type_valid(ot);
                               sym:=tlocalvarsym.create(objrealname,vs_value,ot,[]);
                               sym:=tlocalvarsym.create(objrealname,vs_value,ot,[]);
                             end
                             end
                           else
                           else
@@ -928,11 +936,7 @@ implementation
                                  begin
                                  begin
                                    ot:=ttypesym(srsym).typedef;
                                    ot:=ttypesym(srsym).typedef;
                                    parse_nested_types(ot,false,nil);
                                    parse_nested_types(ot,false,nil);
-                                   if not (is_class(ot) or is_javaclass(ot)) then
-                                     begin
-                                       Message1(type_e_class_type_expected,ot.typename);
-                                       ot:=generrordef;
-                                     end;
+                                   check_type_valid(ot);
                                  end
                                  end
                                else
                                else
                                  begin
                                  begin