Skip to content
Permalink
Browse files

Allow function types inside tuples inside arrow return types

Summary:
To avoid ambiguity, Flow disallows using a function type in the return type, like

  const f = (): boolean => string => { return (b: boolean): string => "hello"; }

unless you wrap it in parens

  const f = (): (boolean => string) => { return (b: boolean): string => "hello"; }

We forgot to allow it inside tuples too, like

  const f = (): [boolean => string] => { return [(b: boolean): string => "hello"]; }

Reviewed By: dsainati1

Differential Revision: D15150181

fbshipit-source-id: dbc9292ac0935ea79373437501b22373e538979a
  • Loading branch information...
gabelevi authored and facebook-github-bot committed Apr 30, 2019
1 parent 52bbf66 commit 65e6d1df078e778d0244d4ee49bd28c741b5af0f
@@ -0,0 +1 @@
(): [number => void] => {}
@@ -0,0 +1,70 @@
{
"type":"Program",
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":26}},
"range":[0,26],
"body":[
{
"type":"ExpressionStatement",
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":26}},
"range":[0,26],
"expression":{
"type":"ArrowFunctionExpression",
"loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":26}},
"range":[0,26],
"id":null,
"params":[],
"body":{
"type":"BlockStatement",
"loc":{"source":null,"start":{"line":1,"column":24},"end":{"line":1,"column":26}},
"range":[24,26],
"body":[]
},
"async":false,
"generator":false,
"predicate":null,
"expression":false,
"returnType":{
"type":"TypeAnnotation",
"loc":{"source":null,"start":{"line":1,"column":2},"end":{"line":1,"column":20}},
"range":[2,20],
"typeAnnotation":{
"type":"TupleTypeAnnotation",
"loc":{"source":null,"start":{"line":1,"column":4},"end":{"line":1,"column":20}},
"range":[4,20],
"types":[
{
"type":"FunctionTypeAnnotation",
"loc":{"source":null,"start":{"line":1,"column":5},"end":{"line":1,"column":19}},
"range":[5,19],
"params":[
{
"type":"FunctionTypeParam",
"loc":{"source":null,"start":{"line":1,"column":5},"end":{"line":1,"column":11}},
"range":[5,11],
"name":null,
"typeAnnotation":{
"type":"NumberTypeAnnotation",
"loc":{"source":null,"start":{"line":1,"column":5},"end":{"line":1,"column":11}},
"range":[5,11]
},
"optional":false
}
],
"returnType":{
"type":"VoidTypeAnnotation",
"loc":{"source":null,"start":{"line":1,"column":15},"end":{"line":1,"column":19}},
"range":[15,19]
},
"rest":null,
"typeParameters":null
}
]
}
},
"typeParameters":null
},
"directive":null
}
],
"comments":[]
}
@@ -229,7 +229,7 @@ module Type (Parse: Parser_common.PARSER) : TYPE = struct
in fun env ->
with_loc (fun env ->
Expect.token env T_LBRACKET;
let tl = types env [] in
let tl = types (with_no_anon_function_type false env) [] in
Expect.token env T_RBRACKET;
Type.Tuple tl
) env

1 comment on commit 65e6d1d

@TrySound

This comment has been minimized.

Copy link
Collaborator

commented on 65e6d1d Apr 30, 2019

🎉

Please sign in to comment.
You can’t perform that action at this time.