Skip to content

Commit 8c95430

Browse files
committed
Add keypath method/initializer handling for predicate macro.
1 parent 3b31f75 commit 8c95430

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Sources/FoundationMacros/PredicateMacro.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import SwiftSyntax
1414
import SwiftSyntaxMacros
1515
internal import SwiftDiagnostics
1616
internal import SwiftSyntaxBuilder
17+
@_spi(ExperimentalLanguageFeatures) import SwiftSyntax
1718

1819
// A list of all functions supported by Predicate/Expression itself, any other functions called will be diagnosed as an error
1920
// This allows for checking the function name, the number of arguments, and the argument labels, but the types of the arguments will need to be validated by the post-expansion type checking pass
@@ -393,6 +394,12 @@ extension KeyPathExprSyntax {
393394
}
394395
case .subscript(let sub):
395396
result = ExprSyntax(SubscriptCallExprSyntax(calledExpression: result, arguments: sub.arguments))
397+
#if !FOUNDATION_FRAMEWORK
398+
case .method(let method):
399+
let methodName = method.declName
400+
let methodAccess = MemberAccessExprSyntax(base: result, declName: methodName)
401+
result = ExprSyntax(FunctionCallExprSyntax(calledExpression: methodAccess, arguments: method.arguments))
402+
#endif
396403
#if FOUNDATION_FRAMEWORK
397404
default:
398405
return nil

0 commit comments

Comments
 (0)