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

Comments

Projects
None yet
3 participants
@popham
Contributor

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;
  }
}
@avikchaudhuri

This comment has been minimized.

Show comment
Hide comment
@avikchaudhuri

avikchaudhuri Jun 1, 2016

Contributor

This will be fixed in an upcoming release.

Contributor

avikchaudhuri commented Jun 1, 2016

This will be fixed in an upcoming release.

@ghost ghost closed this in 2df7671 Jun 10, 2016

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment