diff options
author | Volodymyr Sapsai <vsapsai@apple.com> | 2019-10-09 19:29:13 +0000 |
---|---|---|
committer | Volodymyr Sapsai <vsapsai@apple.com> | 2019-10-09 19:29:13 +0000 |
commit | 02c2ab3d8872416589bd1a6ca3dfb96ba373a3b9 (patch) | |
tree | 5e18f62ae7d6a7840a7a39724db55f71eae9df52 | |
parent | 87aa9c9e4d41ed881453e2fab85b3d25f648bb55 (diff) | |
download | bcm5719-llvm-02c2ab3d8872416589bd1a6ca3dfb96ba373a3b9.tar.gz bcm5719-llvm-02c2ab3d8872416589bd1a6ca3dfb96ba373a3b9.zip |
[ObjC generics] Fix not inheriting type bounds in categories/extensions.
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
llvm-svn: 374202
-rw-r--r-- | clang/include/clang/AST/Type.h | 2 | ||||
-rw-r--r-- | clang/lib/AST/Type.cpp | 4 | ||||
-rw-r--r-- | clang/test/SemaObjC/parameterized_classes_subst.m | 14 |
3 files changed, 19 insertions, 1 deletions
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index ecbbd73e19f..c9238e95210 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -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; diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index 4fed5b410b1..4d54ea1061e 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -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, diff --git a/clang/test/SemaObjC/parameterized_classes_subst.m b/clang/test/SemaObjC/parameterized_classes_subst.m index d14a6e9deb4..b6d884760d2 100644 --- a/clang/test/SemaObjC/parameterized_classes_subst.m +++ b/clang/test/SemaObjC/parameterized_classes_subst.m @@ -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 |