From 16aa78d41867b2d545109f9129bca4f895c0ef7b Mon Sep 17 00:00:00 2001 From: Devdatta Talele Date: Mon, 6 Jul 2026 19:07:50 +0530 Subject: [PATCH] [Tests] Cover @derivative module selector in ModuleSelectorTests Add a substructure assertion inside testModuleSelectorCorrectCode for @derivative(of: Module::name). The argument list flows through parseQualifiedDeclarationName -> parseDeclReferenceExpr and therefore already accepts module selectors; the new test locks that behavior in for the simple decl-reference form. The existing @derivative test in testModuleSelectorAttrs covers the complex qualified form (@derivative with member access + wrt clause). This new test covers the simpler decl-reference form in testModuleSelectorCorrectCode alongside the neighbouring @_implements and @_dynamicReplacement module-selector coverage. Drop the pre-existing FIXME. The @_differentiable(jvp:vjp:) legacy argument form referenced by that FIXME has been removed from the language, and the underscore-prefixed @_derivative spelling is no longer parsed as a derivative-registration attribute (only the modern @derivative spelling is recognised - see DeclarationAttributeWithSpecialSyntax in Sources/SwiftParser/Attributes.swift). --- .../translated/ModuleSelectorTests.swift | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/Tests/SwiftParserTest/translated/ModuleSelectorTests.swift b/Tests/SwiftParserTest/translated/ModuleSelectorTests.swift index 1f2114b0ca8..2dddc8c892d 100644 --- a/Tests/SwiftParserTest/translated/ModuleSelectorTests.swift +++ b/Tests/SwiftParserTest/translated/ModuleSelectorTests.swift @@ -179,8 +179,36 @@ final class ModuleSelectorTests: ParserTestCase { ) ) - // FIXME: Add tests with autodiff @_differentiable(jvp:vjp:) and - // @_derivative(of:) + assertParse( + """ + @derivative(of: ModuleSelectorTestingKit::negate) + func negateDerivative() {} + """, + substructure: FunctionDeclSyntax( + attributes: [ + .attribute( + AttributeSyntax( + attributeName: makeType(name: "derivative"), + leftParen: .leftParenToken(), + arguments: .derivativeRegistrationArguments( + DerivativeAttributeArgumentsSyntax( + originalDeclName: makeDeclRef( + moduleSelector: "ModuleSelectorTestingKit", + baseName: "negate" + ) + ) + ), + rightParen: .rightParenToken() + ) + ) + ], + name: .identifier("negateDerivative"), + signature: FunctionSignatureSyntax( + parameterClause: FunctionParameterClauseSyntax {} + ), + body: CodeBlockSyntax {} + ) + ) assertParse( """