Skip to content

Commit c4cbe7f

Browse files
committed
---
yaml --- r: 348852 b: refs/heads/master c: b5a0d58 h: refs/heads/master
1 parent c941876 commit c4cbe7f

File tree

3 files changed

+94
-21
lines changed

3 files changed

+94
-21
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 12c1db9c939fc741c8af719e164b246c564b6f96
2+
refs/heads/master: b5a0d58dc0c8fbbc320b83e48927355a7c58663e
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/lib/Sema/CSDiagnostics.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5037,8 +5037,8 @@ bool ArgumentMismatchFailure::diagnoseAsNote() {
50375037
auto argToParam = locator->findFirst<LocatorPathElt::ApplyArgToParam>();
50385038
assert(argToParam);
50395039

5040-
if (auto *decl = getDecl()) {
5041-
emitDiagnostic(decl, diag::candidate_has_invalid_argument_at_position,
5040+
if (auto *callee = getCallee()) {
5041+
emitDiagnostic(callee, diag::candidate_has_invalid_argument_at_position,
50425042
getToType(), argToParam->getParamIdx());
50435043
return true;
50445044
}
@@ -5066,11 +5066,10 @@ bool ArgumentMismatchFailure::diagnoseUseOfReferenceEqualityOperator() const {
50665066
// one would cover both arguments.
50675067
if (getAnchor() == rhs && rhsType->is<FunctionType>()) {
50685068
auto &cs = getConstraintSystem();
5069-
auto info = getFunctionArgApplyInfo(locator);
5070-
if (info && cs.hasFixFor(cs.getConstraintLocator(
5071-
binaryOp, {ConstraintLocator::ApplyArgument,
5072-
LocatorPathElt::ApplyArgToParam(
5073-
0, 0, info->getParameterFlagsAtIndex(0))})))
5069+
if (cs.hasFixFor(cs.getConstraintLocator(
5070+
binaryOp, {ConstraintLocator::ApplyArgument,
5071+
LocatorPathElt::ApplyArgToParam(
5072+
0, 0, getParameterFlagsAtIndex(0))})))
50745073
return true;
50755074
}
50765075

@@ -5228,14 +5227,12 @@ bool ArgumentMismatchFailure::diagnoseMisplacedMissingArgument() const {
52285227
if (!MissingArgumentsFailure::isMisplacedMissingArgument(cs, locator))
52295228
return false;
52305229

5231-
auto info = *getFunctionArgApplyInfo(locator);
5232-
52335230
auto *argType = cs.createTypeVariable(
52345231
cs.getConstraintLocator(locator, LocatorPathElt::SynthesizedArgument(1)),
52355232
/*flags=*/0);
52365233

52375234
// Assign new type variable to a type of a parameter.
5238-
auto *fnType = info.getFnType();
5235+
auto *fnType = getFnType();
52395236
const auto &param = fnType->getParams()[0];
52405237
cs.assignFixedType(argType, param.getOldType());
52415238

trunk/lib/Sema/CSDiagnostics.h

Lines changed: 86 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,10 +1752,17 @@ class FunctionArgApplyInfo {
17521752
/// func bar(_ v: Int) { foo(v) } // `Int` is not convertible to `String`
17531753
/// ```
17541754
class ArgumentMismatchFailure : public ContextualFailure {
1755+
// FIXME: Currently ArgumentMismatchFailure can be used from CSDiag, in which
1756+
// case it's possible we're not able to resolve the arg apply info. Once
1757+
// the CSDiag logic has been removed, we should be able to store Info
1758+
// unwrapped.
1759+
Optional<FunctionArgApplyInfo> Info;
1760+
17551761
public:
17561762
ArgumentMismatchFailure(Expr *root, ConstraintSystem &cs, Type argType,
17571763
Type paramType, ConstraintLocator *locator)
1758-
: ContextualFailure(root, cs, argType, paramType, locator) {}
1764+
: ContextualFailure(root, cs, argType, paramType, locator),
1765+
Info(getFunctionArgApplyInfo(getLocator())) {}
17591766

17601767
bool diagnoseAsError() override;
17611768
bool diagnoseAsNote() override;
@@ -1772,6 +1779,84 @@ class ArgumentMismatchFailure : public ContextualFailure {
17721779
bool diagnoseUseOfReferenceEqualityOperator() const;
17731780

17741781
protected:
1782+
/// \returns The position of the argument being diagnosed, starting at 1.
1783+
unsigned getArgPosition() const { return Info->getArgPosition(); }
1784+
1785+
/// \returns The position of the parameter being diagnosed, starting at 1.
1786+
unsigned getParamPosition() const { return Info->getParamPosition(); }
1787+
1788+
/// Returns the argument expression being diagnosed.
1789+
///
1790+
/// Note this may differ from \c getAnchor(), which will return a smaller
1791+
/// sub-expression if the failed constraint is for a sub-expression within
1792+
/// an argument. For example, in an argument conversion from (T, U) to (U, U),
1793+
/// the conversion from T to U may fail. In this case, \c getArgExpr() will
1794+
/// return the (T, U) expression, whereas \c getAnchor() will return the T
1795+
/// expression.
1796+
Expr *getArgExpr() const { return Info->getArgExpr(); }
1797+
1798+
/// Returns the argument type for the conversion being diagnosed.
1799+
///
1800+
/// \param withSpecifier Whether to keep the inout or @lvalue specifier of
1801+
/// the argument, if any.
1802+
///
1803+
/// Note this may differ from \c getFromType(), which will give the source
1804+
/// type of a failed constraint for the argument conversion. For example in
1805+
/// an argument conversion from T? to U?, the conversion from T to U may fail.
1806+
/// In this case, \c getArgType() will return T?, whereas \c getFromType()
1807+
/// will return T.
1808+
Type getArgType(bool withSpecifier = false) const {
1809+
return Info->getArgType(withSpecifier);
1810+
}
1811+
1812+
/// \returns The interface type for the function being applied.
1813+
Type getFnInterfaceType() const { return Info->getFnInterfaceType(); }
1814+
1815+
/// \returns The function type being applied, including any generic
1816+
/// substitutions.
1817+
FunctionType *getFnType() const { return Info->getFnType(); }
1818+
1819+
/// \returns The callee for the argument conversion, if any.
1820+
const ValueDecl *getCallee() const {
1821+
return Info ? Info->getCallee() : nullptr;
1822+
}
1823+
1824+
/// \returns The full name of the callee, or a null decl name if there is no
1825+
/// callee.
1826+
DeclName getCalleeFullName() const {
1827+
return getCallee() ? getCallee()->getFullName() : DeclName();
1828+
}
1829+
1830+
/// Returns the type of the parameter involved in the mismatch, including any
1831+
/// generic substitutions.
1832+
///
1833+
/// \param lookThroughAutoclosure Whether an @autoclosure () -> T parameter
1834+
/// should be treated as being of type T.
1835+
///
1836+
/// Note this may differ from \c getToType(), see the note on \c getArgType().
1837+
Type getParamType(bool lookThroughAutoclosure = true) const {
1838+
return Info->getParamType(lookThroughAutoclosure);
1839+
}
1840+
1841+
/// Returns the type of the parameter involved in the mismatch.
1842+
///
1843+
/// \param lookThroughAutoclosure Whether an @autoclosure () -> T parameter
1844+
/// should be treated as being of type T.
1845+
///
1846+
/// Note this may differ from \c getToType(), see the note on \c getArgType().
1847+
Type getParamInterfaceType(bool lookThroughAutoclosure = true) const {
1848+
return Info->getParamInterfaceType(lookThroughAutoclosure);
1849+
}
1850+
1851+
/// \returns The flags of the parameter involved in the mismatch.
1852+
ParameterTypeFlags getParameterFlags() const {
1853+
return Info->getParameterFlags();
1854+
}
1855+
1856+
/// \returns The flags of a parameter at a given index.
1857+
ParameterTypeFlags getParameterFlagsAtIndex(unsigned idx) const {
1858+
return Info->getParameterFlagsAtIndex(idx);
1859+
}
17751860

17761861
/// Situations like this:
17771862
///
@@ -1783,15 +1868,6 @@ class ArgumentMismatchFailure : public ContextualFailure {
17831868
bool diagnoseMisplacedMissingArgument() const;
17841869

17851870
SourceLoc getLoc() const { return getAnchor()->getLoc(); }
1786-
1787-
ValueDecl *getDecl() const {
1788-
auto selectedOverload = getChoiceFor(getLocator());
1789-
if (!selectedOverload)
1790-
return nullptr;
1791-
1792-
auto choice = selectedOverload->choice;
1793-
return choice.getDeclOrNull();
1794-
}
17951871
};
17961872

17971873
} // end namespace constraints

0 commit comments

Comments
 (0)