Skip to content

Commit

Permalink
[CSFix] Teach getStructuralTypeContext about tuple initialization c…
Browse files Browse the repository at this point in the history
…alls
  • Loading branch information
xedin committed Feb 18, 2020
1 parent 802e141 commit bb656e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/Sema/CSFix.cpp
Expand Up @@ -283,6 +283,11 @@ getStructuralTypeContext(ConstraintSystem &cs, ConstraintLocator *locator) {
return std::make_tuple(CTP_AssignSource,
cs.getType(assignExpr->getSrc()),
cs.getType(assignExpr->getDest()));
} else if (auto *call = dyn_cast<CallExpr>(locator->getAnchor())) {
assert(isa<TypeExpr>(call->getFn()));
return std::make_tuple(CTP_Initialization,
cs.getType(call->getFn())->getMetatypeInstanceType(),
cs.getType(call->getArg()));
}

return None;
Expand Down
7 changes: 4 additions & 3 deletions test/Constraints/diagnostics.swift
Expand Up @@ -666,9 +666,10 @@ _ = (i = 6) ? 42 : 57 // expected-error {{use of '=' in a boolean context, did y
// <rdar://problem/22263468> QoI: Not producing specific argument conversion diagnostic for tuple init
func r22263468(_ a : String?) {
typealias MyTuple = (Int, String)
_ = MyTuple(42, a) // expected-error {{value of optional type 'String?' must be unwrapped to a value of type 'String'}}
// expected-note@-1{{coalesce using '??' to provide a default when the optional value contains 'nil'}}
// expected-note@-2{{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
// TODO(diagnostics): This is a regression from diagnosing missing optional unwrap for `a`, we have to
// re-think the way errors in tuple elements are detected because it's currently impossible to detect
// exactly what went wrong here and aggregate fixes for different elements at the same time.
_ = MyTuple(42, a) // expected-error {{tuple type 'MyTuple' (aka '(Int, String)') is not convertible to tuple type '(Int, String?)'}}
}


Expand Down

0 comments on commit bb656e1

Please sign in to comment.