Skip to content

Commit 0af22a4

Browse files
authored
Merge pull request #28329 from marcrasi/tf-971
2 parents badcc2c + 8bb7c46 commit 0af22a4

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2351,9 +2351,10 @@ static bool parseDifferentiableAttributeArgument(Parser &P,
23512351
return false;
23522352
}
23532353

2354-
// If the next token is an arrow, then the matched '( <identifier> )' is
2355-
// actually the parameter type list, not an argument to '@differentiable'.
2356-
if (P.Tok.is(tok::arrow))
2354+
// If the next token is not a `(`, `@`, or an identifier, then the
2355+
// matched '( <identifier> )' is actually the parameter type list,
2356+
// not an argument to '@differentiable'.
2357+
if (P.Tok.isNot(tok::l_paren, tok::at_sign, tok::identifier))
23572358
return false;
23582359

23592360
backtrack.cancelBacktrack();

test/AutoDiff/Parse/differentiable_func_type.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ let b: @differentiable(linear) (Float) -> Float // okay
88
// CHECK: (pattern_named 'b'
99
// CHECK-NEXT: (type_attributed attrs=@differentiable(linear)
1010

11+
let c: @differentiable (Float) throws -> Float // okay
12+
// CHECK: (pattern_named 'c'
13+
// CHECK-NEXT: (type_attributed attrs=@differentiable{{[^(]}}
14+
15+
let d: @differentiable(linear) (Float) throws -> Float // okay
16+
// CHECK: (pattern_named 'd'
17+
// CHECK-NEXT: (type_attributed attrs=@differentiable(linear)
18+
1119
// Generic type test.
1220
struct A<T> {
1321
func foo() {

0 commit comments

Comments
 (0)