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

[flow] Process polymorphic type bounds on functions #444

Merged
merged 1 commit into from
Mar 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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