mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge remote-tracking branch 'origin/main' into rebranch
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
17
test/IDE/complete_singlevaluestmt_return.swift
Normal file
17
test/IDE/complete_singlevaluestmt_return.swift
Normal 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
|
||||
}
|
||||
|
||||
@@ -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 #^^#
|
||||
}
|
||||
@@ -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 {
|
||||
}
|
||||
@@ -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 {
|
||||
Reference in New Issue
Block a user