Attached macro support for enum case arguments

Currently macros are not supported to be attached to enum case arguments. While there are no macro-roles that specify usage in such a way but using existing macro roles gives error:

Unknown attribute 'Macro'

for enum arguments without argument name,

enum SomeEnum {
    case string(@Macro String)
}

and for enum arguments with argument name:

enum SomeEnum {
    case int(@Macro val: Int)
}

Expected parameter name followed by ':'

On the other-hand, adding macro attributes to function arguments gives different error:

func someFunc(@Macro val: Int) {
    
}

'(macroRole)' macro cannot be attached to parameter

While I can't think of any expansion that can be performed by macros of such type, but these kind of macros can be used to provide some metadata to another macro that performs expansion.

This would be helpful in my library MetaCodable for generating Codable implementation for enums and customizing the generated implementations per case arguments as already done for struct properties.

2 Likes