Browse Source

* give an error if the number of formal parameters of an obj-c method
does not match the number of colons in the message name

git-svn-id: branches/objc@13668 -

Jonas Maebe 16 years ago
parent
commit
bcfcf30e04
3 changed files with 46 additions and 2 deletions
  1. 1 0
      .gitattributes
  2. 17 2
      compiler/symdef.pas
  3. 28 0
      tests/test/tobjc16.pp

+ 1 - 0
.gitattributes

@@ -8223,6 +8223,7 @@ tests/test/tobjc12.pp svneol=native#text/plain
 tests/test/tobjc13.pp svneol=native#text/plain
 tests/test/tobjc14.pp svneol=native#text/plain
 tests/test/tobjc15.pp svneol=native#text/plain
+tests/test/tobjc16.pp svneol=native#text/plain
 tests/test/tobjc2.pp svneol=native#text/plain
 tests/test/tobjc3.pp svneol=native#text/plain
 tests/test/tobjc4.pp svneol=native#text/plain

+ 17 - 2
compiler/symdef.pas

@@ -4385,7 +4385,8 @@ implementation
       var
         def: tdef absolute data;
         pd: tprocdef absolute data;
-        i: longint;
+        i,
+        paracount: longint;
       begin
         if (def.typ=procdef) then
           begin
@@ -4397,7 +4398,21 @@ implementation
                 { Mangled name is already set in case this is a copy of
                   another type.  }
                 if not(po_has_mangledname in pd.procoptions) then
-                  pd.setmangledname(pd.objcmangledname)
+                  begin
+                    { check whether the number of formal parameters is correct }
+                    paracount:=0;
+                    for i:=1 to length(pd.messageinf.str^) do
+                      if pd.messageinf.str^[i]=':' then
+                        inc(paracount);
+                    for i:=0 to pd.paras.count-1 do
+                      if not(vo_is_hidden_para in tparavarsym(pd.paras[i]).varoptions) and
+                         not is_array_of_const(tparavarsym(pd.paras[i]).vardef) then
+                        dec(paracount);
+                    if (paracount<>0) then
+                      MessagePos(pd.fileinfo,sym_e_objc_para_mismatch);
+
+                    pd.setmangledname(pd.objcmangledname);
+                  end
                 else
                   { all checks already done }
                   exit;

+ 28 - 0
tests/test/tobjc16.pp

@@ -0,0 +1,28 @@
+{ %fail }
+{ %opt=-vh -Seh }
+{ %target=darwin }
+{ %cpu=powerpc,i386 }
+
+{$modeswitch objectivec1}
+
+type
+  ta = objcclass
+    { should give an error about a wrong number of parameters --
+      the message name suggests two parameters, but the procedure
+      has only one. }
+    procedure test(a: longint); message 'test:a:';
+  end; external;
+
+var
+  a: ta;
+  b: nsobject;
+  c: id;
+begin
+  { avoid hints about unused types/variables/units }
+  a:=nil;
+  if (a<>nil) then
+    exit;
+  c:=nil;
+  b:=c;
+  b.isEqual_(b);
+end.