Skip to content

Commit 3370637

Browse files
authored
Merge pull request swiftlang#79705 from hamishknight/cursor-of-the-implicit
[IDE] Avoid inferring container type for implicit expressions
2 parents fc41265 + f524691 commit 3370637

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,6 @@ class PrintAST : public ASTVisitor<PrintAST> {
11591159
Type OldType = CurrentType;
11601160
if (CurrentType && (Old != nullptr || Options.PrintAsMember)) {
11611161
if (auto *NTD = dyn_cast<NominalTypeDecl>(D)) {
1162-
assert(Options.CurrentModule);
11631162
auto Subs = CurrentType->getContextSubstitutionMap(
11641163
NTD->getDeclContext());
11651164
setCurrentType(NTD->getDeclaredInterfaceType().subst(Subs));

lib/IDE/IDERequests.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,13 @@ bool CursorInfoResolver::walkToExprPre(Expr *E) {
341341
}
342342

343343
if (auto SAE = dyn_cast<SelfApplyExpr>(E)) {
344-
if (SAE->getFn()->getStartLoc() == LocToResolve) {
344+
auto *fn = SAE->getFn();
345+
if (!fn->isImplicit() && fn->getStartLoc() == LocToResolve) {
345346
ContainerType = SAE->getBase()->getType();
346347
}
347348
} else if (auto ME = dyn_cast<MemberRefExpr>(E)) {
348349
SourceLoc MemberLoc = ME->getNameLoc().getBaseNameLoc();
349-
if (MemberLoc.isValid() && MemberLoc == LocToResolve) {
350+
if (!ME->isImplicit() && MemberLoc.isValid() && MemberLoc == LocToResolve) {
350351
ContainerType = ME->getBase()->getType();
351352
}
352353
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@resultBuilder
2+
struct Builder {
3+
static func buildBlock<T>(_ x: T) -> T { x }
4+
static func buildExpression<T>(_ x: T) -> T { x }
5+
}
6+
7+
// https://github.com/swiftlang/swift/issues/79696
8+
// Make sure we don't pick up the builder as the container type.
9+
struct A {
10+
struct B {
11+
@Builder
12+
var foo: Any {
13+
B
14+
// RUN: %sourcekitd-test -req=cursor -pos=%(line-1):7 %s -- %s | %FileCheck %s --check-prefix NESTED_TY
15+
// NESTED_TY-NOT: Container
16+
}
17+
@Builder var bar: Any {
18+
foo
19+
// RUN: %sourcekitd-test -req=cursor -pos=%(line-1):7 %s -- %s | %FileCheck %s --check-prefix PROP
20+
// PROP: <Container>$s4main1AV1BVD</Container>
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)