Skip to content

Commit

Permalink
Revert "Allow declaration files to declare generator functions"
Browse files Browse the repository at this point in the history
This reverts commit cce04ec.
  • Loading branch information
samwgoldman committed Jun 20, 2015
1 parent 04ccba4 commit 8ecbaab
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 46 deletions.
9 changes: 0 additions & 9 deletions src/parser/parser_flow.ml
Original file line number Diff line number Diff line change
Expand Up @@ -481,12 +481,10 @@ end = struct
match param_list_or_type env with
| ParamList (rest, params) ->
Expect.token env T_ARROW;
let generator = false in
let returnType = _type env in
let end_loc = fst returnType in
Loc.btwn start_loc end_loc, Type.(Function Function.({
params;
generator;
returnType;
rest;
typeParameters = None;
Expand All @@ -498,12 +496,10 @@ end = struct
let typeParameters = type_parameter_declaration env in
let rest, params = function_param_list env in
Expect.token env T_ARROW;
let generator = false in
let returnType = _type env in
let end_loc = fst returnType in
Loc.btwn start_loc end_loc, Type.(Function Function.({
params;
generator;
returnType;
rest;
typeParameters;
Expand All @@ -514,12 +510,10 @@ end = struct
let typeParameters = type_parameter_declaration env in
let rest, params = function_param_list env in
Expect.token env T_COLON;
let generator = false in
let returnType = _type env in
let loc = Loc.btwn start_loc (fst returnType) in
loc, Type.Function.({
params;
generator;
returnType;
rest;
typeParameters;
Expand Down Expand Up @@ -2859,9 +2853,7 @@ end = struct
})) in

let declare_function env start_loc =
let async = Declaration.async env in
Expect.token env T_FUNCTION;
let generator = Declaration.generator env async in
let id = Parse.identifier env in
let start_sig_loc = Peek.loc env in
let typeParameters = Type.type_parameter_declaration env in
Expand All @@ -2872,7 +2864,6 @@ end = struct
let loc = Loc.btwn start_sig_loc end_loc in
let value = loc, Ast.Type.(Function {Function.
params;
generator;
returnType;
rest;
typeParameters;
Expand Down
1 change: 0 additions & 1 deletion src/parser/spider_monkey_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ and Type : sig

type t = {
params: Param.t list;
generator: bool;
returnType: Type.t;
rest: Param.t option;
typeParameters: Type.ParameterDeclaration.t option;
Expand Down
5 changes: 2 additions & 3 deletions src/typing/type_inference_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ let rec convert cx map = Ast.Type.(function
mk_nominal_type_ cx reason map (c, params)
)

| loc, Function { Function.params; generator; returnType; rest; typeParameters } ->
| loc, Function { Function.params; returnType; rest; typeParameters } ->
let typeparams, map_ = mk_type_param_declarations cx ~map typeParameters in
let map = SMap.fold SMap.add map_ map in

Expand All @@ -796,7 +796,6 @@ let rec convert cx map = Ast.Type.(function
((snd name).Ast.Identifier.name) :: rev_pnames
| None -> rev_tlist, rev_pnames
) in
let ret = convert cx map returnType in
let ft =
FunT (
mk_reason "function type" loc,
Expand All @@ -806,7 +805,7 @@ let rec convert cx map = Ast.Type.(function
this_t = Flow_js.mk_tvar cx (mk_reason "this" loc);
params_tlist = (List.rev rev_params_tlist);
params_names = Some (List.rev rev_params_names);
return_t = ret;
return_t = convert cx map returnType;
closure_t = 0
})
in
Expand Down
32 changes: 8 additions & 24 deletions tests/generators/generators.exp
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,18 @@ generators.js:21:10,11: string
This type is incompatible with
generators.js:28:22,28: boolean

generators.js:31:37,42: number
This type is incompatible with
generators.js:32:30,35: string

generators.js:33:17,30: call of method next
Error:
generators.js:33:29,29: number
This type is incompatible with
generators.js:31:53,59: boolean

generators.js:33:17,36: property value
Error:
generators.js:31:45,50: string
This type is incompatible with
generators.js:37:16,22: boolean

generators.js:69:3,16: yield* delegate
generators.js:60:3,16: yield* delegate
Error:
generators.js:71:32,33: string
generators.js:62:32,33: string
This type is incompatible with
generators.js:67:12,17: number
generators.js:58:12,17: number

generators.js:75:11,12: string
generators.js:66:11,12: string
This type is incompatible with
generators.js:81:8,13: number
generators.js:72:8,13: number

generators.js:98:45,50: number
generators.js:89:45,50: number
This type is incompatible with
generators.js:102:8,13: string
generators.js:93:8,13: string

Found 12 errors
Found 9 errors
9 changes: 0 additions & 9 deletions tests/generators/generators.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ if (typeof infer_stmt_next === "undefined") {
(infer_stmt_next : boolean) // error: string ~> boolean
}

declare function *decl(): Generator<number, string, boolean>;
for (var x of decl()) { (x : string) } // error: number ~> string
var decl_next = decl().next(0).value; // error: number ~> boolean
if (typeof decl_next === "undefined") {
} else if (typeof decl_next === "number") {
} else {
(decl_next : boolean) // error: string ~> boolean
}

function *widen_next() {
var x = yield 0;
if (typeof x === "number") {
Expand Down

0 comments on commit 8ecbaab

Please sign in to comment.