question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refinements should be invalidated by side effects

See original GitHub issue
const 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:open
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
vkurchatkincommented, May 22, 2020

I guess if soundness is the goal, then there is no middle ground

0reactions
Raynoscommented, May 22, 2020

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”

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found