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

Async import - unbound module type #7173

Open
CarlOlson opened this issue Nov 25, 2024 · 1 comment
Open

Async import - unbound module type #7173

CarlOlson opened this issue Nov 25, 2024 · 1 comment
Assignees
Labels

Comments

@CarlOlson
Copy link

Importing code from another workspace often creates an error:

  4 ┆ switch value {
  5 ┆ | Some(arr) =>
  6 ┆   module Array = await Belt.Array
  7 ┆   Js.log(arr->Array.keepMap(x => x))
  8 ┆ | None => ()

  Unbound module type __Belt_Array__
  1. Here is the smallest example I've found: playgound
let fn = async value => {
  switch value {
  | Some(_) =>
    module Array = await Belt.Array
    ()
  | None => ()
  }
}
  1. However, this does not error: playground
let fn = async value => {
  module Array = await Belt.Array
  switch value {
  | Some(_) => ()
  | None => ()
  }
}
  1. Nor does this: playground
module type T = module type of Belt.Array

let fn = async value => {
  switch value {
  | Some(arr) =>
    module Array: T = await Belt.Array
    Js.log(arr->Array.keepMap(x => x))
  | None => ()
  }
}

But, (3) doesn't even produce an async import:

// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';

let Belt_Array = require("rescript/lib/js/Belt_Array.js");

async function fn(value) {
  if (value !== undefined) {
    console.log(Belt_Array.keepMap(value, x => x));
    return;
  }
  
}

exports.fn = fn;
/* No side effect */

This has been tested on 11.1.4 and 12.0.0-alpha.5, but the master branch has not been tested.

While importing Belt or Js asynchronously isn't desired, this error happens in my project in several useful locations.

@shulhi shulhi added the bug label Nov 25, 2024
@zth
Copy link
Collaborator

zth commented Nov 26, 2024

cc @mununki

@mununki mununki self-assigned this Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants