Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bugbash] Mixed refines to read-only object under typeof = object
Summary: It is not safe to refine `mixed` to `{[string] : mixed}` because this allows writes of any kind into the refined object, and we don't know what type of values the object holds. The only safe operation is to read `mixed` out of the object, so the properties must be read only. ``` function bad (x : mixed) { if (typeof x === "object" && x !== null) { x.a = 3; } } let obj : {a : string} = {a : "oops"}; bad(obj); // yikes ``` Reviewed By: mvitousek Differential Revision: D14799387 fbshipit-source-id: 210ef1d98733b085b202dcbd4e1e83d69e707f08
- Loading branch information
1 parent
ace3612
commit 0983bd0
Showing
4 changed files
with
20 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// @flow | ||
function bad (x : mixed) { | ||
if (typeof x === "object" && x !== null) { | ||
x.a = 3; | ||
} | ||
} | ||
|
||
let obj : {a : string} = {a : "oops"}; | ||
bad(obj); // yikes |
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