-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.circular referenceBug → internal error: Circular referenceBug → internal error: Circular referencecompilerThe Swift compiler itselfThe Swift compiler itselfinternal errorBug: Internal errorBug: Internal errornested typesFeature: nested typesFeature: nested typesswift 5.9swift macroFeature → declarations: Swift `macro` declarationsFeature → declarations: Swift `macro` declarationstype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysisunexpected errorBug: Unexpected errorBug: Unexpected error
Description
Description
When defining a new type within a structure, the macro throws an error 'Circular reference resolving attached macro 'xxx'
@entity // ERROR: Circular reference resolving attached macro 'entity'
struct NewDBTest { // ERROR: Circular reference
let a: String
}
extension NewDBTest {
struct Test { }
}
extension NewDBTest.Test { // ERROR: 'Test' is not a member type of struct 'IcarusClient.NewDBTest'
}
@entity is a member macro of a generating constructor
public struct EntityMacro: MemberMacro {
public static func expansion(
of node: AttributeSyntax,
providingMembersOf declaration: some DeclGroupSyntax,
in context: some MacroExpansionContext
) throws -> [DeclSyntax] {
guard let declaration = declaration.as(StructDeclSyntax.self)
else { throw IcarusTrackerError.invalidInputType }
let arguments = declaration.storedProperties()
.filter { !$0.isStatic && !$0.isConstant }
.compactMap { property -> (name: String, type: TypeSyntax)? in
guard let name = property.name, let type = property.type
else { return nil }
return (name, type)
}
let initDecl = try InitializerDeclSyntax("public init(\(raw: arguments.map { "\($0.name): \($0.type)" }.joined(separator: ", ")))") {
for argument in arguments {
ExprSyntax(stringLiteral: "self.\(argument.name) = \(argument.name)")
}
}
return [
DeclSyntax(initDecl)
]
}
}
Steps to Reproduce
No response
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.circular referenceBug → internal error: Circular referenceBug → internal error: Circular referencecompilerThe Swift compiler itselfThe Swift compiler itselfinternal errorBug: Internal errorBug: Internal errornested typesFeature: nested typesFeature: nested typesswift 5.9swift macroFeature → declarations: Swift `macro` declarationsFeature → declarations: Swift `macro` declarationstype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysisunexpected errorBug: Unexpected errorBug: Unexpected error