From: Douglas Gregor Date: Tue, 8 Dec 2015 22:45:17 +0000 (+0000) Subject: Objective-C properties: fix bogus use of "isa<>" on a QualType. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1145c8be28a937de42eeb9b8e06908dfdba65024;p=clang Objective-C properties: fix bogus use of "isa<>" on a QualType. 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 --- diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index f0948b7758..e204936b50 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -1372,12 +1372,11 @@ bool Sema::DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *property, QualType PropertyIvarType = property->getType().getNonReferenceType(); bool compat = Context.hasSameType(PropertyIvarType, GetterType); if (!compat) { - if (isa(PropertyIvarType) && - isa(GetterType)) - compat = - Context.canAssignObjCInterfaces( - GetterType->getAs(), - PropertyIvarType->getAs()); + const ObjCObjectPointerType *propertyObjCPtr = nullptr; + const ObjCObjectPointerType *getterObjCPtr = nullptr; + if ((propertyObjCPtr = PropertyIvarType->getAs()) && + (getterObjCPtr = GetterType->getAs())) + compat = Context.canAssignObjCInterfaces(getterObjCPtr, propertyObjCPtr); else if (CheckAssignmentConstraints(Loc, GetterType, PropertyIvarType) != Compatible) { Diag(Loc, diag::error_property_accessor_type) diff --git a/test/SemaObjCXX/property-type-mismatch.mm b/test/SemaObjCXX/property-type-mismatch.mm index 2b267ad96e..6ab07b8f3b 100644 --- a/test/SemaObjCXX/property-type-mismatch.mm +++ b/test/SemaObjCXX/property-type-mismatch.mm @@ -18,3 +18,13 @@ @property (assign) NSObject *prop; @end +@interface C : NSObject +@end + +@interface D +@property (nonatomic,readonly,nonnull) C *property; +@end + +@interface D () +@property (nonatomic, setter=_setProperty:) C *property; // okay +@end