]> granicus.if.org Git - clang/commitdiff
[ObjC generics] Fix not inheriting type bounds in categories/extensions.
authorVolodymyr Sapsai <vsapsai@apple.com>
Wed, 9 Oct 2019 19:29:13 +0000 (19:29 +0000)
committerVolodymyr Sapsai <vsapsai@apple.com>
Wed, 9 Oct 2019 19:29:13 +0000 (19:29 +0000)
When a category/extension doesn't repeat a type bound, corresponding
type parameter is substituted with `id` when used as a type argument. As
a result, in the added test case it was causing errors like

> type argument 'T' (aka 'id') does not satisfy the bound ('id<NSCopying>') of type parameter 'T'

We are already checking that type parameters should be consistent
everywhere (see `checkTypeParamListConsistency`) and update
`ObjCTypeParamDecl` to have correct underlying type. And when we use the
type parameter as a method return type or a method parameter type, it is
substituted to the bounded type. But when we use the type parameter as a
type argument, we check `ObjCTypeParamType` that ignores the updated
underlying type and remains `id`.

Fix by desugaring `ObjCTypeParamType` to the underlying type, the same
way we are doing with `TypedefType`.

rdar://problem/54329242

Reviewers: erik.pilkington, ahatanak

Reviewed By: erik.pilkington

Subscribers: jkorous, dexonsmith, ributzka, cfe-commits

Differential Revision: https://reviews.llvm.org/D66696

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

include/clang/AST/Type.h
lib/AST/Type.cpp
test/SemaObjC/parameterized_classes_subst.m

index ecbbd73e19fb451122583c598dc57750c3137a4f..c9238e95210125123d9137a52ce172184b407c56 100644 (file)
@@ -5569,7 +5569,7 @@ class ObjCTypeParamType : public Type,
 
 public:
   bool isSugared() const { return true; }
-  QualType desugar() const { return getCanonicalTypeInternal(); }
+  QualType desugar() const;
 
   static bool classof(const Type *T) {
     return T->getTypeClass() == ObjCTypeParam;
index 4fed5b410b172446c15d63fca1638fd79c4f6689..4d54ea1061edcd1003dcb5b7e9e0ce21fd670ff8 100644 (file)
@@ -663,6 +663,10 @@ ObjCTypeParamType::ObjCTypeParamType(const ObjCTypeParamDecl *D,
   initialize(protocols);
 }
 
+QualType ObjCTypeParamType::desugar() const {
+  return getDecl()->getUnderlyingType();
+}
+
 ObjCObjectType::ObjCObjectType(QualType Canonical, QualType Base,
                                ArrayRef<QualType> typeArgs,
                                ArrayRef<ObjCProtocolDecl *> protocols,
index d14a6e9deb4066956c162ee7a9180141f035346a..b6d884760d294ec848daee894585c91e598a4478 100644 (file)
@@ -467,3 +467,17 @@ void bar(MyMutableDictionary<NSString *, NSString *> *stringsByString,
 - (void)mapUsingBlock2:(id)block { // expected-warning{{conflicting parameter types in implementation}}
 }
 @end
+
+// --------------------------------------------------------------------------
+// Use a type parameter as a type argument.
+// --------------------------------------------------------------------------
+// Type bounds in a category/extension are omitted. rdar://problem/54329242
+@interface ParameterizedContainer<T : id<NSCopying>>
+- (ParameterizedContainer<T> *)inInterface;
+@end
+@interface ParameterizedContainer<T> (Cat)
+- (ParameterizedContainer<T> *)inCategory;
+@end
+@interface ParameterizedContainer<U> ()
+- (ParameterizedContainer<U> *)inExtension;
+@end