From 5686cf0bcf358bd753e100614e658fd64b9193b2 Mon Sep 17 00:00:00 2001 From: Oscar Spencer Date: Fri, 14 Oct 2022 17:17:51 -0500 Subject: [PATCH] fix(compiler): Fully expand types when finding concrete representation --- compiler/src/typed/type_utils.re | 2 +- compiler/test/suites/types.re | 15 ++++++++++++++- compiler/test/test-libs/funcAliasExport.gr | 3 +++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 compiler/test/test-libs/funcAliasExport.gr diff --git a/compiler/src/typed/type_utils.re b/compiler/src/typed/type_utils.re index f80e96937b..ca0b3d79a4 100644 --- a/compiler/src/typed/type_utils.re +++ b/compiler/src/typed/type_utils.re @@ -97,7 +97,7 @@ let allocation_type_of_wasm_repr = repr => { }; let repr_of_type = (env, ty) => - if (is_function(ty)) { + if (is_function(Ctype.full_expand(env, ty))) { let (args, ret) = get_fn_allocation_type(env, ty); let args = List.map(wasm_repr_of_allocation_type, args); let rets = diff --git a/compiler/test/suites/types.re b/compiler/test/suites/types.re index bacc61a75e..11f8166703 100644 --- a/compiler/test/suites/types.re +++ b/compiler/test/suites/types.re @@ -211,8 +211,12 @@ describe("aliased types", ({test, testSkip}) => { ); }); -describe("abstract types", ({test}) => { +describe("abstract types", ({test, testSkip}) => { + let test_or_skip = + Sys.backend_type == Other("js_of_ocaml") ? testSkip : test; + let assertCompileError = makeCompileErrorRunner(test); + let assertRun = makeRunner(test_or_skip); assertCompileError( "type_abstract_1", @@ -225,4 +229,13 @@ describe("abstract types", ({test}) => { // "expected of type // Foo", ); + + assertRun( + "regression_annotated_func_export", + {| + import A from "funcAliasExport" + print(A.function()) + |}, + "abc\n", + ); }); diff --git a/compiler/test/test-libs/funcAliasExport.gr b/compiler/test/test-libs/funcAliasExport.gr new file mode 100644 index 0000000000..69ab92ec3b --- /dev/null +++ b/compiler/test/test-libs/funcAliasExport.gr @@ -0,0 +1,3 @@ +export type FnType = () -> String + +export let function: FnType = () => "abc"