Jelajahi Sumber

* fixed type compatibility checking for classrefs and id
* modified test for this

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

Jonas Maebe 16 tahun lalu
induk
melakukan
5128a6726c
2 mengubah file dengan 19 tambahan dan 5 penghapusan
  1. 12 5
      compiler/defcmp.pas
  2. 7 0
      tests/test/tobjc18.pp

+ 12 - 5
compiler/defcmp.pas

@@ -1084,10 +1084,10 @@ implementation
                        end
                      { id = generic class instance. metaclasses are also
                        class instances themselves.  }
-                     else if ((def_from=objc_idtype) or
-                              (def_to=objc_metaclasstype)) and
-                             ((def_to=objc_idtype) or
-                              (def_to=objc_metaclasstype)) then
+                     else if ((def_from=objc_idtype) and
+                              (def_to=objc_metaclasstype)) or
+                             ((def_to=objc_idtype) and
+                              (def_from=objc_metaclasstype)) then
                        begin
                          doconv:=tc_equal;
                          eq:=te_convert_l2;
@@ -1361,7 +1361,14 @@ implementation
                  begin
                    doconv:=tc_equal;
                    eq:=te_convert_l1;
-                 end;
+                 end
+               else
+                 { id is compatible with all classref types }
+                 if (def_from=objc_idtype) then
+                   begin
+                     doconv:=tc_equal;
+                     eq:=te_convert_l1;
+                   end;
              end;
 
            filedef :

+ 7 - 0
tests/test/tobjc18.pp

@@ -65,7 +65,14 @@ end;
 
 var
   a: MyOverride;
+  b: id;
 begin
+  { test type compatibility conversions between id and class ref }
+  b:=MyOverride2;
+  selfshouldbetestinlinetypedefinition:=b;
+  b:=selfshouldbetestinlinetypedefinition;
+
+  { tested calling class methods and inherited class methods }
   a:=MyOverride2.alloc;
   a:=a.init;
   selfshouldbe:=MyOverride2;