Merge remote-tracking branch 'origin/main' into rebranch

This commit is contained in:
swift-ci
2025-09-15 01:41:51 -07:00
9 changed files with 67 additions and 5 deletions

View File

@@ -225,6 +225,10 @@ public:
ASTNode findAsyncNode();
/// Whether the body contains an explicit `return` statement. This computation
/// is cached.
bool hasExplicitReturnStmt(ASTContext &ctx) const;
/// If this brace contains a single ASTNode, or a \c #if that has a single active
/// element, returns it. This will always be the last element of the brace.
/// Otherwise returns \c nullptr.

View File

@@ -301,6 +301,11 @@ ASTNode BraceStmt::findAsyncNode() {
return asyncFinder.getAsyncNode();
}
bool BraceStmt::hasExplicitReturnStmt(ASTContext &ctx) const {
return evaluateOrDefault(ctx.evaluator,
BraceHasExplicitReturnStmtRequest{this}, false);
}
static bool hasSingleActiveElement(ArrayRef<ASTNode> elts) {
return elts.size() == 1;
}

View File

@@ -1289,9 +1289,7 @@ bool AnyFunctionRef::bodyHasExplicitReturnStmt() const {
return false;
}
auto &ctx = getAsDeclContext()->getASTContext();
return evaluateOrDefault(ctx.evaluator,
BraceHasExplicitReturnStmtRequest{body}, false);
return body->hasExplicitReturnStmt(getAsDeclContext()->getASTContext());
}
void AnyFunctionRef::getExplicitReturnStmts(

View File

@@ -309,10 +309,13 @@ static bool isViableElement(ASTNode element,
// Skip if we're doing completion for a SingleValueStmtExpr, and have a
// brace that doesn't involve a single expression, and doesn't have a
// code completion token, as it won't contribute to the type of the
// SingleValueStmtExpr.
// SingleValueStmtExpr. We also need to skip if the body has a ReturnStmt,
// which isn't something that's currently allowed, but is necessary to
// correctly infer the contextual type without leaving it unbound.
if (isForSingleValueStmtCompletion &&
!SingleValueStmtExpr::hasResult(braceStmt) &&
!cs.containsIDEInspectionTarget(braceStmt)) {
!cs.containsIDEInspectionTarget(braceStmt) &&
!braceStmt->hasExplicitReturnStmt(cs.getASTContext())) {
return false;
}
}

View File

@@ -279,6 +279,19 @@ public:
return PlaceholderType::get(cs.getASTContext(), errTy);
}
Type transformDependentMemberType(DependentMemberType *DMT) {
auto assocTy = DMT->getAssocType();
ASSERT(assocTy && "Should not have structural type here");
// If the new base is a hole, propagate it to cover the entire
// DependentMemberType.
auto newBase = transform(DMT->getBase());
if (newBase->isPlaceholder())
return PlaceholderType::get(cs.getASTContext(), DMT);
return DependentMemberType::get(newBase, assocTy);
}
Type transform(Type type) {
if (!type)
return type;
@@ -308,6 +321,8 @@ public:
return transformTypeAliasType(aliasTy);
if (auto *errTy = dyn_cast<ErrorType>(tyPtr))
return transformErrorType(errTy);
if (auto *DMT = dyn_cast<DependentMemberType>(tyPtr))
return transformDependentMemberType(DMT);
return std::nullopt;
});

View File

@@ -0,0 +1,17 @@
// RUN: %batch-code-completion
struct S {
var str: String
}
_ = {
let k = if .random() {
return ""
} else {
S()
}
// Make sure we can still infer 'k' here.
return k.#^COMPLETE_ON_SVE_WITH_RET^#
// COMPLETE_ON_SVE_WITH_RET: Decl[InstanceVar]/CurrNominal/TypeRelation[Convertible]: str[#String#]; name=str
}

View File

@@ -0,0 +1,9 @@
// {"kind":"complete","original":"0bd7af1f","signature":"swift::constraints::TypeVarRefCollector::walkToStmtPre(swift::Stmt*)","signatureAssert":"Assertion failed: (result), function getClosureType"}
// RUN: %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s
{
let a =
if <#expression#> {
return
}
return #^^#
}

View File

@@ -0,0 +1,4 @@
// {"kind":"typecheck","original":"9e6249db","signature":"(anonymous namespace)::ConstraintGenerator::visitApplyExpr(swift::ApplyExpr*)"}
// RUN: not %target-swift-frontend -typecheck %s
(a as Sequence).Element {
}

View File

@@ -0,0 +1,7 @@
// {"kind":"typecheck","original":"5e6f691d","signature":"(anonymous namespace)::ConstraintGenerator::visitApplyExpr(swift::ApplyExpr*)"}
// RUN: not %target-swift-frontend -typecheck %s
protocol a {
associatedtype b
struct c<d, a {
e {
d.b {