mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[ASTGen] Handle 'prefixed(_)' in macro introduced names
'_' is not a 'DeclReferenceExprSyntax', but a 'DiscardAssignmentExprSyntax'.
This commit is contained in:
@@ -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.
|
||||
}
|
||||
|
||||
|
||||
@@ -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<T> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user