mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[IDE] Avoid inferring container type for implicit expressions
For e.g implicit `buildExpression` calls, we have a location that matches the argument, but we don't want to consider the result builder type as the container type.
This commit is contained in:
@@ -341,12 +341,13 @@ bool CursorInfoResolver::walkToExprPre(Expr *E) {
|
||||
}
|
||||
|
||||
if (auto SAE = dyn_cast<SelfApplyExpr>(E)) {
|
||||
if (SAE->getFn()->getStartLoc() == LocToResolve) {
|
||||
auto *fn = SAE->getFn();
|
||||
if (!fn->isImplicit() && fn->getStartLoc() == LocToResolve) {
|
||||
ContainerType = SAE->getBase()->getType();
|
||||
}
|
||||
} else if (auto ME = dyn_cast<MemberRefExpr>(E)) {
|
||||
SourceLoc MemberLoc = ME->getNameLoc().getBaseNameLoc();
|
||||
if (MemberLoc.isValid() && MemberLoc == LocToResolve) {
|
||||
if (!ME->isImplicit() && MemberLoc.isValid() && MemberLoc == LocToResolve) {
|
||||
ContainerType = ME->getBase()->getType();
|
||||
}
|
||||
}
|
||||
|
||||
23
test/SourceKit/CursorInfo/issue-79696.swift
Normal file
23
test/SourceKit/CursorInfo/issue-79696.swift
Normal file
@@ -0,0 +1,23 @@
|
||||
@resultBuilder
|
||||
struct Builder {
|
||||
static func buildBlock<T>(_ x: T) -> T { x }
|
||||
static func buildExpression<T>(_ x: T) -> T { x }
|
||||
}
|
||||
|
||||
// https://github.com/swiftlang/swift/issues/79696
|
||||
// Make sure we don't pick up the builder as the container type.
|
||||
struct A {
|
||||
struct B {
|
||||
@Builder
|
||||
var foo: Any {
|
||||
B
|
||||
// RUN: %sourcekitd-test -req=cursor -pos=%(line-1):7 %s -- %s | %FileCheck %s --check-prefix NESTED_TY
|
||||
// NESTED_TY-NOT: Container
|
||||
}
|
||||
@Builder var bar: Any {
|
||||
foo
|
||||
// RUN: %sourcekitd-test -req=cursor -pos=%(line-1):7 %s -- %s | %FileCheck %s --check-prefix PROP
|
||||
// PROP: <Container>$s4main1AV1BVD</Container>
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user