diff --git a/src/analysis/analyse.test.ts b/src/analysis/analyse.test.ts index 84f812d1..accc2484 100644 --- a/src/analysis/analyse.test.ts +++ b/src/analysis/analyse.test.ts @@ -264,17 +264,18 @@ describe("modules", () => { expect(a.errors).toEqual([]); }); - test.todo("implicitly imports variants of the modules in the prelude", () => { + test("implicitly imports variants of the modules in the prelude", () => { const [A] = performAnalysis( ` - pub(..) type MyType { A } + pub(..) type MyType { Variant } `, { namespace: "A" }, ); const [a] = performAnalysis( ` - pub let x = A + // import A.{MyType(..)} + pub let x = Variant `, { dependencies: { A }, @@ -301,7 +302,7 @@ describe("modules", () => { }); }); - test.todo("handles nested type references from other modules", () => { + test("handles nested type references from other modules", () => { const [A] = performAnalysis( ` pub(..) type T { T } @@ -391,7 +392,7 @@ describe("modules", () => { }); }); - test.todo("allow importing types (unqualified)", () => { + test("allow importing types (unqualified)", () => { const [Mod] = performAnalysis(`pub type Example { }`, { namespace: "Mod" }); const [a] = performAnalysis( diff --git a/src/analysis/analyse.ts b/src/analysis/analyse.ts index fd38195b..6b73e1a7 100644 --- a/src/analysis/analyse.ts +++ b/src/analysis/analyse.ts @@ -149,7 +149,17 @@ export class Analysis { return; case "constructor": { - const declarationType = this.typesHydration.getPolyType( + const analysis = + resolution.namespace === this.ns + ? this + : this.options.getDependency?.(resolution.namespace); + + if (analysis === undefined) { + // probably unreachable + throw new Error("TODO handle"); + } + + const declarationType = analysis.typesHydration.getPolyType( resolution.declaration, ); @@ -159,7 +169,7 @@ export class Analysis { : { tag: "Fn", args: resolution.variant.args.map((arg) => - this.typesHydration.getPolyType(arg), + analysis.typesHydration.getPolyType(arg), ), return: declarationType, }; diff --git a/src/analysis/resolution.ts b/src/analysis/resolution.ts index 1c591c20..21ddc13e 100644 --- a/src/analysis/resolution.ts +++ b/src/analysis/resolution.ts @@ -197,6 +197,20 @@ export class ResolutionAnalysis { declarationLookup, ]); + if ( + declarationLookup.type === "adt" && + declarationLookup.pub === ".." + ) { + for (const exposedVariant of declarationLookup.variants) { + this.importedValues.set(exposedVariant.name, { + type: "constructor", + declaration: declarationLookup, + variant: exposedVariant, + namespace: analysis.ns, + }); + } + } + break; }