Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logically equivalent intersection/union constructs behave differently #824

Closed
popham opened this issue Sep 19, 2015 · 1 comment
Closed

Logically equivalent intersection/union constructs behave differently #824

popham opened this issue Sep 19, 2015 · 1 comment

Comments

@popham
Copy link
Contributor

@popham popham commented Sep 19, 2015

Under Flow, the following are logically equivalent:

  1. Discr & (B | C)
  2. Discr & B | Discr & C
  3. Discr & K, where type K = B | C
    (I verified that & has higher precedence than | over here, here, and here).

Flow handles them inconsistently (in a case involving circular importing):

// main.js
import { B, C } from "./extensions";

type K = B | C;

type Discr = {
  which(): number;
};

export default class A {
  static sMethod(p: B | C): bool {
    return false;
  }
  static tMethod(p: Discr & (B | C)): bool {
  /*
    main.js:1:13,13: C
    This type is incompatible with
    main.js:1:10,10: B
  */
  //static tMethod(p: Discr & B | Discr & C): bool { /* OK */
  //static tMethod(p: Discr & K): bool {
  /*
    main.js:1:13,13: C
    This type is incompatible with
    main.js:1:10,10: B
  */
    if (p.which() === 5) {
      throw new Error("Peep");
    }
    return this.sMethod(p);
  }
}
// extensions.js
import A from "./main";

export class B extends A {
  which(): number {
    return 1;
  }
}
export class C extends A {
  which(): number {
    return 2;
  }
}
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.