Refinements should be invalidated by side effects
See original GitHub issueconst a: { a: string | number } = { a: 'foo' };
function foo() {
a.a = 1;
}
function test(x: { a: string | number }) {
if (typeof x.a === 'string') {
foo(); // this invalidates the refinement
const a: string = x.a.toUpperCase(); // runtime error
}
}
test(a);
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Pure functions · Issue #2715 · facebook/flow - GitHub
This issue seems to be focused on side-effects that mutate data somewhere. Pure functions in general aren't supposed to have any side-effects, ...
Read more >Rely-Guarantee References for Refinement Types Over ...
Reasoning about side effects and aliasing is the heart of verifying imperative programs. Unrestricted side effects through one refer- ence can invalidate ......
Read more >An Effective Theory of Type Refinements
program should not invalidate or contradict previous reasoning principles. 2. The system should support modular or local reasoning. In any given program, ...
Read more >Type Refinements in Flow - javascript - Stack Overflow
Functions/methods aren't pure in Javascript but may perform side effects. Date().getTime() for example may delete this.startedDateTime or set it ...
Read more >Rely-guarantee references for refinement types over aliased ...
Unrestricted side effects through one reference can invalidate assumptions about an alias. We present a new type system approach to reasoning ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I guess if soundness is the goal, then there is no middle ground
Should some of these soundness features be behind opt in / opt out flags ?
Like maybe in my code base I would be ok with assuming “no side effects in function calls” and some other code bases might really like the advanced checking of “Please invalidate on side effects”