Преглед изворни кода

+ support procvar[] in tp/mac procvar mode if the procvar returns an array type

florian пре 2 година
родитељ
комит
ec28b7586c
2 измењених фајлова са 35 додато и 1 уклоњено
  1. 12 1
      compiler/pexpr.pas
  2. 23 0
      tests/tbs/tb0703.pp

+ 12 - 1
compiler/pexpr.pas

@@ -2184,7 +2184,7 @@ implementation
              begin
                consume(_CARET);
 
-               { support tp/mac procvar^ if the procvar returns a
+               { support in tp/mac procvar mode procvar^ if the procvar returns a
                  pointer type }
                if ((m_tp_procvar in current_settings.modeswitches) or
                    (m_mac_procvar in current_settings.modeswitches)) and
@@ -2230,6 +2230,17 @@ implementation
 
           _LECKKLAMMER:
              begin
+               { support in tp/mac procvar mode procvar[] if the procvar returns an
+                 array type }
+               if ((m_tp_procvar in current_settings.modeswitches) or
+                   (m_mac_procvar in current_settings.modeswitches)) and
+                  (p1.resultdef.typ=procvardef) and
+                  (tprocvardef(p1.resultdef).returndef.typ=arraydef) then
+                 begin
+                   p1:=ccallnode.create_procvar(nil,p1);
+                   typecheckpass(p1);
+                 end;
+
                if is_class_or_interface_or_object(p1.resultdef) or
                   is_dispinterface(p1.resultdef) or
                   is_record(p1.resultdef) or

+ 23 - 0
tests/tbs/tb0703.pp

@@ -0,0 +1,23 @@
+
+{$mode delphi}
+uses
+  Types;
+
+type
+  TArrayFunc = function: TIntegerDynArray;
+
+function MyFunc : TIntegerDynArray;
+  begin
+    SetLength(Result,1);
+    Result[0]:=$12345678;
+  end;
+
+var
+  f: TArrayFunc;
+  i: integer;
+begin
+ f := @MyFunc;
+ i := f[0];
+ if i<>$12345678 then
+   halt(1);
+end.