This revision was automatically updated to reflect the committed changes. Closed by commit rGa8c8b627f23f: [ObjC generics] Fix not inheriting type bounds in categories/extensions. (authored by vsapsai).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D72872/new/ https://reviews.llvm.org/D72872 Files: clang/include/clang/AST/ASTContext.h clang/lib/AST/ASTContext.cpp clang/lib/AST/Type.cpp clang/lib/Sema/SemaDeclObjC.cpp clang/test/SemaObjC/parameterized_classes_collection_literal.m clang/test/SemaObjC/parameterized_classes_subst.m
Index: clang/test/SemaObjC/parameterized_classes_subst.m =================================================================== --- clang/test/SemaObjC/parameterized_classes_subst.m +++ clang/test/SemaObjC/parameterized_classes_subst.m @@ -467,3 +467,17 @@ - (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 Index: clang/test/SemaObjC/parameterized_classes_collection_literal.m =================================================================== --- clang/test/SemaObjC/parameterized_classes_collection_literal.m +++ clang/test/SemaObjC/parameterized_classes_collection_literal.m @@ -29,7 +29,9 @@ @end @interface NSDictionary<K, V> : NSObject <NSCopying> -+ (instancetype)dictionaryWithObjects:(const V [])objects forKeys:(const K [])keys count:(NSUInteger)cnt; ++ (instancetype)dictionaryWithObjects:(const V [])objects + forKeys:(const K <NSCopying> [])keys + count:(NSUInteger)cnt; @end void testArrayLiteral(void) { @@ -50,3 +52,9 @@ @"world" : @"blah" // expected-warning{{object of type 'NSString *' is not compatible with dictionary value type 'NSNumber *'}} }; } + +void testCastingInDictionaryLiteral(NSString *arg) { + NSDictionary *dict = @{ + (id)arg : @"foo", + }; +} Index: clang/lib/Sema/SemaDeclObjC.cpp =================================================================== --- clang/lib/Sema/SemaDeclObjC.cpp +++ clang/lib/Sema/SemaDeclObjC.cpp @@ -938,8 +938,7 @@ // Override the new type parameter's bound type with the previous type, // so that it's consistent. - newTypeParam->setTypeSourceInfo( - S.Context.getTrivialTypeSourceInfo(prevTypeParam->getUnderlyingType())); + S.Context.adjustObjCTypeParamBoundType(prevTypeParam, newTypeParam); continue; } @@ -966,8 +965,7 @@ } // Update the new type parameter's bound to match the previous one. - newTypeParam->setTypeSourceInfo( - S.Context.getTrivialTypeSourceInfo(prevTypeParam->getUnderlyingType())); + S.Context.adjustObjCTypeParamBoundType(prevTypeParam, newTypeParam); } return false; Index: clang/lib/AST/Type.cpp =================================================================== --- clang/lib/AST/Type.cpp +++ clang/lib/AST/Type.cpp @@ -3534,6 +3534,7 @@ const ObjCTypeParamDecl *OTPDecl, ArrayRef<ObjCProtocolDecl *> protocols) { ID.AddPointer(OTPDecl); + ID.AddPointer(OTPDecl->getUnderlyingType().getAsOpaquePtr()); ID.AddInteger(protocols.size()); for (auto proto : protocols) ID.AddPointer(proto); Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -4874,6 +4874,17 @@ return QualType(newType, 0); } +void ASTContext::adjustObjCTypeParamBoundType(const ObjCTypeParamDecl *Orig, + ObjCTypeParamDecl *New) const { + New->setTypeSourceInfo(getTrivialTypeSourceInfo(Orig->getUnderlyingType())); + // Update TypeForDecl after updating TypeSourceInfo. + auto NewTypeParamTy = cast<ObjCTypeParamType>(New->getTypeForDecl()); + SmallVector<ObjCProtocolDecl *, 8> protocols; + protocols.append(NewTypeParamTy->qual_begin(), NewTypeParamTy->qual_end()); + QualType UpdatedTy = getObjCTypeParamType(New, protocols); + New->setTypeForDecl(UpdatedTy.getTypePtr()); +} + /// ObjCObjectAdoptsQTypeProtocols - Checks that protocols in IC's /// protocol list adopt all protocols in QT's qualified-id protocol /// list. Index: clang/include/clang/AST/ASTContext.h =================================================================== --- clang/include/clang/AST/ASTContext.h +++ clang/include/clang/AST/ASTContext.h @@ -1442,6 +1442,8 @@ QualType getObjCTypeParamType(const ObjCTypeParamDecl *Decl, ArrayRef<ObjCProtocolDecl *> protocols) const; + void adjustObjCTypeParamBoundType(const ObjCTypeParamDecl *Orig, + ObjCTypeParamDecl *New) const; bool ObjCObjectAdoptsQTypeProtocols(QualType QT, ObjCInterfaceDecl *Decl);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits