浏览代码

* apply slightly adjusted patch by Blaise.ru which moves parsing of result types to a separate functions thus ensuring that File types can't be used for procedure variables (just like they already couldn't be used as a result type for normal functions)
+ added test

git-svn-id: trunk@47810 -

svenbarth 4 年之前
父节点
当前提交
2a897f5b6b
共有 4 个文件被更改,包括 21 次插入6 次删除
  1. 1 0
      .gitattributes
  2. 1 5
      compiler/pdecsub.pas
  3. 11 1
      compiler/ptype.pas
  4. 8 0
      tests/tbf/tb0273.pp

+ 1 - 0
.gitattributes

@@ -12735,6 +12735,7 @@ tests/tbf/tb0269.pp svneol=native#text/pascal
 tests/tbf/tb0270.pp svneol=native#text/pascal
 tests/tbf/tb0271.pp svneol=native#text/pascal
 tests/tbf/tb0272.pp svneol=native#text/plain
+tests/tbf/tb0273.pp svneol=native#text/pascal
 tests/tbf/tb0588.pp svneol=native#text/pascal
 tests/tbf/ub0115.pp svneol=native#text/plain
 tests/tbf/ub0149.pp svneol=native#text/plain

+ 1 - 5
compiler/pdecsub.pas

@@ -1344,7 +1344,7 @@ implementation
             parse_generic:=(df_generic in pd.defoptions);
             if pd.is_generic or pd.is_specialization then
               symtablestack.push(pd.parast);
-            single_type(pd.returndef,[stoAllowSpecialization]);
+            pd.returndef:=result_type([stoAllowSpecialization]);
 
             // Issue #24863, enabled only for the main progra commented out for now because it breaks building of RTL and needs extensive
 // testing and/or RTL patching.
@@ -1555,10 +1555,6 @@ implementation
             include(pd.procoptions,po_variadic);
           end;
 
-        { file types can't be function results }
-        if assigned(pd) and
-           (pd.returndef.typ=filedef) then
-          message(parser_e_illegal_function_result);
         { support procedure proc stdcall export; }
         if not(check_proc_directive(false)) then
           begin

+ 11 - 1
compiler/ptype.pas

@@ -42,6 +42,8 @@ interface
 
     { reads a string, file type or a type identifier }
     procedure single_type(out def:tdef;options:TSingleTypeOptions);
+    { ... but rejects types that cannot be returned from functions }
+    function result_type(options:TSingleTypeOptions):tdef;
 
     { reads any type declaration, where the resulting type will get name as type identifier }
     procedure read_named_type(var def:tdef;const newsym:tsym;genericdef:tstoreddef;genericlist:tfphashobjectlist;parseprocvardir:boolean;var hadtypetoken:boolean);
@@ -645,6 +647,14 @@ implementation
       end;
 
 
+    function result_type(options:TSingleTypeOptions):tdef;
+      begin
+        single_type(result,options);
+        { file types cannot be function results }
+        if result.typ=filedef then
+          message(parser_e_illegal_function_result);
+      end;
+
     procedure parse_record_members(recsym:tsym);
 
       function IsAnonOrLocal: Boolean;
@@ -1587,7 +1597,7 @@ implementation
             if is_func then
               begin
                 consume(_COLON);
-                single_type(pd.returndef,[stoAllowSpecialization]);
+                pd.returndef:=result_type([stoAllowSpecialization]);
               end;
             if try_to_consume(_OF) then
               begin

+ 8 - 0
tests/tbf/tb0273.pp

@@ -0,0 +1,8 @@
+{ %FAIL }
+
+// EXPECTED: 'Error: Illegal function result type'
+// ACTUAL: gets compiled
+type M = function : file;
+
+begin
+end.