Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

Commit

Permalink
[flow] Process polymorphic type bounds on functions (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
rattrayalex authored and hzoo committed Mar 20, 2017
1 parent 515adef commit a2c3b30
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ function monkeypatch() {
}
}

function visitTypeParameters(typeParameters) {
var params = typeParameters.params;

// visit bounds on polymorphpic types, eg; `Foo` in `fn<T: Foo>(a: T): T`
for (var i = 0; i < params.length; i++) {
var param = params[i];
if (param.typeAnnotation) {
visitTypeAnnotation.call(this, param.typeAnnotation);
}
}
}

function checkIdentifierOrVisit(node) {
if (node.typeAnnotation) {
visitTypeAnnotation.call(this, node.typeAnnotation);
Expand Down Expand Up @@ -249,6 +261,7 @@ function monkeypatch() {
var typeParamScope;
if (node.typeParameters) {
typeParamScope = nestTypeParamScope(this.scopeManager, node);
visitTypeParameters.call(this, node.typeParameters);
}
if (node.returnType) {
checkIdentifierOrVisit.call(this, node.returnType);
Expand Down
6 changes: 3 additions & 3 deletions test/non-regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ describe("verify", () => {
);
});

it("type parameters", () => {
it("type parameter bounds", () => {
verifyAndAssertMessages(
unpad(`
import type Foo from 'foo';
import type Foo2 from 'foo';
function log<T1, T2>(a: T1, b: T2) { return a + b; }
log<Foo, Foo2>(1, 2);
function log<T1: Foo, T2: Foo2>(a: T1, b: T2) { return a + b; }
log(1, 2);
`),
{ "no-unused-vars": 1, "no-undef": 1 },
[]
Expand Down

0 comments on commit a2c3b30

Please sign in to comment.