Răsfoiți Sursa

Fix for Mantis #25915.

* ptype.pas, id_type:
    generate the "identifier not found" message only if the identifier was really not found and not when the identifier is a non-type
* pexpr.pas, statement_syssym: 
    don't generate the "type id expected" error message for Default() anymore; this is already handled by single_type

+ added test (though this again will not help much as output is not parsed...)

git-svn-id: trunk@27464 -
svenbarth 11 ani în urmă
părinte
comite
b9a59c33f4
2 a modificat fișierele cu 17 adăugiri și 7 ștergeri
  1. 2 3
      compiler/pexpr.pas
  2. 15 4
      compiler/ptype.pas

+ 2 - 3
compiler/pexpr.pas

@@ -877,9 +877,8 @@ implementation
               def:=nil;
               single_type(def,[stoAllowSpecialization]);
               statement_syssym:=cerrornode.create;
-              if def=generrordef then
-                Message(type_e_type_id_expected)
-              else
+              if def<>generrordef then
+                { "type expected" error is already done by single_type }
                 if def.typ=forwarddef then
                   Message1(type_e_type_is_not_completly_defined,tforwarddef(def).tosymname^)
                 else

+ 15 - 4
compiler/ptype.pas

@@ -300,7 +300,7 @@ implementation
     { to a appropriating tdef, s gets the name of   }
     { the type to allow name mangling          }
       var
-        is_unit_specific : boolean;
+        is_unit_specific,not_a_type : boolean;
         pos : tfileposinfo;
         s,sorg : TIDString;
         t : ttoken;
@@ -316,10 +316,21 @@ implementation
             try_parse_structdef_nested_type(def,current_structdef,isforwarddef) then
            exit;
          { Use the special searchsym_type that search only types }
-         searchsym_type(s,srsym,srsymtable);
+         if not searchsym_type(s,srsym,srsymtable) then
+           { for a good error message we need to know whether the symbol really did not exist or
+             whether we found a non-type one }
+           not_a_type:=searchsym(s,srsym,srsymtable)
+         else
+           not_a_type:=false;
          { handle unit specification like System.Writeln }
          is_unit_specific:=try_consume_unitsym(srsym,srsymtable,t,true);
          consume(t);
+         if not_a_type then
+           begin
+             { reset the symbol and symtable to not leak any unexpected values }
+             srsym:=nil;
+             srsymtable:=nil;
+           end;
          { Types are first defined with an error def before assigning
            the real type so check if it's an errordef. if so then
            give an error. Only check for typesyms in the current symbol
@@ -343,14 +354,14 @@ implementation
              exit;
            end;
          { unknown sym ? }
-         if not assigned(srsym) then
+         if not assigned(srsym) and not not_a_type then
           begin
             Message1(sym_e_id_not_found,sorg);
             def:=generrordef;
             exit;
           end;
          { type sym ? }
-         if (srsym.typ<>typesym) then
+         if not_a_type or (srsym.typ<>typesym) then
           begin
             Message(type_e_type_id_expected);
             def:=generrordef;