Skip to content

Commit e964d12

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.
1 parent b7b6a1d commit e964d12

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
@@ -5163,7 +5163,7 @@ void Parser::recordLocalType(TypeDecl *TD) {
51635163
return;
51645164

51655165
if (!InInactiveClauseEnvironment)
5166-
SF.LocalTypeDecls.insert(TD);
5166+
SF.getOutermostParentSourceFile()->LocalTypeDecls.insert(TD);
51675167
}
51685168

51695169
/// 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)