Skip to content
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
18 changes: 15 additions & 3 deletions lib/Sema/CSFix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,21 @@ getStructuralTypeContext(const Solution &solution, ConstraintLocator *locator) {
return std::make_tuple(contextualTypeElt->getPurpose(), exprType,
contextualType);
} else if (auto argApplyInfo = solution.getFunctionArgApplyInfo(locator)) {
return std::make_tuple(CTP_CallArgument,
argApplyInfo->getArgType(),
argApplyInfo->getParamType());
Type fromType = argApplyInfo->getArgType();
Type toType = argApplyInfo->getParamType();
// In case locator points to the function result we want the
// argument and param function types result.
if (locator->isLastElement<LocatorPathElt::FunctionResult>()) {
auto fromFnType = fromType->getAs<FunctionType>();
auto toFnType = toType->getAs<FunctionType>();
if (fromFnType && toFnType) {
auto &cs = solution.getConstraintSystem();
return std::make_tuple(
cs.getContextualTypePurpose(locator->getAnchor()),
fromFnType->getResult(), toFnType->getResult());
}
}
return std::make_tuple(CTP_CallArgument, fromType, toType);
} else if (auto *coerceExpr = getAsExpr<CoerceExpr>(locator->getAnchor())) {
return std::make_tuple(CTP_CoerceOperand,
solution.getType(coerceExpr->getSubExpr()),
Expand Down
18 changes: 18 additions & 0 deletions test/IDE/complete_inout.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t

struct Bar() {
init?(withInout: inout Int) {}
init?(withPointer: UnsafePointer<Int>) {}
}

struct Foo {
var myInt: Int

func bar() {
let context = Bar(wihtInout: &self.#^COMPLETE_INOUT?check=CHECK^#)
let context = Bar(withPointer: &self.#^COMPLETE_POINTER?check=CHECK^#)
}
}

// CHECK: Decl[InstanceVar]/CurrNominal: myInt[#Int#]; name=myInt
17 changes: 17 additions & 0 deletions test/expr/closure/closures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -589,3 +589,20 @@ class SR14120 {
}
}
}

// SR-14678
func call<T>(_ : Int, _ f: () -> (T, Int)) -> (T, Int) {
f()
}

func testSR14678() -> (Int, Int) {
call(1) { // expected-error {{cannot convert return expression of type '((), Int)' to return type '(Int, Int)'}}
(print("hello"), 0)
}
}

func testSR14678_Optional() -> (Int, Int)? {
call(1) { // expected-error {{cannot convert return expression of type '((), Int)' to return type '(Int, Int)'}}
(print("hello"), 0)
}
}