google / google/j2objc

Problem with isAssignable in IOSConcreteClass.m

Open
#890 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
6k
Forks
999
Avg merge
19h 20m
Merged PRs (30d)
14

Description

isAssignable doesn't work when testing assignable on the interface implementation. Perhaps, it uses isAssignable in IOSConcreteClass.m. It seems to use isSubclass which is not giving the expected behavior when the class conforms a protocol.

I think this may only happens with XCode9-Swift4 update as my code broken after upgrading to it. Please see below code to see the difference between isAssignable in Java and Swift 4.

Thank you for your help in advance!

**In Java**
```
// print "Can Arraylist -> List? true"
System.out.println("Can Arraylist -> List? " + List.class.isAssignableFrom(ArrayList.class));
```

**In Swift4 (XCode 9)**
```
// print false -- Protocol conformance is somehow not assignable (problem here)
print(JavaUtilList_class_().isAssignable(from: JavaUtilArrayList_class_()))

// print true -- Subclass seems to work fine
print(JavaUtilAbstractCollection_class_().isAssignable(from: JavaUtilArrayList_class_()))

// print true
print(JavaUtilArrayList_class_().objcClass.conforms(to: JavaUtilList.self))

// print false
print(JavaUtilArrayList_class_().objcClass.isSubclass(of: JavaUtilList.self))
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.