diff --git a/lib/ASTGen/Sources/ASTGen/DeclAttrs.swift b/lib/ASTGen/Sources/ASTGen/DeclAttrs.swift index 2197c1fcbfd..31a0f503adc 100644 --- a/lib/ASTGen/Sources/ASTGen/DeclAttrs.swift +++ b/lib/ASTGen/Sources/ASTGen/DeclAttrs.swift @@ -1246,12 +1246,19 @@ extension ASTGenVisitor { // E.g. 'named(foo())', use the callee to generate the name. arg = call.calledExpression } - guard let arg = arg.as(DeclReferenceExprSyntax.self) else { - // TODO: Diagnose. - return nil + + if let arg = arg.as(DeclReferenceExprSyntax.self) { + name = self.generateDeclNameRef(declReferenceExpr: arg).name + } else if arg.is(DiscardAssignmentExprSyntax.self) { + name = BridgedDeclNameRef.createParsed(.createIdentifier(self.ctx.getIdentifier("_"))) + } else { + // TODO: Diagnose + fatalError("expected name") + //return nil } - name = self.generateDeclNameRef(declReferenceExpr: arg).name + if arguments.count >= 2 { + fatalError("unexpected arguments") // TODO: Diagnose. } diff --git a/test/ASTGen/macros.swift b/test/ASTGen/macros.swift index 38a1494c7be..dd013c87594 100644 --- a/test/ASTGen/macros.swift +++ b/test/ASTGen/macros.swift @@ -115,3 +115,34 @@ func f(a: Int, b: String) async throws -> String struct TestArbitrary { #bitwidthNumberedStructs("MyIntOne") } + +// Stored properties generated by a peer macro +@attached(accessor) +@attached(peer, names: prefixed(_)) +macro myPropertyWrapper() = + #externalMacro(module: "MacroDefinition", type: "PropertyWrapperMacro") + +struct MyWrapperThingy { + var storage: T + + var wrappedValue: T { + get { + print("Getting value \(storage)") + return storage + } + + set { + print("Setting value \(newValue)") + storage = newValue + } + } +} + +struct S3 { + @myPropertyWrapper + var x: Int = 0 + + init(x: Int) { + self._x = MyWrapperThingy(storage: x) + } +}