Files
swift-mirror/test/Constraints/noderivative.swift
Andrew Savonichev b1f36d2c6d [AutoDiff] Fix test/Constraints/noderivative.swift (#67190)
The test imports _Differentiation, so it needs the REQUIRES line or people that build without that feature will fail this test.
2023-07-10 09:50:06 -07:00

27 lines
1016 B
Swift

// RUN: %target-typecheck-verify-swift
// REQUIRES: differentiable_programming
import _Differentiation
// Allow Type -> @noDerivative Type
//
func test1(_ foo: @escaping @differentiable(reverse) (Float, Float) -> Float) {
let fn: @differentiable(reverse) (Float, @noDerivative Float) -> Float = foo
_ = fn(0, 0)
}
// Allow @noDerivative Type -> Type when LHS function is not differentiable
//
func test2(_ foo: @escaping @differentiable(reverse) (Float, @noDerivative Float) -> Float) {
let fn: (Float, Float) -> Float = foo
_ = fn(0, 0)
}
// Disallow @noDerivative Type -> Type when LHS function is also differentiable
//
func test3(_ foo: @escaping @differentiable(reverse) (Float, @noDerivative Float) -> Float) {
// expected-error @+1 {{cannot convert value of type '@differentiable(reverse) (Float, @noDerivative Float) -> Float' to specified type '@differentiable(reverse) (Float, Float) -> Float'}}
let fn: @differentiable(reverse) (Float, Float) -> Float = foo
_ = fn(0, 0)
}