Skip to content

Commit 406549d

Browse files
committed
[Parser] Add local type declarations to the outermost enclosing source file
The parser is currently responsible for adding local type declarations to a `SourceFile`, which IR generation later queries. However, IRGen never sees the source files associated with macro expansion buffers, so local types introduced there don't get recorded. In time, this approach of using the parser to record semantic information should be replaced with something more "pull" oriented. For now, however, record local type declarations in the outermost enclosing source file... so we see the ones produced by macro expansions, too. Fixes rdar://109370309. (cherry picked from commit e964d12)
1 parent c2a1dce commit 406549d

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
@@ -5100,7 +5100,7 @@ void Parser::recordLocalType(TypeDecl *TD) {
51005100
return;
51015101

51025102
if (!InInactiveClauseEnvironment)
5103-
SF.LocalTypeDecls.insert(TD);
5103+
SF.getOutermostParentSourceFile()->LocalTypeDecls.insert(TD);
51045104
}
51055105

51065106
/// 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
@@ -234,11 +234,17 @@ func testStringifyWithThrows() throws {
234234

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

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

@@ -495,7 +501,7 @@ func testHasEqualsSelf(
495501
_ = (y == true) // expected-error{{referencing operator function '=='}}
496502
_ = (z == true) // expected-error{{referencing operator function '=='}}
497503
_ = (w == true) // expected-error{{referencing operator function '=='}}
498-
#endif
504+
#endif
499505

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

0 commit comments

Comments
 (0)