Skip to content

Commit 1cefebe

Browse files
authored
[AutoDiff] Fix @differentiable-related override matching crash. (swiftlang#29985)
Remove meaningless `assert(false)` assertion from `hasOverridingDifferentiableAttribute` in `TypeCheckDeclOverride.cpp`. The assertion served no purpose and can safely be removed. Resolves TF-1167. Add test.
1 parent e8a7b1b commit 1cefebe

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,9 +689,6 @@ static bool hasOverridingDifferentiableAttribute(ValueDecl *derivedDecl,
689689
overrides = false;
690690
break;
691691
}
692-
if (!derivedParameters && !baseParameters) {
693-
assert(false);
694-
}
695692
}
696693
if (overrides)
697694
return true;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %target-swift-frontend -enable-experimental-differentiable-programming -typecheck -verify %s
2+
// REQUIRES: asserts
3+
4+
// TF-1167: `OverrideMatcher::match` crash due to meaningless assertion:
5+
// `assert(false)`. The assertion was triggered when parameter indices
6+
// could not be resolved for neither base nor derived declaration
7+
// `@differentiable` attributes.
8+
//
9+
// `import _Differentiation` is intentionally omitted from this test case.
10+
11+
public protocol Base {
12+
associatedtype Input
13+
// expected-error @+1 {{use of undeclared type 'Differentiable'}}
14+
associatedtype Output: Differentiable
15+
16+
// expected-error @+1 {{@differentiable attribute used without importing module '_Differentiation'}}
17+
@differentiable(wrt: self)
18+
func callAsFunction(_ input: Input) -> Output
19+
}
20+
public protocol Derived: Base {
21+
// expected-error @+1 {{@differentiable attribute used without importing module '_Differentiation'}}
22+
@differentiable
23+
func callAsFunction(_ input: Input) -> Output
24+
}

0 commit comments

Comments
 (0)