Skip to content

Commit c285987

Browse files
authored
Merge pull request #66327 from DougGregor/local-types-in-macro-expansions
2 parents ed78fe0 + e964d12 commit c285987

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5162,7 +5162,7 @@ void Parser::recordLocalType(TypeDecl *TD) {
51625162
return;
51635163

51645164
if (!InInactiveClauseEnvironment)
5165-
SF.LocalTypeDecls.insert(TD);
5165+
SF.getOutermostParentSourceFile()->LocalTypeDecls.insert(TD);
51665166
}
51675167

51685168
/// Set the original declaration in `@differentiable` attributes.

test/Macros/macro_expand.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,17 @@ func testStringifyWithThrows() throws {
235235

236236
// CHECK-DIAGS: @__swiftmacro_9MacroUser23testStringifyWithThrowsyyKF9stringifyfMf1_.swift:1:2: error: call can throw but is not marked with 'try'
237237
#endif
238-
238+
239239
// The macro adds the 'try' for us.
240240
_ = #stringifyAndTry(maybeThrowing())
241241
}
242242

243+
func testStringifyWithLocalType() throws {
244+
_ = #stringify({
245+
struct QuailError: Error {}
246+
throw QuailError()
247+
})
248+
}
243249
244250
@freestanding(expression) macro addBlocker<T>(_ value: T) -> T = #externalMacro(module: "MacroDefinition", type: "AddBlocker")
245251

@@ -496,7 +502,7 @@ func testHasEqualsSelf(
496502
_ = (y == true) // expected-error{{referencing operator function '=='}}
497503
_ = (z == true) // expected-error{{referencing operator function '=='}}
498504
_ = (w == true) // expected-error{{referencing operator function '=='}}
499-
#endif
505+
#endif
500506

501507
// These should be found through the protocol.
502508
_ = (xP == true)

0 commit comments

Comments
 (0)