Skip to content

[5.5][Sema] Don’t allow unresolved type variables if LeaveBraceStmtBodyUnchecked is true #37309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6593,6 +6593,13 @@ void CodeCompletionCallbacksImpl::doneParsing() {
if (isDynamicLookup(*ExprType))
Lookup.setIsDynamicLookup();
Lookup.getValueExprCompletions(*ExprType, ReferencedDecl.getDecl());
/// We set the type of ParsedExpr explicitly above. But we don't want an
/// unresolved type in our AST when we type check again for operator
/// completions. Remove the type of the ParsedExpr and see if we can come up
/// with something more useful based on the the full sequence expression.
if (ParsedExpr->getType()->is<UnresolvedType>()) {
ParsedExpr->setType(nullptr);
}
Lookup.getOperatorCompletions(ParsedExpr, leadingSequenceExprs);
Lookup.getPostfixKeywordCompletions(*ExprType, ParsedExpr);
break;
Expand Down
1 change: 0 additions & 1 deletion lib/Sema/TypeCheckStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,6 @@ void StmtChecker::typeCheckASTNode(ASTNode &node) {
options |= TypeCheckExprFlags::IsDiscarded;
if (LeaveBraceStmtBodyUnchecked) {
options |= TypeCheckExprFlags::LeaveClosureBodyUnchecked;
options |= TypeCheckExprFlags::AllowUnresolvedTypeVariables;
}

auto resultTy =
Expand Down
2 changes: 1 addition & 1 deletion test/IDE/complete_call_arg.swift
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func curry<T1, T2, R>(_ f: @escaping (T1, T2) -> R) -> (T1) -> (T2) -> R {
return { t1 in { t2 in f(#^NESTED_CLOSURE^#, t2) } }
// NESTED_CLOSURE: Begin completions
// FIXME: Should be '/TypeRelation[Invalid]: t2[#T2#]'
// NESTED_CLOSURE: Decl[LocalVar]/Local: t2[#_#]; name=t2
// NESTED_CLOSURE: Decl[LocalVar]/Local: t2; name=t2
// NESTED_CLOSURE: Decl[LocalVar]/Local: t1[#T1#]; name=t1
}

Expand Down
21 changes: 21 additions & 0 deletions validation-test/IDE/crashers_2_fixed/rdar76686564.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: %target-swift-ide-test --conforming-methods -code-completion-token=COMPLETE --conforming-methods-expected-types=s:14swift_ide_test10MySequenceP -source-filename %s

protocol MySequence {
associatedtype Element
}

struct Foo<X>: MySequence {
typealias Element = X
}

struct ArgumentDefinition {
fileprivate func bashCompletionWords() -> Foo<String> { fatalError() }
}

func myFlatMap<SegmentOfResult: MySequence>(_ transform: (ArgumentDefinition) -> SegmentOfResult) -> Foo<SegmentOfResult.Element> {
fatalError()
}

func generateArgumentWords() {
_ = myFlatMap { $0.#^COMPLETE^# } as Foo<String>
}