/* @flow */

function foo(x: ?boolean) {
  if (!x) {
    x++; // should error for null, void and boolean (false)
  }
}

function bar(x: ?number) {
  if (!x) {
    x[0]; // should error for null, void and number (0)
  }
}

function baz(x: ?number) {
  if (x === null || x === undefined) {
    return;
  }

  if (!x) {
    x[0]; // should error for number (0)
  }
}

class TestClass {}

let tests = [
  function () {
    var y = true;
    while (y) {
      y = !y;
    }
  },
  function (x: Function) {
    !x as false; // ok, functions are always truthy
  },
  function (x: Object) {
    !x as false; // ok, objects are always truthy
  },
  function (x: string) {
    !x as false; // error, strings are not always truthy
  },
  function (x: number) {
    !x as false; // error, numbers are not always truthy
  },
  function (x: boolean) {
    !x as false; // error, bools are not always truthy
  },
  function (x: TestClass) {
    !x as false; // ok, classes are always truthy
  },
];
