Skip to content

Commit 8bb7c46

Browse files
author
Marc Rasi
committed
[AutoDiff upstream] fix TF-971
1 parent 2488f48 commit 8bb7c46

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
@@ -2233,9 +2233,10 @@ static bool parseDifferentiableAttributeArgument(Parser &P,
22332233
return false;
22342234
}
22352235

2236-
// If the next token is an arrow, then the matched '( <identifier> )' is
2237-
// actually the parameter type list, not an argument to '@differentiable'.
2238-
if (P.Tok.is(tok::arrow))
2236+
// If the next token is not a `(`, `@`, or an identifier, then the
2237+
// matched '( <identifier> )' is actually the parameter type list,
2238+
// not an argument to '@differentiable'.
2239+
if (P.Tok.isNot(tok::l_paren, tok::at_sign, tok::identifier))
22392240
return false;
22402241

22412242
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)