genType icon indicating copy to clipboard operation
genType copied to clipboard

Weird behavior - define a single gentype export and it affects other exports in the file

Open jmagaram opened this issue 4 years ago • 0 comments

Consider this file. GenType creates everything I expect, including a constant for the whole NegativeInt module. BUT comment out the @genType let bozo = 0 and NOTHING gets generated. This seems really odd. Why would the inclusion of the bozo line affect generation of anything else?

Separately, I'm finding some inconsistent behavior with trying to generate those wrapped up constant exports like NegativeInt that include all the defined module functions. Sometimes it creates the constant with everything wrapped up, and sometimes it only creates the pieces inside NegativeInt without a wrapper. Can't pin this down. I was actually surprised it ever works since you can't put a genType annotation on the module itself and I thought it only worked with first class modules.

module type Validated = {
  type t
  type domain
  @genType
  let make: domain => option<t>
  @genType
  let makeExn: domain => t
  @genType
  let value: t => domain
}

module type Config = {
  type domain
  let validate: domain => option<domain>
}

module type MakeValidated = (P: Config) => (Validated with type domain := P.domain)

module Make: MakeValidated = (P: Config) => {
  type t = P.domain
  let make = v => v->P.validate
  let makeExn = v => v->make->Option.getExn
  external value: t => P.domain = "%identity"
}

module NegativeInt = Make({
  type domain = int
  let validate = n =>
    switch n < 0 {
    | true => Some(n)
    | false => None
    }
})

// Comment out these lines and nothing is generated
@genType
let bozo = 0

Part of what gets generated...

export const NegativeInt: {
  makeExn: (_1: number) => NegativeInt_t;
  value: (_1: NegativeInt_t) => number;
  make: (_1: number) => null | undefined | NegativeInt_t;
} = ExperimentBS.NegativeInt;

jmagaram avatar Oct 29 '21 18:10 jmagaram