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.

llvm-svn: 255066
This commit is contained in:
Douglas Gregor 2015-12-08 22:45:17 +00:00
parent 8f64ca1529
commit 1cbb289c7d
2 changed files with 15 additions and 6 deletions

View 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)

View File

@ -18,3 +18,13 @@
@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