Pārlūkot izejas kodu

* give a warning instead of an error if a parameter or local variable in a
an Objective-C method masks an identifier from a category, because due
to the fact that all standard categories are imported at the same time via
the CocoaAll unit, this can often happen with categories you don't know/
care about. These errors also didn't happen in 2.6.x

git-svn-id: trunk@29497 -

Jonas Maebe 10 gadi atpakaļ
vecāks
revīzija
990e47f2d3
7 mainītis faili ar 323 papildinājumiem un 255 dzēšanām
  1. 2 0
      .gitattributes
  2. 6 1
      compiler/msg/errore.msg
  3. 3 2
      compiler/msgidx.inc
  4. 245 243
      compiler/msgtxt.inc
  5. 20 9
      compiler/symtable.pas
  6. 24 0
      tests/test/tobjc41.pp
  7. 23 0
      tests/test/uobjc41.pp

+ 2 - 0
.gitattributes

@@ -11937,6 +11937,7 @@ tests/test/tobjc38.pp svneol=native#text/plain
 tests/test/tobjc39.pp svneol=native#text/plain
 tests/test/tobjc4.pp svneol=native#text/plain
 tests/test/tobjc40.pp svneol=native#text/plain
+tests/test/tobjc41.pp svneol=native#text/plain
 tests/test/tobjc4a.pp svneol=native#text/plain
 tests/test/tobjc5.pp svneol=native#text/plain
 tests/test/tobjc5a.pp svneol=native#text/plain
@@ -12619,6 +12620,7 @@ tests/test/uobjc35e.pp svneol=native#text/plain
 tests/test/uobjc35f.pp svneol=native#text/plain
 tests/test/uobjc35g.pp svneol=native#text/plain
 tests/test/uobjc39.pp svneol=native#text/plain
+tests/test/uobjc41.pp svneol=native#text/plain
 tests/test/uobjc7.pp svneol=native#text/plain
 tests/test/uobjcl1.pp svneol=native#text/plain
 tests/test/uprec6.pp svneol=native#text/plain

+ 6 - 1
compiler/msg/errore.msg

@@ -1972,7 +1972,7 @@ type_w_instance_abstract_class=04122_W_Creating an instance of abstract class "$
 #
 # Symtable
 #
-# 05087 is the last used one
+# 05095 is the last used one
 #
 % \section{Symbol handling}
 % This section lists all the messages that concern the handling of symbols.
@@ -2276,6 +2276,11 @@ sym_h_managed_function_result_uninitialized=05094_H_Function result variable of
 % before it is initialized (i.e. it appears in the left-hand side of an
 % assignment). Since the variable is managed, i. e. implicitly initialized by the compiler, this might be intended behaviour and
 % does not necessarily mean that the code is wrong.
+sym_w_duplicate_id=05095_W_Duplicate identifier "$1"
+% The identifier was already declared in an Objective-C category that's in the
+% same scope as the current identifier. This is a warning instead of an error,
+% because while this hides the identifier from the category, there are often
+% many unused categories in scope.
 % \end{description}
 #
 # Codegenerator

+ 3 - 2
compiler/msgidx.inc

@@ -635,6 +635,7 @@ const
   sym_h_uninitialized_managed_variable=05092;
   sym_w_managed_function_result_uninitialized=05093;
   sym_h_managed_function_result_uninitialized=05094;
+  sym_w_duplicate_id=05095;
   cg_e_parasize_too_big=06009;
   cg_e_file_must_call_by_reference=06012;
   cg_e_cant_use_far_pointer_there=06013;
@@ -1003,9 +1004,9 @@ const
   option_info=11024;
   option_help_pages=11025;
 
-  MsgTxtSize = 74687;
+  MsgTxtSize = 74721;
 
   MsgIdxMax : array[1..20] of longint=(
-    26,99,340,123,95,57,126,29,202,64,
+    26,99,340,123,96,57,126,29,202,64,
     58,20,1,1,1,1,1,1,1,1
   );

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 245 - 243
compiler/msgtxt.inc


+ 20 - 9
compiler/symtable.pas

@@ -229,7 +229,7 @@ interface
     function generate_objectpascal_helper_key(def:tdef):string;
     procedure incompatibletypes(def1,def2:tdef);
     procedure hidesym(sym:TSymEntry);
