Skip to content

Commit f70de4b

Browse files
committed
---
yaml --- r: 325999 b: refs/heads/master-next c: 34a12aa h: refs/heads/master i: 325997: 7fe062e 325995: 4668a81 325991: bbff5fa 325983: d7be5ba
1 parent 1976b7a commit f70de4b

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: e052da7d8886fa0439677852e8f7830b20c2e1da
3-
refs/heads/master-next: 0f24f7e05a9e640264a1a067a4ef57b891754f5a
3+
refs/heads/master-next: 34a12aa30e5f697cbbffd4a355e71ae8ffb1fa4d
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/include/swift/AST/DiagnosticsSema.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,11 @@ ERROR(cannot_convert_default_arg_value_nil,none,
379379
ERROR(cannot_convert_argument_value,none,
380380
"cannot convert value of type %0 to expected argument type %1",
381381
(Type,Type))
382+
383+
NOTE(candidate_has_invalid_argument_at_position,none,
384+
"candidate expects value of type %0 at psoition #%1",
385+
(Type, unsigned))
386+
382387
ERROR(cannot_convert_argument_value_generic,none,
383388
"cannot convert value of type %0 (%1) to expected argument type %2 (%3)",
384389
(Type, StringRef, Type, StringRef))

branches/master-next/lib/Sema/CSDiagnostics.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4447,3 +4447,25 @@ void InOutConversionFailure::fixItChangeArgumentType() const {
44474447
actualType, neededType)
44484448
.fixItReplaceChars(startLoc, endLoc, scratch);
44494449
}
4450+
4451+
bool ArgumentMismatchFailure::diagnoseAsError() {
4452+
emitDiagnostic(getLoc(), diag::cannot_convert_argument_value, getFromType(),
4453+
getToType());
4454+
return true;
4455+
}
4456+
4457+
bool ArgumentMismatchFailure::diagnoseAsNote() {
4458+
auto *locator = getLocator();
4459+
auto argToParam = locator->findFirst<LocatorPathElt::ApplyArgToParam>();
4460+
assert(argToParam);
4461+
4462+
if (auto overload = getChoiceFor(getRawAnchor())) {
4463+
if (auto *decl = overload->choice.getDeclOrNull()) {
4464+
emitDiagnostic(decl, diag::candidate_has_invalid_argument_at_position,
4465+
getToType(), argToParam->getParamIdx());
4466+
return true;
4467+
}
4468+
}
4469+
4470+
return false;
4471+
}

branches/master-next/lib/Sema/CSDiagnostics.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,26 @@ class InvalidTupleSplatWithSingleParameterFailure final
15991599
bool diagnoseAsError() override;
16001600
};
16011601

1602+
/// Diagnose a situation there is a mismatch between argument and parameter
1603+
/// types e.g.:
1604+
///
1605+
/// ```swift
1606+
/// func foo(_: String) {}
1607+
/// func bar(_ v: Int) { foo(v) } // `Int` is not convertible to `String`
1608+
/// ```
1609+
class ArgumentMismatchFailure : public ContextualFailure {
1610+
public:
1611+
ArgumentMismatchFailure(Expr *root, ConstraintSystem &cs, Type argType,
1612+
Type paramType, ConstraintLocator *locator)
1613+
: ContextualFailure(root, cs, argType, paramType, locator) {}
1614+
1615+
bool diagnoseAsError() override;
1616+
bool diagnoseAsNote() override;
1617+
1618+
protected:
1619+
SourceLoc getLoc() const { return getAnchor()->getLoc(); }
1620+
};
1621+
16021622
/// Provides information about the application of a function argument to a
16031623
/// parameter.
16041624
class FunctionArgApplyInfo {

branches/master-next/lib/Sema/CSFix.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,10 @@ AllowInOutConversion *AllowInOutConversion::create(ConstraintSystem &cs,
774774
}
775775

776776
bool AllowArgumentMismatch::diagnose(Expr *root, bool asNote) const {
777-
return false;
777+
auto &cs = getConstraintSystem();
778+
ArgumentMismatchFailure failure(root, cs, getFromType(), getToType(),
779+
getLocator());
780+
return failure.diagnose(asNote);
778781
}
779782

780783
AllowArgumentMismatch *

0 commit comments

Comments
 (0)