Skip to content

[Parser] Add local type declarations to the outermost enclosing source file #66327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5163,7 +5163,7 @@ void Parser::recordLocalType(TypeDecl *TD) {
return;

if (!InInactiveClauseEnvironment)
SF.LocalTypeDecls.insert(TD);
SF.getOutermostParentSourceFile()->LocalTypeDecls.insert(TD);
}

/// Set the original declaration in `@differentiable` attributes.
Expand Down
10 changes: 8 additions & 2 deletions test/Macros/macro_expand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,17 @@ func testStringifyWithThrows() throws {

// CHECK-DIAGS: @__swiftmacro_9MacroUser23testStringifyWithThrowsyyKF9stringifyfMf1_.swift:1:2: error: call can throw but is not marked with 'try'
#endif

// The macro adds the 'try' for us.
_ = #stringifyAndTry(maybeThrowing())
}

func testStringifyWithLocalType() throws {
_ = #stringify({
struct QuailError: Error {}
throw QuailError()
})
}

@freestanding(expression) macro addBlocker<T>(_ value: T) -> T = #externalMacro(module: "MacroDefinition", type: "AddBlocker")

Expand Down Expand Up @@ -496,7 +502,7 @@ func testHasEqualsSelf(
_ = (y == true) // expected-error{{referencing operator function '=='}}
_ = (z == true) // expected-error{{referencing operator function '=='}}
_ = (w == true) // expected-error{{referencing operator function '=='}}
#endif
#endif

// These should be found through the protocol.
_ = (xP == true)
Expand Down