Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Very strange bahaviour while using imported types #158

Closed
meafmira opened this issue Feb 28, 2019 · 1 comment
Closed

Very strange bahaviour while using imported types #158

meafmira opened this issue Feb 28, 2019 · 1 comment

Comments

@meafmira
Copy link

meafmira commented Feb 28, 2019

3 files:

  1. RecType.re:
[@genType]
type dialog = {
  a: string,
  b: int,
};
  1. ImportedType.re:
[@genType]
[@genType.import ("Imported", "Module")]
type importedType;
  1. ComposeTypes.re:
[@genType]
let f = (imported: ImportedType.importedType, rec_: RecType.dialog) => {
  rec_;
};

Let's see generated code for ComposeTypes.re:

/**
 * @flow strict
 * @generated
 * @nolint
 */
/* eslint-disable */

// $FlowExpectedError: Reason checked type sufficiently
import * as ComposeTypesBS from './ComposeTypes.bs';

// $FlowExpectedError: Reason checked type sufficiently
import * as Curry from 'bs-platform/lib/es6/curry.js';

// flowlint-next-line nonstrict-import:off
import type { dialog as RecType_dialog } from './RecType.gen';

// flowlint-next-line nonstrict-import:off
import type { importedType as ImportedType_importedType } from './ImportedType.gen';

export const f: (
  ImportedType_importedType,
  RecType_dialog,
) => RecType_dialog = function _(Arg1, Arg2) {
  const result = Curry._2(ComposeTypesBS.f, Arg1, Arg2);
  return result;
};

This is wrong, because there is no conversion from reason record to js object. But!
If we remove import annotation:

[@genType]
type importedType;

than it's ok:

export const f: (
  ImportedType_importedType,
  RecType_dialog,
) => RecType_dialog = function _(Arg1, Arg2) {
  const result = Curry._2(ComposeTypesBS.f, Arg1, [Arg2.a, Arg2.b]);
  return { a: result[0], b: result[1] };
};

Or we can remove imported type from function signature:

[@genType]
let f = (rec_: RecType.otherName) => {
  rec_;
};

and it's ok too:

export const f: (RecType_dialog) => RecType_dialog = function _(Arg1) {
  const result = ComposeTypesBS.f([Arg1.a, Arg1.b]);
  return { a: result[0], b: result[1] };
};

Or we can simply rename type dialog from RecType.re to other name. For example otherName:

[@genType]
type otherName = {
  a: string,
  b: int,
};

And this is fix issue too:

/**
 * @flow strict
 * @generated
 * @nolint
 */
/* eslint-disable */

// $FlowExpectedError: Reason checked type sufficiently
import * as ComposeTypesBS from './ComposeTypes.bs';

// $FlowExpectedError: Reason checked type sufficiently
import * as Curry from 'bs-platform/lib/es6/curry.js';

// flowlint-next-line nonstrict-import:off
import type { importedType as ImportedType_importedType } from './ImportedType.gen';

// flowlint-next-line nonstrict-import:off
import type { otherName as RecType_otherName } from './RecType.gen';

export const f: (
  ImportedType_importedType,
  RecType_otherName,
) => RecType_otherName = function _(Arg1, Arg2) {
  const result = Curry._2(ComposeTypesBS.f, Arg1, [Arg2.a, Arg2.b]);
  return { a: result[0], b: result[1] };
};

It's very strange

cristianoc added a commit that referenced this issue Feb 28, 2019
…iles could reset the type enironment.

Resetting the type environment causes failures depending on the order of type arguments in
#158
@cristianoc
Copy link
Collaborator

Thanks for spotting this. A nasty corner case.

Fixed in Release 2.12.2 https://github.com/cristianoc/genType/releases/tag/v2.12.2

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants