Commit 65f5887
committed
[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
02c2ab3 which was reverted in
4c539e8. 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/D728721 parent 57a7cd7 commit 65f5887
File tree
7 files changed
+43
-7
lines changed- clang
- include/clang/AST
- lib
- AST
- Sema
- test/SemaObjC
7 files changed
+43
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1459 | 1459 | | |
1460 | 1460 | | |
1461 | 1461 | | |
| 1462 | + | |
| 1463 | + | |
1462 | 1464 | | |
1463 | 1465 | | |
1464 | 1466 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5605 | 5605 | | |
5606 | 5606 | | |
5607 | 5607 | | |
| 5608 | + | |
5608 | 5609 | | |
5609 | 5610 | | |
5610 | 5611 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4898 | 4898 | | |
4899 | 4899 | | |
4900 | 4900 | | |
4901 | | - | |
| 4901 | + | |
4902 | 4902 | | |
4903 | 4903 | | |
4904 | 4904 | | |
| |||
4924 | 4924 | | |
4925 | 4925 | | |
4926 | 4926 | | |
| 4927 | + | |
| 4928 | + | |
| 4929 | + | |
| 4930 | + | |
| 4931 | + | |
| 4932 | + | |
| 4933 | + | |
| 4934 | + | |
| 4935 | + | |
| 4936 | + | |
| 4937 | + | |
4927 | 4938 | | |
4928 | 4939 | | |
4929 | 4940 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3585 | 3585 | | |
3586 | 3586 | | |
3587 | 3587 | | |
| 3588 | + | |
3588 | 3589 | | |
3589 | 3590 | | |
| 3591 | + | |
3590 | 3592 | | |
3591 | 3593 | | |
3592 | 3594 | | |
3593 | 3595 | | |
3594 | 3596 | | |
3595 | 3597 | | |
3596 | | - | |
| 3598 | + | |
3597 | 3599 | | |
3598 | 3600 | | |
3599 | 3601 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
938 | 938 | | |
939 | 939 | | |
940 | 940 | | |
941 | | - | |
942 | | - | |
| 941 | + | |
943 | 942 | | |
944 | 943 | | |
945 | 944 | | |
| |||
966 | 965 | | |
967 | 966 | | |
968 | 967 | | |
969 | | - | |
970 | | - | |
| 968 | + | |
971 | 969 | | |
972 | 970 | | |
973 | 971 | | |
| |||
Lines changed: 9 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| |||
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
467 | 467 | | |
468 | 468 | | |
469 | 469 | | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
0 commit comments