Răsfoiți Sursa

* fixed support for repeating constructor without parameters in Delphi
mode + test

git-svn-id: trunk@5692 -

Jonas Maebe 18 ani în urmă
părinte
comite
a63ed25f74
4 a modificat fișierele cu 29 adăugiri și 5 ștergeri
  1. 1 0
      .gitattributes
  2. 10 0
      compiler/defutil.pas
  3. 4 5
      compiler/pdecsub.pas
  4. 14 0
      tests/tbs/tb0518.pp

+ 1 - 0
.gitattributes

@@ -6239,6 +6239,7 @@ tests/tbs/tb0514.pp svneol=native#text/plain
 tests/tbs/tb0515.pp svneol=native#text/plain
 tests/tbs/tb0516.pp svneol=native#text/plain
 tests/tbs/tb0517.pp svneol=native#text/plain
+tests/tbs/tb0518.pp svneol=native#text/plain
 tests/tbs/ub0060.pp svneol=native#text/plain
 tests/tbs/ub0069.pp svneol=native#text/plain
 tests/tbs/ub0119.pp svneol=native#text/plain

+ 10 - 0
compiler/defutil.pas

@@ -230,6 +230,9 @@ interface
     {# returns true, if the type passed is a varset }
     function is_varset(p : tdef) : boolean;
 
+    { # returns true if the procdef has no parameters and no specified return type }
+    function is_bareprocdef(pd : tprocdef): boolean;
+
 implementation
 
     uses
@@ -1018,4 +1021,11 @@ implementation
       end;
 
 
+    function is_bareprocdef(pd : tprocdef): boolean;
+      begin
+        result:=(pd.maxparacount=0) and
+                (is_void(pd.returndef) or
+                 (pd.proctypeoption = potype_constructor));
+      end;
+
 end.

+ 4 - 5
compiler/pdecsub.pas

@@ -2431,7 +2431,7 @@ const
               (
                not(m_repeat_forward in current_settings.modeswitches) and
                not(currpd.forwarddef) and
-               (currpd.maxparacount=0) and
+               is_bareprocdef(currpd) and
                not(po_overload in fwpd.procoptions)
               ) or
               { check arguments, we need to check only the user visible parameters. The hidden parameters
@@ -2455,12 +2455,12 @@ const
                  begin
                    forwardfound:=true;
 
-                   if (m_repeat_forward in current_settings.modeswitches) or
+                   if not(m_repeat_forward in current_settings.modeswitches) and
                       (fwpd.proccalloption<>currpd.proccalloption) then
                      paracompopt:=[cpo_ignorehidden,cpo_comparedefaultvalue]
                    else
                      paracompopt:=[cpo_comparedefaultvalue];
-
+ 
                    { Check calling convention }
                    if (fwpd.proccalloption<>currpd.proccalloption) then
                     begin
@@ -2495,8 +2495,7 @@ const
                    { Check if the procedure type and return type are correct,
                      also the parameters must match also with the type }
                    if ((m_repeat_forward in current_settings.modeswitches) or
-                       (currpd.maxparacount<>0) or
-                       (not(is_void(currpd.returndef)))) and
+                       not is_bareprocdef(currpd)) and
                       ((compare_paras(currpd.paras,fwpd.paras,cp_all,paracompopt)<te_equal) or
                        (not equal_defs(fwpd.returndef,currpd.returndef))) then
                      begin

+ 14 - 0
tests/tbs/tb0518.pp

@@ -0,0 +1,14 @@
+{$mode delphi}
+type
+  tc = class
+    constructor create(const n: ansistring);
+  end;
+
+constructor tc.create;
+begin
+  if (n <> 'abc') then halt(1);
+end;
+
+begin
+  tc.create('abc');
+end.