Browse Source

* fix conversion from Objective-C class/protocol to tvarrec (store in
vPointer) (mantis #36362)

git-svn-id: trunk@43594 -

Jonas Maebe 5 years ago
parent
commit
5800ac6213
3 changed files with 37 additions and 3 deletions
  1. 1 0
      .gitattributes
  2. 5 3
      compiler/ncnv.pas
  3. 31 0
      tests/test/units/cocoaall/tw36362.pp

+ 1 - 0
.gitattributes

@@ -15464,6 +15464,7 @@ tests/test/units/classes/ttbits.pp svneol=native#text/pascal
 tests/test/units/classes/ttlist.pp svneol=native#text/plain
 tests/test/units/classes/ttlist.pp svneol=native#text/plain
 tests/test/units/classes/tvclcomobject.pp svneol=native#text/plain
 tests/test/units/classes/tvclcomobject.pp svneol=native#text/plain
 tests/test/units/cocoaall/tw35994.pp svneol=native#text/plain
 tests/test/units/cocoaall/tw35994.pp svneol=native#text/plain
+tests/test/units/cocoaall/tw36362.pp svneol=native#text/plain
 tests/test/units/cpu/tcpu1.pp svneol=native#text/pascal
 tests/test/units/cpu/tcpu1.pp svneol=native#text/pascal
 tests/test/units/crt/tcrt.pp svneol=native#text/plain
 tests/test/units/crt/tcrt.pp svneol=native#text/plain
 tests/test/units/crt/tctrlc.pp svneol=native#text/plain
 tests/test/units/crt/tctrlc.pp svneol=native#text/plain

+ 5 - 3
compiler/ncnv.pas

@@ -843,10 +843,12 @@ implementation
               if iscvarargs then
               if iscvarargs then
                 p:=ctypeconvnode.create(p,voidpointertype);
                 p:=ctypeconvnode.create(p,voidpointertype);
             objectdef :
             objectdef :
-              if (iscvarargs and
-                  not is_objc_class_or_protocol(p.resultdef)) or
+              if is_objc_class_or_protocol(p.resultdef) then
+                p:=ctypeconvnode.create(p,voidpointertype)
+              else if iscvarargs or
                  is_object(p.resultdef) then
                  is_object(p.resultdef) then
-                CGMessagePos1(p.fileinfo,type_e_wrong_type_in_array_constructor,p.resultdef.typename);
+                CGMessagePos1(p.fileinfo,type_e_wrong_type_in_array_constructor,p.resultdef.typename)
+              else
             else
             else
               CGMessagePos1(p.fileinfo,type_e_wrong_type_in_array_constructor,p.resultdef.typename);
               CGMessagePos1(p.fileinfo,type_e_wrong_type_in_array_constructor,p.resultdef.typename);
           end;
           end;

+ 31 - 0
tests/test/units/cocoaall/tw36362.pp

@@ -0,0 +1,31 @@
+{$mode objfpc}
+{$modeswitch objectivec2}
+
+program test;
+uses
+  CocoaAll;
+
+type
+  tc = objcclass(NSObject)
+    a: char;
+  end;
+
+operator := (const right: array of const): NSMutableArray;
+begin
+  if tc(right[0].vPointer).a<>'a' then
+    halt(1);
+  result:=NSMutableArray.alloc.initWithCapacity(1);
+  result.addObject(tc(right[0].vPointer));
+end;
+
+var
+  c: tc;
+  a: NSMutableArray;
+begin
+  c:=tc.alloc.init;
+  c.a:='a';
+  a := [c];
+  for c in a do
+    if c.a<>'a' then
+      halt(2);
+end.