]> granicus.if.org Git - clang/commitdiff
Improved fix for <rdar://problem/6247781> Parser rejecting properly mismatched proper...
authorSteve Naroff <snaroff@apple.com>
Tue, 30 Sep 2008 10:07:56 +0000 (10:07 +0000)
committerSteve Naroff <snaroff@apple.com>
Tue, 30 Sep 2008 10:07:56 +0000 (10:07 +0000)
Needed to make sure the relaxed type checking only applies to "readonly" properties.

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

lib/Sema/SemaDeclObjC.cpp

index bb0923003b6bace8fac0ada408595ff943b6944c..f98eeb611254e6ea358a0acd2b4ff5bf274e10b7 100644 (file)
@@ -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