Skip to content

Commit fe4bac5

Browse files
authored
Merge pull request #6187 from xedin/SR-3248
2 parents 1088c02 + 37c6bdd commit fe4bac5

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,10 @@ namespace {
854854
->getForwardingSubstitutions(M);
855855
entityType = GFT->substGenericArgs(subs);
856856
} else {
857+
if (auto objType =
858+
entityType->getImplicitlyUnwrappedOptionalObjectType())
859+
entityType = objType;
860+
857861
entityType = DC->mapTypeIntoContext(entityType);
858862
}
859863
}
@@ -5620,7 +5624,14 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
56205624
callExpr->setFn(operatorRef);
56215625
};
56225626

5623-
auto fnType = fnExpr->getType()->getRValueType();
5627+
auto getFuncType = [](Type type) -> Type {
5628+
auto fnType = type->getRValueType();
5629+
if (auto objectType = fnType->getImplicitlyUnwrappedOptionalObjectType())
5630+
return objectType;
5631+
return fnType;
5632+
};
5633+
5634+
auto fnType = getFuncType(fnExpr->getType());
56245635

56255636
// If we have a contextual type, and if we have an ambiguously typed function
56265637
// result from our previous check, we re-type-check it using this contextual
@@ -5631,9 +5642,8 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
56315642
// produce better diagnostics below by diagnosing this here rather than trying
56325643
// to peel apart the failed conversion to function type.
56335644
if (CS->getContextualType() &&
5634-
(isUnresolvedOrTypeVarType(fnExpr->getType()) ||
5635-
(fnExpr->getType()->is<AnyFunctionType>() &&
5636-
fnExpr->getType()->hasUnresolvedType()))) {
5645+
(isUnresolvedOrTypeVarType(fnType) ||
5646+
(fnType->is<AnyFunctionType>() && fnType->hasUnresolvedType()))) {
56375647
// FIXME: Prevent typeCheckChildIndependently from transforming expressions,
56385648
// because if we try to typecheck OSR expression with contextual type,
56395649
// it'll end up converting it into DeclRefExpr based on contextual info,
@@ -5650,15 +5660,15 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
56505660
&listener);
56515661

56525662
if (type.hasValue())
5653-
fnType = type.getValue()->getRValueType();
5663+
fnType = getFuncType(type.getValue());
56545664
} else {
56555665
fnExpr = typeCheckChildIndependently(callExpr->getFn(), Type(),
56565666
CTP_CalleeResult, TCC_ForceRecheck,
56575667
&listener);
56585668
if (!fnExpr)
56595669
return true;
56605670

5661-
fnType = fnExpr->getType()->getRValueType();
5671+
fnType = getFuncType(fnExpr->getType());
56625672
}
56635673
}
56645674

test/Constraints/optional.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,17 @@ func sr2752(x: String?, y: String?) {
147147
y.map { _ in "" } ?? "\(xx)"
148148
}
149149
}
150+
151+
// SR-3248 - Invalid diagnostic calling implicitly unwrapped closure
152+
var sr3248 : ((Int) -> ())!
153+
sr3248?(a: 2) // expected-error {{extraneous argument label 'a:' in call}}
154+
sr3248!(a: 2) // expected-error {{extraneous argument label 'a:' in call}}
155+
sr3248(a: 2) // expected-error {{extraneous argument label 'a:' in call}}
156+
157+
struct SR_3248 {
158+
var callback: (([AnyObject]) -> Void)!
159+
}
160+
161+
SR_3248().callback?("test") // expected-error {{cannot convert value of type 'String' to expected argument type '[AnyObject]'}}
162+
SR_3248().callback!("test") // expected-error {{cannot convert value of type 'String' to expected argument type '[AnyObject]'}}
163+
SR_3248().callback("test") // expected-error {{cannot convert value of type 'String' to expected argument type '[AnyObject]'}}

0 commit comments

Comments
 (0)