diff options
Diffstat (limited to 'lib/Sema/SemaDeclObjC.cpp')
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index bb0923003b..f98eeb6112 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -1254,13 +1254,18 @@ Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, PropertyId->getName()); return 0; } + QualType PropType = Context.getCanonicalType(property->getType()); + QualType IvarType = Context.getCanonicalType(Ivar->getType()); + // Check that type of property and its ivar are type compatible. - // A property is allowed to be a sub-class of the instance variable type. - if (CheckAssignmentConstraints(property->getType(), - Ivar->getType()) != Compatible) { - Diag(PropertyLoc, diag::error_property_ivar_type, property->getName(), - Ivar->getName()); - return 0; + if (PropType != IvarType) { + // A readonly property is allowed to be a sub-class of the ivar type. + if (!property->isReadOnly() || + CheckAssignmentConstraints(PropType, IvarType) != Compatible) { + Diag(PropertyLoc, diag::error_property_ivar_type, property->getName(), + Ivar->getName()); + return 0; + } } } else if (PropertyIvar) { // @dynamic |