-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[Sema] Fix compiler error when extending a typealias of a partially specialized generic type #73169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7025a0d
772995f
0e2ee58
f95b4a5
f7cbfb4
a6b222b
11bff2a
fb4dcdd
74fc932
6f6f37f
8f45a15
e1ab6bb
e513182
06d2a96
7c2dae5
8719c90
bd7a393
6a81633
0a5afa6
2dcb95f
2a53487
eb49f5a
86f74ca
6302d7d
871df92
ea8f12c
2a929de
997bd4e
b102077
b5a899e
491fd95
99d29cb
b070615
a68d748
aec1481
a18c1b3
f42dc3b
9aa17c5
7240766
ed5ddbd
fa9c005
4d26c68
de51bf2
6340373
c4eb3a6
3d8aabb
aeb2e73
be58943
6d61966
98a9f2e
bd7df19
b480ceb
ad5d532
cc1b299
04c1f72
8a849b7
87cdebf
be17e78
8a71a9a
6fb08c1
fe2fc6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3025,6 +3025,34 @@ AllMembersRequest::evaluate( | |
| return evaluateMembersRequest(idc, MembersRequestKind::All); | ||
| } | ||
|
|
||
| static bool isTypeInferredByTypealias(TypeAliasDecl *typealias, | ||
| NominalTypeDecl *nominal) { | ||
| if (!nominal->isGeneric()){ | ||
| return false; | ||
| } | ||
|
|
||
| auto nominalGenericArguments = nominal->getDeclaredInterfaceType() | ||
| ->getAs<BoundGenericType>() | ||
| ->getGenericArgs(); | ||
| auto typealiasGenericArguments = typealias->getUnderlyingType() | ||
| ->getAs<BoundGenericType>() | ||
| ->getGenericArgs(); | ||
|
|
||
| for (size_t i = 0; i < nominalGenericArguments.size(); i++) { | ||
| auto nominalBoundGenericType = nominalGenericArguments[i]; | ||
| auto typealiasBoundGenericType = typealiasGenericArguments[i]; | ||
| if (nominalBoundGenericType->isEqual(typealiasBoundGenericType)) { | ||
| continue; | ||
| } | ||
|
|
||
| if (typealiasBoundGenericType->hasTypeParameter()) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| bool TypeChecker::isPassThroughTypealias(TypeAliasDecl *typealias, | ||
| NominalTypeDecl *nominal) { | ||
| // Pass-through only makes sense when the typealias refers to a nominal | ||
|
|
@@ -3045,17 +3073,39 @@ bool TypeChecker::isPassThroughTypealias(TypeAliasDecl *typealias, | |
| // If neither is generic, we're done: it's a pass-through alias. | ||
| if (!nominalSig) return true; | ||
|
|
||
| // Check that the type parameters are the same the whole way through. | ||
| auto nominalGenericParams = nominalSig.getGenericParams(); | ||
| auto typealiasGenericParams = typealiasSig.getGenericParams(); | ||
| if (nominalGenericParams.size() != typealiasGenericParams.size()) | ||
| return false; | ||
| if (!std::equal(nominalGenericParams.begin(), nominalGenericParams.end(), | ||
| typealiasGenericParams.begin(), | ||
| [](GenericTypeParamType *gp1, GenericTypeParamType *gp2) { | ||
| return gp1->isEqual(gp2); | ||
| })) | ||
| return false; | ||
|
|
||
| if (nominalGenericParams.size() != typealiasGenericParams.size()) { | ||
|
|
||
| unsigned nominalMaxDepth = nominalGenericParams.back()->getDepth(); | ||
| unsigned typealiasMaxDepth = typealiasGenericParams.back()->getDepth(); | ||
| unsigned maxDepth = std::max(nominalMaxDepth, typealiasMaxDepth); | ||
|
|
||
| while (!nominalGenericParams.empty() && | ||
| nominalGenericParams.back()->getDepth() == maxDepth) { | ||
| nominalGenericParams = nominalGenericParams.drop_back(); | ||
| } | ||
|
|
||
| while (!typealiasGenericParams.empty() && | ||
| typealiasGenericParams.back()->getDepth() == maxDepth) { | ||
| typealiasGenericParams = typealiasGenericParams.drop_back(); | ||
| } | ||
|
|
||
| if (nominalGenericParams.size() != typealiasGenericParams.size()) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!std::equal(nominalGenericParams.begin(), nominalGenericParams.end(), | ||
| typealiasGenericParams.begin(), | ||
| [](GenericTypeParamType *gp1, GenericTypeParamType *gp2) { | ||
| return gp1->isEqual(gp2); | ||
| })) { | ||
| return false; | ||
| } | ||
|
Comment on lines
+3099
to
+3105
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to perform this check regardless of whether the original number of generic params matched.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confused here, added a comment above about this
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment: #73169 (comment) So the goal is to relax the fall-through type alias criteria a little bit by allowing a mismatch in the number of generic parameters at the greatest depth, but only if that difference is due to some of those generic parameters being bound to fully concrete types. As for other depths, the current rules still apply. For example, Could you rebase (I have renamed |
||
|
|
||
| return isTypeInferredByTypealias(typealias, nominal); | ||
| } | ||
|
|
||
| // If neither is generic at this level, we have a pass-through typealias. | ||
| if (!typealias->isGeneric()) return true; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.