Skip to content

Commit bdc01ea

Browse files
committed
[Macros] Handle macro argument lists in diagnostics
This improves diagnostics for missing/extra/incorrectly-labeled arguments.
1 parent 0407610 commit bdc01ea

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4753,7 +4753,8 @@ bool MissingArgumentsFailure::diagnoseSingleMissingArgument() const {
47534753
auto anchor = getRawAnchor();
47544754
if (!(isExpr<CallExpr>(anchor) || isExpr<SubscriptExpr>(anchor) ||
47554755
isExpr<UnresolvedMemberExpr>(anchor) ||
4756-
isExpr<ObjectLiteralExpr>(anchor)))
4756+
isExpr<ObjectLiteralExpr>(anchor) ||
4757+
isExpr<MacroExpansionExpr>(anchor)))
47574758
return false;
47584759

47594760
if (SynthesizedArgs.size() != 1)
@@ -5112,6 +5113,8 @@ MissingArgumentsFailure::getCallInfo(ASTNode anchor) const {
51125113
return std::make_pair((Expr *)SE, SE->getArgs());
51135114
} else if (auto *OLE = getAsExpr<ObjectLiteralExpr>(anchor)) {
51145115
return std::make_pair((Expr *)OLE, OLE->getArgs());
5116+
} else if (auto *ME = getAsExpr<MacroExpansionExpr>(anchor)) {
5117+
return std::make_pair((Expr *)ME, ME->getArgs());
51155118
}
51165119
return None;
51175120
}

test/Macros/macros_diagnostics.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// REQUIRES: executable_test
77

88
@expression macro stringify<T>(_ value: T) -> (T, String) = MacroDefinition.StringifyMacro
9+
// expected-note@-1{{'stringify' declared here}}
910
@expression macro missingMacro1(_: Any) = MissingModule.MissingType // expected-note{{'missingMacro1' declared here}}
1011
@expression macro missingMacro2(_: Any) = MissingModule.MissingType
1112

@@ -40,6 +41,11 @@ struct ZZZ {
4041
func test(a: Int, b: Int) {
4142
// FIXME: Bad diagnostic.
4243
let s = #stringify<Int, Int>(a + b) // expected-error{{type of expression is ambiguous without more context}}
44+
45+
_ = #stringify()
46+
// expected-error@-1{{missing argument for parameter #1 in call}}
47+
_ = #stringify(label: a + b)
48+
// expected-error@-1{{extraneous argument label 'label:' in call}}
4349
}
4450

4551
func shadow(a: Int, b: Int, stringify: Int) {

0 commit comments

Comments
 (0)