Skip to content

Commit bf61578

Browse files
committed
[Macros] Don't assert when a macro parameter has a default argument
1 parent 85ba74b commit bf61578

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9502,9 +9502,8 @@ ParserResult<MacroDecl> Parser::parseDeclMacro(DeclAttributes &attributes) {
95029502
} else {
95039503
// Parameter list.
95049504
SmallVector<Identifier, 2> namePieces;
9505-
DefaultArgumentInfo defaultArgs;
95069505
auto parameterResult = parseSingleParameterClause(
9507-
ParameterContextKind::Macro, &namePieces, &defaultArgs);
9506+
ParameterContextKind::Macro, &namePieces, nullptr);
95089507
status |= parameterResult;
95099508
parameterList = parameterResult.getPtrOrNull();
95109509

test/Macros/macros_diagnostics.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,8 @@ func testExternalMacroOutOfPlace() {
134134
let _: Int = #externalMacro(module: "A", type: "B")
135135
// expected-error@-1{{macro 'externalMacro' can only be used to define another macro}}
136136
}
137+
138+
@freestanding(expression)
139+
public macro macroWithDefaults(_: Int = 17) = #externalMacro(module: "A", type: "B")
140+
// expected-error@-1{{default arguments are not allowed in macros}}
141+
// expected-warning@-2{{external macro implementation type 'A.B' could not be found for macro 'macroWithDefaults'}}

0 commit comments

Comments
 (0)