-    procedure duplicatesym(var hashedid:THashedIDString;dupsym,origsym:TSymEntry);
+    procedure duplicatesym(var hashedid: THashedIDString; dupsym, origsym:TSymEntry; warn: boolean);
     function handle_generic_dummysym(sym:TSymEntry;var symoptions:tsymoptions):boolean;
     function get_jumpbuf_size : longint;
 
@@ -630,7 +630,7 @@ implementation
       begin
         hsym:=tsym(FindWithHash(hashedid));
         if assigned(hsym) then
-          DuplicateSym(hashedid,sym,hsym);
+          DuplicateSym(hashedid,sym,hsym,false);
         result:=assigned(hsym);
       end;
 
@@ -1461,7 +1461,8 @@ implementation
 
     function tObjectSymtable.checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;
       var
-         hsym : tsym;
+         hsym: tsym;
+         warn: boolean;
       begin
          result:=false;
          if not assigned(defowner) then
@@ -1492,7 +1493,14 @@ implementation
                   )
                  ) then
                 begin
-                  DuplicateSym(hashedid,sym,hsym);
+                  { only watn when a parameter/local variable in a method
+                    conflicts with a category method, because this can easily
+                    happen due to all possible categories being imported via
+                    CocoaAll }
+                  warn:=
+                    is_objccategory(tdef(hsym.owner.defowner)) and
+                    (sym.typ in [paravarsym,localvarsym]);
+                  DuplicateSym(hashedid,sym,hsym,warn);
                   result:=true;
                 end;
            end
@@ -1571,7 +1579,7 @@ implementation
                    (vo_is_result in tabstractvarsym(hsym).varoptions)) then
               HideSym(hsym)
             else
-              DuplicateSym(hashedid,sym,hsym);
+              DuplicateSym(hashedid,sym,hsym,false);
             result:=true;
             exit;
           end;
@@ -1591,7 +1599,7 @@ implementation
                    (vo_is_result in tabstractvarsym(sym).varoptions)) then
               Hidesym(sym)
             else
-              DuplicateSym(hashedid,sym,hsym);
+              DuplicateSym(hashedid,sym,hsym,false);
             result:=true;
             exit;
           end;
@@ -1697,7 +1705,7 @@ implementation
                   tnamespacesym(sym).unitsym:=tsym(hsym);
               end
             else
-              DuplicateSym(hashedid,sym,hsym);
+              DuplicateSym(hashedid,sym,hsym,false);
             result:=true;
             exit;
           end;
@@ -2040,12 +2048,15 @@ implementation
       end;
 
 
-    procedure duplicatesym(var hashedid:THashedIDString;dupsym,origsym:TSymEntry);
+    procedure duplicatesym(var hashedid: THashedIDString; dupsym, origsym: TSymEntry; warn: boolean);
       var
         st : TSymtable;
         filename : TIDString;
       begin
-        Message1(sym_e_duplicate_id,tsym(origsym).realname);
+        if not warn then
+          Message1(sym_e_duplicate_id,tsym(origsym).realname)
+        else
+         Message1(sym_w_duplicate_id,tsym(origsym).realname);
         { Write hint where the original symbol was found }
         st:=finduniTSymtable(origsym.owner);
         with tsym(origsym).fileinfo do

+ 24 - 0
tests/test/tobjc41.pp

@@ -0,0 +1,24 @@
+{ %target=darwin }
+{ %fail }
+{ %opt=-Sew }
+
+{$mode objfpc}
+{$modeswitch objectivec2}
+
+uses
+  uobjc41;
+
+type
+	NSDictionaryUtilities = objccategory (NSSubject)
+           { the "key" paramter should give a warning because there's already a "key"
+             message in a category for NSObject }
+		function containsKey (key: NSString): boolean; message 'containsKey:';
+	end;
+
+function NSDictionaryUtilities.containsKey (key: NSString): boolean;
+begin
+  result:=false;
+end;
+
+begin
+end.

+ 23 - 0
tests/test/uobjc41.pp

@@ -0,0 +1,23 @@
+{$mode objfpc}
+{$modeswitch objectivec2}
+
+unit uobjc41;
+
+interface
+
+type
+  NSSubject = objcclass(NSObject)
+  end;
+
+  MyCategory = objccategory(NSObject)
+    procedure key; message 'key';
+  end;
+
+implementation
+
+procedure MyCategory.key;
+begin
+end;
+
+begin
+end.

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels