-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[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
Open
xavgru12
wants to merge
61
commits into
swiftlang:main
Choose a base branch
from
xavgru12:genericTypealias
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
7025a0d
comment out isPassThroughTypealies
xavgru12 772995f
merge with main
xavgru12 0e2ee58
copy isPassThroughTypealias to isTypeInferredByTypealias and comment …
xavgru12 f95b4a5
add declaration of new function
xavgru12 f7cbfb4
merge with main
xavgru12 a6b222b
merge with main
xavgru12 11bff2a
merge with main
xavgru12 fb4dcdd
checkout main
xavgru12 74fc932
comment out isPassThroughTypealies
xavgru12 6f6f37f
copy isPassThroughTypealias to isTypeInferredByTypealias and comment …
xavgru12 8f45a15
add declaration of new function
xavgru12 e1ab6bb
remove oudtdated file
xavgru12 e513182
first version
xavgru12 06d2a96
returns only true if no unsupported type conversion is entered
xavgru12 7c2dae5
add back spaces
xavgru12 8719c90
remove more unwanted changes
xavgru12 bd7a393
get rid of unneeded changes
xavgru12 6a81633
according to github issue, this is supposed to fail, but the error me…
xavgru12 0a5afa6
add unit test for the new supported case
xavgru12 2dcb95f
remove unneeded include
xavgru12 2a53487
commit forced blank lines
xavgru12 eb49f5a
remove unneeded copy
xavgru12 86f74ca
remove extra brackets
xavgru12 6302d7d
remove comment
xavgru12 871df92
format code
xavgru12 ea8f12c
change variable name
xavgru12 2a929de
change location of function
xavgru12 997bd4e
remove unneeded check§
xavgru12 b102077
correct location
xavgru12 b5a899e
Revert "commit forced blank lines"
xavgru12 491fd95
revert evaluate ternary operator
xavgru12 99d29cb
whitespace
xavgru12 b070615
Revert "commit forced blank lines"
xavgru12 a68d748
whitespace
xavgru12 aec1481
Revert "commit forced blank lines"
xavgru12 a18c1b3
add missing bracket
xavgru12 f42dc3b
Revert "commit forced blank lines"
xavgru12 9aa17c5
Merge branch 'main' into merge_in_typealias
xavgru12 7240766
make the new function static
xavgru12 ed5ddbd
add typealiasBoundGenericType->hasTypeParameter()
xavgru12 fa9c005
add test case for typealiasBoundGenericType->hasTypeParameter() infer…
xavgru12 4d26c68
remove redundant check
xavgru12 de51bf2
fix typo
xavgru12 6340373
breaking expected fail
xavgru12 c4eb3a6
add test case for making type check stricter
xavgru12 3d8aabb
add isGeneric check
xavgru12 aeb2e73
add assert
xavgru12 be58943
make sure no exotic cases slip through
xavgru12 6d61966
add test case for expected fail
xavgru12 98a9f2e
add test case extension for expected pass
xavgru12 bd7df19
Merge remote-tracking branch 'origin/main' into generic_typealias
xavgru12 b480ceb
rename struct to fix redeclaration after merge
xavgru12 ad5d532
remove assert since it breaks 4 tests: Compatibility/stdlib_generic_t…
xavgru12 cc1b299
remove superfluous getPointer
xavgru12 04c1f72
add another test case
xavgru12 8a849b7
remove isInferredType
xavgru12 87cdebf
minimize diagnostic noise
xavgru12 be17e78
add test case
xavgru12 8a71a9a
changed foreach to while
xavgru12 6fb08c1
update test case with where
xavgru12 fe2fc6d
remove comments
xavgru12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
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. 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 |
||
|
||
return isTypeInferredByTypealias(typealias, nominal); | ||
} | ||
|
||
// If neither is generic at this level, we have a pass-through typealias. | ||
if (!typealias->isGeneric()) return true; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.