Skip to content

Commit d0c9b6b

Browse files
authored
Merge pull request #37309 from ahoppen/pr-5.5/conforming-methods-in-closure
[5.5][Sema] Don’t allow unresolved type variables if `LeaveBraceStmtBodyUnchecked` is `true`
2 parents ce3f107 + f297187 commit d0c9b6b

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6593,6 +6593,13 @@ void CodeCompletionCallbacksImpl::doneParsing() {
65936593
if (isDynamicLookup(*ExprType))
65946594
Lookup.setIsDynamicLookup();
65956595
Lookup.getValueExprCompletions(*ExprType, ReferencedDecl.getDecl());
6596+
/// We set the type of ParsedExpr explicitly above. But we don't want an
6597+
/// unresolved type in our AST when we type check again for operator
6598+
/// completions. Remove the type of the ParsedExpr and see if we can come up
6599+
/// with something more useful based on the the full sequence expression.
6600+
if (ParsedExpr->getType()->is<UnresolvedType>()) {
6601+
ParsedExpr->setType(nullptr);
6602+
}
65966603
Lookup.getOperatorCompletions(ParsedExpr, leadingSequenceExprs);
65976604
Lookup.getPostfixKeywordCompletions(*ExprType, ParsedExpr);
65986605
break;

lib/Sema/TypeCheckStmt.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,6 @@ void StmtChecker::typeCheckASTNode(ASTNode &node) {
15061506
options |= TypeCheckExprFlags::IsDiscarded;
15071507
if (LeaveBraceStmtBodyUnchecked) {
15081508
options |= TypeCheckExprFlags::LeaveClosureBodyUnchecked;
1509-
options |= TypeCheckExprFlags::AllowUnresolvedTypeVariables;
15101509
}
15111510

15121511
auto resultTy =

test/IDE/complete_call_arg.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ func curry<T1, T2, R>(_ f: @escaping (T1, T2) -> R) -> (T1) -> (T2) -> R {
439439
return { t1 in { t2 in f(#^NESTED_CLOSURE^#, t2) } }
440440
// NESTED_CLOSURE: Begin completions
441441
// FIXME: Should be '/TypeRelation[Invalid]: t2[#T2#]'
442-
// NESTED_CLOSURE: Decl[LocalVar]/Local: t2[#_#]; name=t2
442+
// NESTED_CLOSURE: Decl[LocalVar]/Local: t2; name=t2
443443
// NESTED_CLOSURE: Decl[LocalVar]/Local: t1[#T1#]; name=t1
444444
}
445445

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-swift-ide-test --conforming-methods -code-completion-token=COMPLETE --conforming-methods-expected-types=s:14swift_ide_test10MySequenceP -source-filename %s
2+
3+
protocol MySequence {
4+
associatedtype Element
5+
}
6+
7+
struct Foo<X>: MySequence {
8+
typealias Element = X
9+
}
10+
11+
struct ArgumentDefinition {
12+
fileprivate func bashCompletionWords() -> Foo<String> { fatalError() }
13+
}
14+
15+
func myFlatMap<SegmentOfResult: MySequence>(_ transform: (ArgumentDefinition) -> SegmentOfResult) -> Foo<SegmentOfResult.Element> {
16+
fatalError()
17+
}
18+
19+
func generateArgumentWords() {
20+
_ = myFlatMap { $0.#^COMPLETE^# } as Foo<String>
21+
}

0 commit comments

Comments
 (0)