]> granicus.if.org Git - clang/commitdiff
Objective-C properties: fix bogus use of "isa<>" on a QualType.
authorDouglas Gregor <dgregor@apple.com>
Tue, 8 Dec 2015 22:45:17 +0000 (22:45 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 8 Dec 2015 22:45:17 +0000 (22:45 +0000)
The code used "isa" to check the type and then "getAs" to look through
sugar; we need to look through the sugar when checking, too, otherwise
any kind of sugar (nullability qualifiers in the example; or a
typedef) will thwart this semantic check. Fixes rdar://problem/23804250.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255066 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaObjCProperty.cpp
test/SemaObjCXX/property-type-mismatch.mm

index f0948b77580450301de95519aa5e8c1d683f0d37..e204936b500721c2de721cffb8268d611985f27b 100644 (file)
@@ -1372,12 +1372,11 @@ bool Sema::DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *property,
   QualType PropertyIvarType = property->getType().getNonReferenceType();
   bool compat = Context.hasSameType(PropertyIvarType, GetterType);
   if (!compat) {
-    if (isa<ObjCObjectPointerType>(PropertyIvarType) && 
-        isa<ObjCObjectPointerType>(GetterType))
-      compat =
-        Context.canAssignObjCInterfaces(
-                                      GetterType->getAs<ObjCObjectPointerType>(),
-                                      PropertyIvarType->getAs<ObjCObjectPointerType>());
+    const ObjCObjectPointerType *propertyObjCPtr = nullptr;
+    const ObjCObjectPointerType *getterObjCPtr = nullptr;
+    if ((propertyObjCPtr = PropertyIvarType->getAs<ObjCObjectPointerType>()) && 
+        (getterObjCPtr = GetterType->getAs<ObjCObjectPointerType>()))
+      compat = Context.canAssignObjCInterfaces(getterObjCPtr, propertyObjCPtr);
     else if (CheckAssignmentConstraints(Loc, GetterType, PropertyIvarType) 
               != Compatible) {
           Diag(Loc, diag::error_property_accessor_type)
index 2b267ad96eefe87e09795f37b8e04afe46c03abc..6ab07b8f3b801f57fb4a9f4f20132011244a5887 100644 (file)
 @property (assign) NSObject<P2> *prop;
 @end
 
+@interface C<T> : NSObject 
+@end
+
+@interface D
+@property (nonatomic,readonly,nonnull) C<D *> *property;
+@end
+
+@interface D ()
+@property (nonatomic, setter=_setProperty:) C *property; // okay
+@end