-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix indexing constructors with generic parameters #65597
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
Changes from all commits
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 |
---|---|---|
|
@@ -815,9 +815,22 @@ passReference(ValueDecl *D, Type Ty, SourceLoc BaseNameLoc, SourceRange Range, | |
|
||
if (auto *TD = dyn_cast<TypeDecl>(D)) { | ||
if (!CtorRefs.empty() && BaseNameLoc.isValid()) { | ||
Expr *Fn = CtorRefs.back()->getFn(); | ||
if (Fn->getLoc() == BaseNameLoc) { | ||
D = ide::getReferencedDecl(Fn).second.getDecl(); | ||
ConstructorRefCallExpr *Ctor = CtorRefs.back(); | ||
SourceLoc CtorLoc = Ctor->getFn()->getLoc(); | ||
// Get the location of the type, ignoring parens, rather than the start of | ||
// the Expr, to match the lookup. | ||
if (auto *TE = dyn_cast<TypeExpr>(Ctor->getBase())) | ||
CtorLoc = TE->getTypeRepr()->getWithoutParens()->getLoc(); | ||
Comment on lines
+822
to
+823
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. I think there may be some other TypeReprs that this doesn't quite handle correctly e.g 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. Hrm what's the scenario more specifically? this code: protocol P {
init(value: Int)
}
func foo<T: P>(A: T.Type?) {
_ = A?(value: 0)
} Forces you to do 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. I mean like this: struct S {}
func foo(_ x: S) {
_ = S?(x)
} Optional has an init that takes the wrapped value 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. ah yep, that case doesn't work you're right, i'll file that example 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. 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. Thanks! |
||
|
||
bool isImplicit = false; | ||
Expr *Fn = Ctor->getFn(); | ||
while (auto *ICE = dyn_cast<ImplicitConversionExpr>(Fn)) | ||
Fn = ICE->getSubExpr(); | ||
if (auto *DRE = dyn_cast<DeclRefExpr>(Fn)) | ||
isImplicit = DRE->isImplicit(); | ||
|
||
if (isImplicit && CtorLoc == BaseNameLoc) { | ||
D = ide::getReferencedDecl(Ctor->getFn()).second.getDecl(); | ||
if (D == nullptr) { | ||
assert(false && "Unhandled constructor reference"); | ||
return true; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,7 +129,7 @@ class GenCls<T> { | |
} | ||
|
||
func test2() { | ||
// CHECK: <Class@[[@LINE-19]]:7>GenCls</Class><<iStruct@>Int</iStruct>>() | ||
// CHECK: <Ctor@[[@LINE-17]]:3-Class@[[@LINE-19]]:7>GenCls</Ctor><<iStruct@>Int</iStruct>>() | ||
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. this was wrong before for the same reason |
||
GenCls<Int>() | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.