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

Commit a2c3b30

Browse files
rattrayalexhzoo
authored andcommitted
[flow] Process polymorphic type bounds on functions (#444)
1 parent 515adef commit a2c3b30

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

index.js

+13
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ function monkeypatch() {
176176
}
177177
}
178178

179+
function visitTypeParameters(typeParameters) {
180+
var params = typeParameters.params;
181+
182+
// visit bounds on polymorphpic types, eg; `Foo` in `fn<T: Foo>(a: T): T`
183+
for (var i = 0; i < params.length; i++) {
184+
var param = params[i];
185+
if (param.typeAnnotation) {
186+
visitTypeAnnotation.call(this, param.typeAnnotation);
187+
}
188+
}
189+
}
190+
179191
function checkIdentifierOrVisit(node) {
180192
if (node.typeAnnotation) {
181193
visitTypeAnnotation.call(this, node.typeAnnotation);
@@ -249,6 +261,7 @@ function monkeypatch() {
249261
var typeParamScope;
250262
if (node.typeParameters) {
251263
typeParamScope = nestTypeParamScope(this.scopeManager, node);
264+
visitTypeParameters.call(this, node.typeParameters);
252265
}
253266
if (node.returnType) {
254267
checkIdentifierOrVisit.call(this, node.returnType);

test/non-regression.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,13 @@ describe("verify", () => {
222222
);
223223
});
224224

225-
it("type parameters", () => {
225+
it("type parameter bounds", () => {
226226
verifyAndAssertMessages(
227227
unpad(`
228228
import type Foo from 'foo';
229229
import type Foo2 from 'foo';
230-
function log<T1, T2>(a: T1, b: T2) { return a + b; }
231-
log<Foo, Foo2>(1, 2);
230+
function log<T1: Foo, T2: Foo2>(a: T1, b: T2) { return a + b; }
231+
log(1, 2);
232232
`),
233233
{ "no-unused-vars": 1, "no-undef": 1 },
234234
[]

0 commit comments

Comments
 (0)