diff --git a/lib/Sema/CSFix.cpp b/lib/Sema/CSFix.cpp index d8979dd2476e7..a098b4624015f 100644 --- a/lib/Sema/CSFix.cpp +++ b/lib/Sema/CSFix.cpp @@ -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()) { + auto fromFnType = fromType->getAs(); + auto toFnType = toType->getAs(); + 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(locator->getAnchor())) { return std::make_tuple(CTP_CoerceOperand, solution.getType(coerceExpr->getSubExpr()), diff --git a/test/IDE/complete_inout.swift b/test/IDE/complete_inout.swift new file mode 100644 index 0000000000000..b0c2c53492ec1 --- /dev/null +++ b/test/IDE/complete_inout.swift @@ -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) {} +} + +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 \ No newline at end of file diff --git a/test/expr/closure/closures.swift b/test/expr/closure/closures.swift index 9da2a79f6c75e..2ee7694387f68 100644 --- a/test/expr/closure/closures.swift +++ b/test/expr/closure/closures.swift @@ -589,3 +589,20 @@ class SR14120 { } } } + +// SR-14678 +func call(_ : 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) + } +}