Skip to content

Commit 29465f8

Browse files
authored
Add standalone test.
1 parent d69e892 commit 29465f8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

test/AutoDiff/Sema/derivative_attr_type_checking.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,23 @@ extension HasStoredProperty {
546546
}
547547
}
548548

549+
// Test derivative registration for protocol requirements. Currently unsupported.
550+
// TODO(TF-982): Lift this restriction and add proper support.
551+
552+
protocol ProtocolRequirementDerivative {
553+
func requirement(_ x: Float) -> Float
554+
}
555+
extension ProtocolRequirementDerivative {
556+
// NOTE: the error is misleading because `findAbstractFunctionDecl` in
557+
// TypeCheckAttr.cpp is not setup to show customized error messages for
558+
// invalid original function candidates.
559+
// expected-error @+1 {{could not find function 'requirement' with expected type '<Self where Self : ProtocolRequirementDerivative> (Self) -> (Float) -> Float'}}
560+
@derivative(of: requirement)
561+
func vjpRequirement(_ x: Float) -> (value: Float, pullback: (Float) -> Float) {
562+
fatalError()
563+
}
564+
}
565+
549566
// Test cross-file derivative registration. Currently unsupported.
550567
// TODO(TF-1021): Lift this restriction.
551568

0 commit comments

Comments
 (0)