-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flow] More precise dependency analysis in class extends
Summary: In the AST, class extends contain an expression, but during type checking, we do not accept any kind of expressions. In fact, we only accept those that are annotation-like, e.g. identifier, members, and casts. For casts, only the anntoation is used to determine the signature, and for all other expressions, the signature will be any. However, our dependency analysis is name_def_ordering is not aware of these rules. We just blindly add everything in the expression as dependency. In the added test, it makes Flow think that there is a legal SCC of ``` Ref --> referencedInClassExtends --> Node -- /\ | |-----------------------------------------\/ ``` which doesn't make sense. It just has not blown up under the current system, due to the use of unresolved tvars in between annotation resolution. This diff fixes that. During the dependency analysis, we will only visit the nodes that are used to determine the signature, mirroring the logic in `mk_extends` in statement.ml. Changelog: [internal] Reviewed By: panagosg7 Differential Revision: D55528626 fbshipit-source-id: 62b7617b596395b133a8d9aea2f5395dc36aa0e8
- Loading branch information
1 parent
b2a1884
commit a1555d9
Showing
4 changed files
with
56 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
//@flow | ||
|
||
class C extends (42 as any as D).f(x => 42) {} | ||
{ | ||
class C extends (42 as any as D).f(x => 42) {} | ||
|
||
class D { | ||
f(x: mixed): any { | ||
return C; | ||
class D { | ||
f(x: mixed): any { | ||
return C; | ||
} | ||
} | ||
} | ||
|
||
{ | ||
type Ref = { children: Array<Node> }; | ||
declare const referencedInClassExtends: Ref; | ||
declare function f(v: mixed): mixed; | ||
// Node does not depend on f and referencedInClassExtends | ||
class Node extends (f(referencedInClassExtends) as any) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters