-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Macros] Only freestanding expression macros can have a non-Void result type #66504
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ internal struct X { } // expected-note{{type declared here}} | |
// expected-warning@-1{{external macro implementation type}} | ||
|
||
struct ZZZ { | ||
macro m5() -> Int = #externalMacro(module: "BuiltinMacros", type: "Blah") | ||
macro m5() = #externalMacro(module: "BuiltinMacros", type: "Blah") | ||
// expected-error@-1{{macro 'm5()' can only be declared at file scope}} | ||
// expected-error@-2{{macro 'm5()' must declare its applicable roles}} | ||
// expected-warning@-3{{external macro implementation type}} | ||
|
@@ -200,3 +200,14 @@ struct SomeType { | |
// expected-error@-2{{use of protocol 'Hashable' as a type must be written 'any Hashable'}} | ||
// expected-error@-3{{external macro implementation type}} | ||
} | ||
|
||
|
||
|
||
@freestanding(declaration) macro nonExpressionReturnsInt<T>(_: T) -> Int = #externalMacro(module: "A", type: "B") | ||
// expected-warning@-1{{external macro implementation type}} | ||
// expected-error@-2{{only a freestanding expression macro can produce a result of type 'Int'}} | ||
// expected-note@-3{{make this macro a freestanding expression macro}}{{1-1=@freestanding(expression)\n}} | ||
// expected-note@-4{{remove the result type if the macro does not produce a value}}{{67-74=}} | ||
|
||
@freestanding(declaration) macro nonExpressionReturnsVoid<T>(_: T) -> Void = #externalMacro(module: "A", type: "B") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don’t think we should be allowing the declaration of any return type for non-freestanding-expression macros. Specifying There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I agree with that. #66526 |
||
// expected-warning@-1{{external macro implementation type}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a macro had multiple roles (including
freestanding(expression)
), should we reject non-void types in that case too?Because in this case the return type
-> Int
still doesn't make sense for the accessor role.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I don't think we should. The result type only applies to the
expression
role, and it's fine for it to be ignored for any attached roles.Note that we don't currently diagnose when a macro has multiple freestanding roles. I'm handling that (and related cleanup) via a separate pull request