Skip to content

Commit cfe7c0c

Browse files
committed
Rename .method parameter "name" to "signature"
To disambiguate overloaded methods in _SwiftifyImportProtocol we now pass the entire function signature instead of just the function name. This should be reflected in the parameter name.
1 parent 9e89957 commit cfe7c0c

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

lib/Macros/Sources/SwiftMacros/SwiftifyImportMacro.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,7 @@ func parseProtocolMacroParam(
16251625
node: enumConstructorExpr)
16261626
}
16271627
let argumentList = enumConstructorExpr.arguments
1628-
let methodSignatureArg = try getArgumentBySignature(argumentList, "signature")
1628+
let methodSignatureArg = try getArgumentByName(argumentList, "signature")
16291629
guard let methodSignatureStringLit = methodSignatureArg.as(StringLiteralExprSyntax.self) else {
16301630
throw DiagnosticError(
16311631
"expected string literal for 'signature' parameter, got \(methodSignatureArg)", node: methodSignatureArg)
@@ -1641,7 +1641,7 @@ func parseProtocolMacroParam(
16411641
notes.append(Note(node: Syntax(method.name), message: MacroExpansionNoteMessage("did you mean '\(method.trimmed.description)'?")))
16421642
}
16431643
throw DiagnosticError(
1644-
"method with signature '\(methodSignature)' not found in protocol", node: methodNameArg, notes: notes)
1644+
"method with signature '\(methodSignature)' not found in protocol", node: methodSignatureArg, notes: notes)
16451645
}
16461646
let paramInfoArg = try getArgumentByName(argumentList, "paramInfo")
16471647
guard let paramInfoArgList = paramInfoArg.as(ArrayExprSyntax.self) else {

test/Macros/SwiftifyImport/CountedBy/Protocol.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// RUN: %target-swift-frontend %s -swift-version 5 -module-name main -disable-availability-checking -typecheck -plugin-path %swift-plugin-dir -dump-macro-expansions -enable-experimental-feature Span -enable-experimental-feature LifetimeDependence 2>&1 | %FileCheck --match-full-lines %s
44

5-
@_SwiftifyImportProtocol(.method(name: "func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt)", paramInfo: [.countedBy(pointer: .param(1), count: "len")]))
5+
@_SwiftifyImportProtocol(.method(signature: "func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt)", paramInfo: [.countedBy(pointer: .param(1), count: "len")]))
66
protocol SimpleProtocol {
77
func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt)
88
}
@@ -14,8 +14,8 @@ protocol SimpleProtocol {
1414
// CHECK-NEXT: }
1515
// CHECK-NEXT: }
1616

17-
@_SwiftifyImportProtocol(.method(name: "func foo(_ ptr: UnsafePointer<CInt>, _ len: CInt)", paramInfo: [.countedBy(pointer: .param(1), count: "len"), .nonescaping(pointer: .param(1))]),
18-
.method(name: "func bar(_ len: CInt) -> UnsafePointer<CInt>", paramInfo: [.countedBy(pointer: .return, count: "len"), .nonescaping(pointer: .return), .lifetimeDependence(dependsOn: .self, pointer: .return, type: .borrow)]))
17+
@_SwiftifyImportProtocol(.method(signature: "func foo(_ ptr: UnsafePointer<CInt>, _ len: CInt)", paramInfo: [.countedBy(pointer: .param(1), count: "len"), .nonescaping(pointer: .param(1))]),
18+
.method(signature: "func bar(_ len: CInt) -> UnsafePointer<CInt>", paramInfo: [.countedBy(pointer: .return, count: "len"), .nonescaping(pointer: .return), .lifetimeDependence(dependsOn: .self, pointer: .return, type: .borrow)]))
1919
protocol SpanProtocol {
2020
func foo(_ ptr: UnsafePointer<CInt>, _ len: CInt)
2121
func bar(_ len: CInt) -> UnsafePointer<CInt>
@@ -35,8 +35,8 @@ protocol SpanProtocol {
3535
// CHECK-NEXT: }
3636
// CHECK-NEXT: }
3737

38-
@_SwiftifyImportProtocol(.method(name: "func foo(_ ptr: UnsafePointer<CInt>, _ len: CInt)", paramInfo: [.countedBy(pointer: .param(1), count: "len"), .nonescaping(pointer: .param(1))]),
39-
.method(name: "func bar(_ ptr: UnsafePointer<CInt>, _ len: CInt)", paramInfo: [.countedBy(pointer: .param(1), count: "len")]))
38+
@_SwiftifyImportProtocol(.method(signature: "func foo(_ ptr: UnsafePointer<CInt>, _ len: CInt)", paramInfo: [.countedBy(pointer: .param(1), count: "len"), .nonescaping(pointer: .param(1))]),
39+
.method(signature: "func bar(_ ptr: UnsafePointer<CInt>, _ len: CInt)", paramInfo: [.countedBy(pointer: .param(1), count: "len")]))
4040
protocol MixedProtocol {
4141
func foo(_ ptr: UnsafePointer<CInt>, _ len: CInt)
4242
func bar(_ ptr: UnsafePointer<CInt>, _ len: CInt)
@@ -55,8 +55,8 @@ protocol MixedProtocol {
5555
// CHECK-NEXT: }
5656
// CHECK-NEXT: }
5757

58-
@_SwiftifyImportProtocol(.method(name: "func foo(_ ptr: UnsafePointer<CInt>, _ len1: CInt)", paramInfo: [.countedBy(pointer: .param(1), count: "len1")]),
59-
.method(name: "func foo(bar: UnsafePointer<CInt>, _ len2: CInt)", paramInfo: [.countedBy(pointer: .param(1), count: "len2")]))
58+
@_SwiftifyImportProtocol(.method(signature: "func foo(_ ptr: UnsafePointer<CInt>, _ len1: CInt)", paramInfo: [.countedBy(pointer: .param(1), count: "len1")]),
59+
.method(signature: "func foo(bar: UnsafePointer<CInt>, _ len2: CInt)", paramInfo: [.countedBy(pointer: .param(1), count: "len2")]))
6060
protocol OverloadedProtocol {
6161
func foo(_ ptr: UnsafePointer<CInt>, _ len1: CInt)
6262
func foo(bar: UnsafePointer<CInt>, _ len2: CInt)
@@ -74,7 +74,7 @@ protocol OverloadedProtocol {
7474
// CHECK-NEXT: }
7575
// CHECK-NEXT: }
7676

77-
@_SwiftifyImportProtocol(.method(name: "open func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt)", paramInfo: [.countedBy(pointer: .param(1), count: "len")]))
77+
@_SwiftifyImportProtocol(.method(signature: "open func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt)", paramInfo: [.countedBy(pointer: .param(1), count: "len")]))
7878
class SimpleClass {
7979
open func myFunc(_ ptr: UnsafePointer<CInt>, _ len: CInt) {}
8080
}

0 commit comments

Comments
 (0)