Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tuple type-annotated rest parameters assertion failure ("Did not expect BoundT") #762

Closed
samwgoldman opened this issue Aug 31, 2015 · 1 comment

Comments

@samwgoldman
Copy link
Member

/* @flow */
function oops<T>(...xs: [T]): void { }
/* @flow */
type Fn = <T>(...xs: [T]) => void;
/* @flow */
class A<T> { f(...xs: [T]): void {}; }

Output:

<<<<<<<<
Did not expect BoundT:
Called from file "list.ml", line 73, characters 12-15
>>>>>>>>

/path/to/test.js:
Failure("Did not expect BoundT")
@samwgoldman samwgoldman changed the title Rest parameters in poly types are not substituted ("Did not expect BoundT") Tuple type-annotated rest parameters assertion failure ("Did not expect BoundT") Aug 31, 2015
@samwgoldman
Copy link
Member Author

The above examples show my confusion between Array<T> and [T] types, the latter being a single element tuple type, which is an unsuitable annotation for rest parameters. However, the error message is unhelpful—PR attempts to address this.

cagdasbozman pushed a commit to OCamlPro/flow that referenced this issue Sep 10, 2015
Summary: Before this change, annotating a rest parameter with a tuple type could
lead to an ugly exception, "Did not expect BoundT"

Instead, warn the user when this pattern occurs, because a tuple type
does not represent rest parameters well. The tuple type implies a fixed
number of elements, but there can be any number of rest parameters, by
definition.

While debugging this, I also noticed an issue with bound type parameters
in another rest parameter use case: `fn<T>(...xs: T)`. Currently, this
also throws the ugly exception, but it's a bit tricker to resolve
because the error is thrown from the unification that occurs before the
type param can be substituted.

Fixes facebook#762
Closes facebook#763

Reviewed By: @mroch

Differential Revision: D2402094

Pulled By: @jeffmo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant