[all-commits] [llvm/llvm-project] 65f588: [ObjC generics] Fix not inheriting type bounds in ...

Volodymyr Sapsai via All-commits all-commits at lists.llvm.org
Fri Apr 24 16:35:15 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 65f58878e72a40d68ef3899c766846ee9ec7cf29
      https://github.com/llvm/llvm-project/commit/65f58878e72a40d68ef3899c766846ee9ec7cf29
  Author: Volodymyr Sapsai <vsapsai at apple.com>
  Date:   2020-04-24 (Fri, 24 Apr 2020)

  Changed paths:
    M clang/include/clang/AST/ASTContext.h
    M clang/include/clang/AST/Type.h
    M clang/lib/AST/ASTContext.cpp
    M clang/lib/AST/Type.cpp
    M clang/lib/Sema/SemaDeclObjC.cpp
    M clang/test/SemaObjC/parameterized_classes_collection_literal.m
    M clang/test/SemaObjC/parameterized_classes_subst.m

  Log Message:
  -----------
  [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 wasn't updated and
remains `id`.

Fix by updating not only `ObjCTypeParamDecl` UnderlyingType but also
TypeForDecl as we use the underlying type to create a canonical type for
`ObjCTypeParamType` (see `ASTContext::getObjCTypeParamType`).

This is a different approach to fixing the issue. The previous one was
02c2ab3d8872416589bd1a6ca3dfb96ba373a3b9 which was reverted in
4c539e8da1b3de38a53ef3f7497f5c45a3243b61. The problem with the previous
approach was that `ObjCTypeParamType::desugar` was returning underlying
type for `ObjCTypeParamDecl` without applying any protocols stored in
`ObjCTypeParamType`. It caused inconsistencies in comparing types before
and after desugaring.

Re-applying after fixing intermittent test failures.

rdar://problem/54329242

Reviewed By: erik.pilkington

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




More information about the All-commits mailing list