Răsfoiți Sursa

* don't allow skipping property parameters if the getter/setter has default
parameters (mantis #13956)
* when reporting an error about too few specified parameters to a call,
return the column of the call itself rather than after the last parameter
(because this ends up after the end of an indexed property in case of
properties, which is confusing)

git-svn-id: trunk@13326 -

Jonas Maebe 16 ani în urmă
părinte
comite
e42842b31c
4 a modificat fișierele cu 42 adăugiri și 12 ștergeri
  1. 1 0
      .gitattributes
  2. 17 8
      compiler/htypechk.pas
  3. 2 4
      compiler/ncal.pas
  4. 22 0
      tests/webtbf/tw13956.pp

+ 1 - 0
.gitattributes

@@ -8605,6 +8605,7 @@ tests/webtbf/tw13563a.pp svneol=native#text/plain
 tests/webtbf/tw1365.pp svneol=native#text/plain
 tests/webtbf/tw1365.pp svneol=native#text/plain
 tests/webtbf/tw13815.pp svneol=native#text/plain
 tests/webtbf/tw13815.pp svneol=native#text/plain
 tests/webtbf/tw1395.pp svneol=native#text/plain
 tests/webtbf/tw1395.pp svneol=native#text/plain
+tests/webtbf/tw13956.pp svneol=native#text/plain
 tests/webtbf/tw13992.pp svneol=native#text/plain
 tests/webtbf/tw13992.pp svneol=native#text/plain
 tests/webtbf/tw1407.pp svneol=native#text/plain
 tests/webtbf/tw1407.pp svneol=native#text/plain
 tests/webtbf/tw1432.pp svneol=native#text/plain
 tests/webtbf/tw1432.pp svneol=native#text/plain

+ 17 - 8
compiler/htypechk.pas

@@ -68,10 +68,10 @@ interface
         FAllowVariant : boolean;
         FAllowVariant : boolean;
         procedure collect_overloads_in_class(ProcdefOverloadList:TFPObjectList);
         procedure collect_overloads_in_class(ProcdefOverloadList:TFPObjectList);
         procedure collect_overloads_in_units(ProcdefOverloadList:TFPObjectList);
         procedure collect_overloads_in_units(ProcdefOverloadList:TFPObjectList);
-        procedure create_candidate_list(ignorevisibility:boolean);
+        procedure create_candidate_list(ignorevisibility,allowdefaultparas:boolean);
         function  proc_add(ps:tprocsym;pd:tprocdef):pcandidate;
         function  proc_add(ps:tprocsym;pd:tprocdef):pcandidate;
       public
       public
-        constructor create(sym:tprocsym;st:TSymtable;ppn:tnode;ignorevisibility:boolean);
+        constructor create(sym:tprocsym;st:TSymtable;ppn:tnode;ignorevisibility,allowdefaultparas:boolean);
         constructor create_operator(op:ttoken;ppn:tnode);
         constructor create_operator(op:ttoken;ppn:tnode);
         destructor destroy;override;
         destructor destroy;override;
         procedure list(all:boolean);
         procedure list(all:boolean);
@@ -1613,7 +1613,7 @@ implementation
                            TCallCandidates
                            TCallCandidates
 ****************************************************************************}
 ****************************************************************************}
 
 
-    constructor tcallcandidates.create(sym:tprocsym;st:TSymtable;ppn:tnode;ignorevisibility:boolean);
+    constructor tcallcandidates.create(sym:tprocsym;st:TSymtable;ppn:tnode;ignorevisibility,allowdefaultparas:boolean);
       begin
       begin
         if not assigned(sym) then
         if not assigned(sym) then
           internalerror(200411015);
           internalerror(200411015);
@@ -1621,7 +1621,7 @@ implementation
         FProcsym:=sym;
         FProcsym:=sym;
         FProcsymtable:=st;
         FProcsymtable:=st;
         FParanode:=ppn;
         FParanode:=ppn;
-        create_candidate_list(ignorevisibility);
+        create_candidate_list(ignorevisibility,allowdefaultparas);
       end;
       end;
 
 
 
 
@@ -1631,7 +1631,7 @@ implementation
         FProcsym:=nil;
         FProcsym:=nil;
         FProcsymtable:=nil;
         FProcsymtable:=nil;
         FParanode:=ppn;
         FParanode:=ppn;
-        create_candidate_list(false);
+        create_candidate_list(false,false);
       end;
       end;
 
 
 
 
@@ -1744,7 +1744,7 @@ implementation
       end;
       end;
 
 
 
 
-    procedure tcallcandidates.create_candidate_list(ignorevisibility:boolean);
+    procedure tcallcandidates.create_candidate_list(ignorevisibility,allowdefaultparas:boolean);
       var
       var
         j     : integer;
         j     : integer;
         pd    : tprocdef;
         pd    : tprocdef;
@@ -1803,8 +1803,17 @@ implementation
               it is visible }
               it is visible }
             if (FParalength>=pd.minparacount) and
             if (FParalength>=pd.minparacount) and
                (
                (
-                (FParalength<=pd.maxparacount) or
-                (po_varargs in pd.procoptions)
+                (
+                 allowdefaultparas and
+                 (
+                  (FParalength<=pd.maxparacount) or
+                  (po_varargs in pd.procoptions)
+                 )
+                ) or
+                (
+                 not allowdefaultparas and
+                 (FParalength=pd.maxparacount)
+                )
                ) and
                ) and
                (
                (
                 ignorevisibility or
                 ignorevisibility or

+ 2 - 4
compiler/ncal.pas

@@ -2330,7 +2330,7 @@ implementation
                   { ignore possible private for properties or in delphi mode for anon. inherited (FK) }
                   { ignore possible private for properties or in delphi mode for anon. inherited (FK) }
                   ignorevisibility:=(nf_isproperty in flags) or
                   ignorevisibility:=(nf_isproperty in flags) or
                                     ((m_delphi in current_settings.modeswitches) and (cnf_anon_inherited in callnodeflags));
                                     ((m_delphi in current_settings.modeswitches) and (cnf_anon_inherited in callnodeflags));
-                  candidates:=tcallcandidates.create(symtableprocentry,symtableproc,left,ignorevisibility);
+                  candidates:=tcallcandidates.create(symtableprocentry,symtableproc,left,ignorevisibility,not(nf_isproperty in flags));
 
 
                    { no procedures found? then there is something wrong
                    { no procedures found? then there is something wrong
                      with the parameter size or the procedures are
                      with the parameter size or the procedures are
@@ -2369,9 +2369,7 @@ implementation
                             end
                             end
                           else
                           else
                             begin
                             begin
-                              if assigned(left) then
-                               current_filepos:=left.fileinfo;
-                              CGMessage1(parser_e_wrong_parameter_size,symtableprocentry.realname);
+                              CGMessagePos1(fileinfo,parser_e_wrong_parameter_size,symtableprocentry.realname);
                               symtableprocentry.write_parameter_lists(nil);
                               symtableprocentry.write_parameter_lists(nil);
                             end;
                             end;
                         end;
                         end;

+ 22 - 0
tests/webtbf/tw13956.pp

@@ -0,0 +1,22 @@
+{ %fail }
+
+{$ifdef fpc}
+{$mode objfpc}{$H+}
+{$endif}
+
+type
+  { TForm1 }
+  TForm1 = class
+  private
+    function GetFoo(Index: Integer; Ask: Boolean = True): Integer;
+  public
+    property Foo[Index: Integer; Ask: Boolean]: Integer read GetFoo;
+  end; 
+
+function TForm1.GetFoo(Index: Integer; Ask: Boolean): Integer;
+begin
+  Result := Foo[Index];
+end;
+
+begin
+end.