File tree Expand file tree Collapse file tree 5 files changed +26
-3
lines changed Expand file tree Collapse file tree 5 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -519,6 +519,12 @@ class alignas(1 << DeclContextAlignInBits) DeclContext
519
519
LLVM_READONLY
520
520
SourceFile *getParentSourceFile () const ;
521
521
522
+ // / Returns the "outermost" source file that contains this context,
523
+ // / looking through any source files for generated code, such as
524
+ // / macro expansions.
525
+ LLVM_READONLY
526
+ SourceFile *getOutermostParentSourceFile () const ;
527
+
522
528
// / Determine whether this declaration context is generic, meaning that it or
523
529
// / any of its parents have generic parameters.
524
530
bool isGenericContext () const ;
Original file line number Diff line number Diff line change @@ -323,6 +323,18 @@ SourceFile *DeclContext::getParentSourceFile() const {
323
323
return fallbackSF;
324
324
}
325
325
326
+ SourceFile *DeclContext::getOutermostParentSourceFile () const {
327
+ auto sf = getParentSourceFile ();
328
+ if (!sf)
329
+ return nullptr ;
330
+
331
+ // Find the originating source file.
332
+ while (auto enclosingSF = sf->getEnclosingSourceFile ())
333
+ sf = enclosingSF;
334
+
335
+ return sf;
336
+ }
337
+
326
338
DeclContext *DeclContext::getModuleScopeContext () const {
327
339
auto DC = const_cast <DeclContext*>(this );
328
340
Original file line number Diff line number Diff line change @@ -1919,10 +1919,11 @@ IRGenModule *IRGenerator::getGenModule(DeclContext *ctxt) {
1919
1919
if (GenModules.size () == 1 || !ctxt) {
1920
1920
return getPrimaryIGM ();
1921
1921
}
1922
- SourceFile *SF = ctxt->getParentSourceFile ();
1922
+ SourceFile *SF = ctxt->getOutermostParentSourceFile ();
1923
1923
if (!SF) {
1924
1924
return getPrimaryIGM ();
1925
1925
}
1926
+
1926
1927
IRGenModule *IGM = GenModules[SF];
1927
1928
assert (IGM);
1928
1929
return IGM;
Original file line number Diff line number Diff line change @@ -9502,9 +9502,8 @@ ParserResult<MacroDecl> Parser::parseDeclMacro(DeclAttributes &attributes) {
9502
9502
} else {
9503
9503
// Parameter list.
9504
9504
SmallVector<Identifier, 2 > namePieces;
9505
- DefaultArgumentInfo defaultArgs;
9506
9505
auto parameterResult = parseSingleParameterClause (
9507
- ParameterContextKind::Macro, &namePieces, &defaultArgs );
9506
+ ParameterContextKind::Macro, &namePieces, nullptr );
9508
9507
status |= parameterResult;
9509
9508
parameterList = parameterResult.getPtrOrNull ();
9510
9509
Original file line number Diff line number Diff line change @@ -134,3 +134,8 @@ func testExternalMacroOutOfPlace() {
134
134
let _: Int = #externalMacro( module: " A " , type: " B " )
135
135
// expected-error@-1{{macro 'externalMacro' can only be used to define another macro}}
136
136
}
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'}}
You can’t perform that action at this time.
0 commit comments