Browse Source

* automatically try to call procvars that are subscripted or used in a
with-statement, both in FPC and TP/Delphi modes (mantis #15728)

git-svn-id: trunk@14881 -

Jonas Maebe 15 years ago
parent
commit
d60e1f674c
4 changed files with 44 additions and 0 deletions
  1. 1 0
      .gitattributes
  2. 4 0
      compiler/pexpr.pas
  3. 4 0
      compiler/pstatmnt.pas
  4. 35 0
      tests/webtbs/tw15728.pp

+ 1 - 0
.gitattributes

@@ -10281,6 +10281,7 @@ tests/webtbs/tw1567.pp svneol=native#text/plain
 tests/webtbs/tw15690.pp svneol=native#text/plain
 tests/webtbs/tw15693.pp svneol=native#text/plain
 tests/webtbs/tw15694.pp svneol=native#text/plain
+tests/webtbs/tw15728.pp svneol=native#text/plain
 tests/webtbs/tw1573.pp svneol=native#text/plain
 tests/webtbs/tw1592.pp svneol=native#text/plain
 tests/webtbs/tw1617.pp svneol=native#text/plain

+ 4 - 0
compiler/pexpr.pas

@@ -2028,6 +2028,10 @@ implementation
                         p1:=cderefnode.create(p1);
                         do_typecheckpass(p1);
                       end;
+                    { procvar.<something> can never mean anything so always
+                      try to call it in case it returns a record/object/... }
+                    maybe_call_procvar(p1,false);
+
                     case p1.resultdef.typ of
                       recorddef:
                         begin

+ 4 - 0
compiler/pstatmnt.pas

@@ -548,6 +548,10 @@ implementation
          if (p.nodetype=vecn) and
             (nf_memseg in p.flags) then
            CGMessage(parser_e_no_with_for_variable_in_other_segments);
+         
+         { "with procvar" can never mean anything, so always try
+           to call it in case it returns a record/object/... }
+         maybe_call_procvar(p,false);
 
          if (p.resultdef.typ in [objectdef,recorddef,classrefdef]) then
           begin

+ 35 - 0
tests/webtbs/tw15728.pp

@@ -0,0 +1,35 @@
+program TT;
+
+{$mode delphi}
+
+uses
+  SysUtils;
+
+type
+  t_R = record
+   R1:integer;
+  end;
+
+t_X = function:t_R;
+
+function A:t_R;
+  begin
+    Result.R1:=123;
+  end;
+
+var X:t_X;
+
+begin
+  X:=A;
+  if x.r1<>123 then
+    halt(1);
+  writeln(X.R1); // Error: Illegal qualifier
+  writeln(X().R1); // OK
+  with X do
+    begin
+      if r1<>123 then
+        halt(2);
+      writeln(R1); //Error: Expression type must be class or record 
+    end;
+  with X() do writeln(R1); // OK
+end.