Browse Source

obcpas: fix categories implementing protocols

Allocate the ImplementedInterfaces array for them and save to/load from ppu

Solves #39375
Jonas Maebe 3 years ago
parent
commit
fcb646bc3b
3 changed files with 34 additions and 3 deletions
  1. 1 1
      compiler/ppu.pas
  2. 2 2
      compiler/symdef.pas
  3. 31 0
      tests/webtbs/tw39375.pp

+ 1 - 1
compiler/ppu.pas

@@ -48,7 +48,7 @@ const
   CurrentPPUVersion = 208;
   { for any other changes to the ppu format, increase this version number
     (it's a cardinal) }
-  CurrentPPULongVersion = 13;
+  CurrentPPULongVersion = 14;
 
 { unit flags }
   uf_big_endian          = $000004;

+ 2 - 2
compiler/symdef.pas

@@ -7431,7 +7431,7 @@ implementation
         if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
           prepareguid;
         { setup implemented interfaces }
-        if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
+        if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_objccategory,odt_javaclass,odt_interfacejava] then
           ImplementedInterfaces:=TFPObjectList.Create(true)
         else
           ImplementedInterfaces:=nil;
@@ -7489,7 +7489,7 @@ implementation
            end;
 
          { load implemented interfaces }
-         if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
+         if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_objccategory,odt_javaclass,odt_interfacejava] then
            begin
              ImplementedInterfaces:=TFPObjectList.Create(true);
              implintfcount:=ppufile.getlongint;

+ 31 - 0
tests/webtbs/tw39375.pp

@@ -0,0 +1,31 @@
+{ %target=darwin,ios,iphonesim }
+
+program Project1;
+{$mode objfpc}{$H+}
+{$ModeSwitch objectivec1}
+type
+CBCentralManager = pointer;
+CBCentralManagerDelegateProtocol = objcprotocol external
+  procedure centralManagerDidUpdateState (central: CBCentralManager); message 'centralManagerDidUpdateState:';
+end;
+
+Test=objccategory(NSObject,CBCentralManagerDelegateProtocol)
+procedure centralManagerDidUpdateState (central: CBCentralManager);
+end;
+
+var
+  called: boolean = false;
+
+procedure Test.centralManagerDidUpdateState (central: CBCentralManager);
+begin
+  called:=true;
+end;
+
+var
+  o: NSObject;
+begin
+  o := NSObject.alloc.init;
+  o.centralManagerDidUpdateState(nil);
+  if not called then
+    halt(1);
+end.