-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[ClangImporter] Forward generic parameters while importing generic @c… #17164
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
Conversation
@swift-ci please test |
@swift-ci please test source compatibility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, but this isn't the only place where the importer creates typealiases for generic types. The other is renames; see SwiftDeclConverter::importCompatibilityTypeAlias
(unrelated to @compatibility_alias
).
lib/ClangImporter/ImportDecl.cpp
Outdated
if (auto *GTD = dyn_cast<GenericTypeDecl>(typeDecl)) { | ||
typealias->setGenericEnvironment(GTD->getGenericEnvironment()); | ||
if (GTD->isGeneric()) | ||
typealias->setGenericParams(GTD->getGenericParams()->clone(dc)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't the typealias have to be the DeclContext?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean GenericContext
? I'm checking for GenericTypeDecl
here because typeDecl
already is a TypeDecl
so not sure if it makes sense to check lower than that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, sorry, I mean in the call to clone
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sure, I'll change that!
@@ -60,8 +60,12 @@ | |||
@interface SwiftNameTestErrorSub : SwiftNameTestError | |||
@end | |||
|
|||
@interface SwiftGenericNameTest<T> : NSObject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please include a test where T is constrained (either to a class or to a protocol or both).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think particular case T is constrained to NSObject, I have a test which tried to pass Int
to it and fails, but I'll add more too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added one more class which has T constrained to NSNumber *
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's just constrained to AnyObject. NSNumber is good enough!
197f2d7
to
9315b55
Compare
@jrose-apple I've made changes to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests look good, code still a bit off!
lib/ClangImporter/ImportDecl.cpp
Outdated
if (auto *GTD = dyn_cast<GenericTypeDecl>(typeDecl)) { | ||
typealias->setGenericEnvironment(GTD->getGenericEnvironment()); | ||
if (GTD->isGeneric()) | ||
typealias->setGenericParams(GTD->getGenericParams()->clone(GTD)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still wrong; it's supposed to be the new DeclContext, not the old one. That's typealias
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get it now, sorry - it has to use typealias
because that's the scope for the new generic parameters, sorry about this...
lib/ClangImporter/ImportDecl.cpp
Outdated
if (GTD && !isa<ProtocolDecl>(GTD)) { | ||
alias->setGenericEnvironment(GTD->getGenericEnvironment()); | ||
if (GTD->isGeneric()) | ||
alias->setGenericParams(GTD->getGenericParams()->clone(GTD)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(here too)
…ompatibility_alias When importing @compatibility_alias declarations check if underlying declaration is generic and if so, forward generic environment and generic parameters (if any) to newly created typealias declaration, otherwise there is going to be a mismatch between type associated with typealias and its declaration which leads to crashes. Resolves: rdar://problem/39849926
While trying to import declaration which requires renaming forward generic parameters (if any) to newly created typealias.
@swift-ci please test |
@swift-ci please test source compatibility |
@swift-ci please test macOS platform |
1 similar comment
@swift-ci please test macOS platform |
@swift-ci please test source compatibility |
…ompatibility_alias
When importing @compatibility_alias declarations check if underlying declaration
is generic and if so, forward generic environment and generic parameters (if any)
to newly created typealias declaration, otherwise there is going to be a mismatch
between type associated with typealias and its declaration which leads to crashes.
Resolves: rdar://problem/39849926